-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[#1936] Change order for primary organisations; reporting org first Code reviewed
- Loading branch information
Showing
2 changed files
with
51 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
|
||
from ..models.project import Project | ||
|
||
def change_primary_organisations(apps, schema_editor): | ||
Project = apps.get_model("rsr", "Project") | ||
|
||
for project in Project.objects.all(): | ||
primary_organisation = None | ||
|
||
# Pick the reporting org first | ||
if project.partnerships.filter(iati_organisation_role=101): | ||
primary_organisation = project.partnerships.filter( | ||
iati_organisation_role=101)[0].organisation | ||
|
||
# Otherwise, pick the partner that can publish the project | ||
elif project.partners.filter(can_create_projects=True): | ||
primary_organisation = project.partners.filter(can_create_projects=True)[0] | ||
|
||
# Otherwise, grab the first accountable partner we find | ||
elif project.partnerships.filter(iati_organisation_role=2): | ||
primary_organisation = project.partnerships.filter( | ||
iati_organisation_role=2)[0].organisation | ||
|
||
# Panic mode: grab the first partner we find | ||
elif project.partners.all(): | ||
primary_organisation = project.partners.all()[0] | ||
|
||
project.primary_organisation = primary_organisation | ||
project.save(update_fields=['primary_organisation']) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('rsr', '0041_auto_20151116_1250'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
change_primary_organisations, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters