@@ -0,0 +1,1347 @@
+# -*- coding: utf-8 -*-%0Afrom __future__ import print_function, unicode_literals%0A%0Afrom compat import BufferDictWriter%0A%0Afrom django.core.management.base import BaseCommand%0A%0Afrom official_documents.models import OfficialDocument%0Afrom popolo.models import Organization, Identifier%0A%0A%0A%0Aclass Command(BaseCommand):%0A%0A    help = %22Create a CSV with candidate info form the SOPNs%22%0A%0A    def handle(self, *args, **options):%0A        fieldnames = (%0A            'party_id',%0A            'party_name',%0A            'party_description',%0A        )%0A        out_csv = BufferDictWriter(fieldnames)%0A        out_csv.writeheader()%0A%0A        for org in Organization.objects.filter(classification='Party'):%0A            try:%0A                party_id = org.identifiers.get(%0A                    scheme='electoral-commission').identifier%0A            except Identifier.DoesNotExist:%0A                party_id = org.identifiers.get(%0A                    scheme='popit-organization').identifier%0A%0A%0A            out_dict = %7B%0A                'party_id': party_id,%0A                'party_name': org.name,%0A                'party_description': '',%0A            %7D%0A            out_csv.writerow(out_dict)%0A            for desc in org.other_names.all():%0A                out_dict%5B'party_description'%5D =  desc.name%0A                out_csv.writerow(out_dict)%0A%0A        self.stdout.write(out_csv.output)%0A

Add management comand to export party dewcriptions