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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions incident/migrations/0044_auto_20200306_1646.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.10 on 2020-03-06 16:46

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('incident', '0043_auto_20200226_1558'),
]

operations = [
migrations.AlterField(
model_name='incidentpage',
name='targeted_institutions',
field=models.ManyToManyField(blank=True, related_name='institutions_incidents', to='incident.Institution', verbose_name='Targeted Institutions'),
),
]
38 changes: 38 additions & 0 deletions incident/migrations/0045_copy_affiliation_to_institutions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 2.2.10 on 2020-03-05 21:28

from django.db import migrations


def copy_affiliation(apps, schema_editor):
"""Copy incident affiliations to """
IncidentPage = apps.get_model('incident', 'IncidentPage')
Institution = apps.get_model('incident', 'Institution')

for incident in IncidentPage.objects.order_by('pk'):
if incident.affiliation and incident.affiliation != 'Independent':
inst, _ = Institution.objects.get_or_create(title=incident.affiliation)

targeted_journos = incident.targeted_journalists.all()
if targeted_journos:
for tj in targeted_journos:
if not tj.institution:
tj.institution = inst
tj.save()
else:
incident.targeted_institutions.add(inst)
incident.save()


class Migration(migrations.Migration):

dependencies = [
('incident', '0044_auto_20200306_1646'),
]

operations = [
migrations.RunPython(
copy_affiliation,
reverse_code=migrations.RunPython.noop,
elidable=True,
),
]
19 changes: 19 additions & 0 deletions incident/migrations/0046_auto_20200306_1648.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.2.10 on 2020-03-06 16:48

from django.db import migrations
import modelcluster.fields


class Migration(migrations.Migration):

dependencies = [
('incident', '0045_copy_affiliation_to_institutions'),
]

operations = [
migrations.AlterField(
model_name='incidentpage',
name='targeted_institutions',
field=modelcluster.fields.ParentalManyToManyField(blank=True, related_name='institutions_incidents', to='incident.Institution', verbose_name='Targeted Institutions'),
),
]
13 changes: 0 additions & 13 deletions incident/templates/incident/incident_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,6 @@ <h2 class="sr-only section-heading">Incident Data</h2>
</tr>
{% endif %}

{% if page.affiliation %}
<tr class="data-table__row">
<th class="data-table__label">
Affiliation
</th>
<td class="data-table__value">
<a href="{% pageurl page.get_parent %}?affiliation={{ page.affiliation }}">
{{ page.affiliation }}
</a>
</td>
</tr>
{% endif %}

{% if page.city or page.state %}
<tr class="data-table__row">
<th class="data-table__label">
Expand Down