Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy affiliations to targeted journalists and institutions #865

Merged
merged 3 commits into from
Apr 7, 2020

Conversation

chigby
Copy link
Contributor

@chigby chigby commented Mar 6, 2020

This is to correct an oversight in from #776 where the field IncidentPage.affiliation should have been used to initialize the Institution model and the relationships between Institution, IncidentPage, and TargetedJournalist. In this pull request, we have:

  1. A set of data migrations to copy affiliation data into the Institution model and its relations. See commit for further detail and rationale.
  2. The removal of the affiliation display on the incident page sidebar.

Fixes #866

Testing and Acceptance

The crucial element here is the data manipulation code. I believe it's good, but we ought to make extra sure that: 1. we know what we want it to do, and 2. it does that correctly.

@chigby chigby requested a review from harrislapiroff as a code owner March 6, 2020 22:16
@chigby chigby force-pushed the copy-affiliations-to-targeted-relations branch 2 times, most recently from 619da58 to 98b891f Compare March 6, 2020 22:23
@chigby chigby force-pushed the copy-affiliations-to-targeted-relations branch from 98b891f to 39fe578 Compare March 25, 2020 17:53
Copy link
Contributor

@harrislapiroff harrislapiroff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This worked as expected! I'd like us to hide the deprecated fields (or mark them as deprecated) but this is a definite improvement over the current situation!

inst, _ = Institution.objects.get_or_create(title=incident.affiliation)

targeted_journos = incident.targeted_journalists.all()
if targeted_journos:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to check my memory that empty querysets are falsey. They are 👍

chigby added 2 commits April 7, 2020 16:58
We are phasing out the one-affiliation-per-incident affiliation model
in favor of an Institution model, which can either be applied on a
journalist by journalist basis, or to the incident as a whole, but as
many as desired.

For this, we must move data from the legacy affiliation field to the
new Institution field.  We do this using a data migration, with two
pre- and post- migrations to work around this bug in
djang-modelcluster:
    wagtail/django-modelcluster#96

For the migration, we want these steps:

1. For each incident, examine the `affiliation` field

2. If it null or set to the default value of "Independent," discard
it.  The "independent" value is a placeholder for no definite
affiliation and will not be used in the new scheme.

3. Create, if it doesn't already exist, an Institution with the title
of the affiliation.

4. If this incident has any targeted journalists who do not already
have an associated institution, associate the new institution with
them.

5. If this incident does *not* have any targeted journalists, add the
new institution as a target of this incident.

This will fully bring any affiliation data into the institution model
and apply it to the incidents that this data described.
Since this information is subsumed by the institution data, I'm
feeling like it should be removed from display as well.
@harrislapiroff harrislapiroff force-pushed the copy-affiliations-to-targeted-relations branch from 39fe578 to 36bf7a7 Compare April 7, 2020 20:58
@harrislapiroff harrislapiroff merged commit 8fce9f7 into master Apr 7, 2020
@harrislapiroff harrislapiroff deleted the copy-affiliations-to-targeted-relations branch April 7, 2020 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate Affiliation to Insitutions
2 participants