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

Kasper #462 - Script for partner types #464

Merged
merged 7 commits into from
Mar 21, 2014
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
1 change: 0 additions & 1 deletion akvo/rsr/iati_code_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,3 @@
(911, u'Other non-bank securities/claims', 900, u'OTHER SECURITIES/CLAIMS', u''),
(912, u'Securities and other instruments issued by multilateral agencies', 900, u'OTHER SECURITIES/CLAIMS', u'')
)

48 changes: 48 additions & 0 deletions akvo/scripts/set_partner_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
#!/usr/bin/env python

"""
Script for setting all organisations to at least 'field' and 'funding' partner type.
"""

from django.core.management import setup_environ
from akvo import settings
setup_environ(settings)

from akvo.rsr.models import Organisation, PartnerType


def set_partner_types():
# Collect all organisations
organisations = Organisation.objects.all()

# Set counters
total_count_org = len(organisations)
field_count = 0
funding_count = 0

# Get field and funding partner type
field_partnertype, created = PartnerType.objects.get_or_create(id="field", label="Field partner")
funding_partnertype, created = PartnerType.objects.get_or_create(id="funding", label="Funding partner")

# For each organisation, check whether they are field and/or funding partners
for count, organisation in enumerate(organisations):
print "Checking organisation " + str(count + 1) + " of " + str(total_count_org) + ": " + organisation.long_name

if field_partnertype not in organisation.partner_types.all():
organisation.partner_types.add(field_partnertype)
print organisation.long_name + " added as field partner"
field_count += 1

if funding_partnertype not in organisation.partner_types.all():
organisation.partner_types.add(funding_partnertype)
print organisation.long_name + " added as funding partner"
funding_count += 1

print "\nDone:\n"
print "- " + str(field_count) + " organisations added as field partner."
print "- " + str(funding_count) + " organisations added as funding partner.\n"


if __name__ == '__main__':
set_partner_types()