@@ -0,0 +1,1821 @@
+%22%22%22Export a CSV listing National Assembly members with term dates.%22%22%22%0A%0Aimport unicodecsv as csv%0Aimport os%0Aimport collections%0A%0Afrom pombola.core.models import Person, Organisation%0A%0Afrom django.core.management.base import BaseCommand, CommandError%0A%0A%0Aclass Command(BaseCommand):%0A    args = 'destination'%0A    help = 'Export a CSV listing National Assembly members with term dates.'%0A%0A    def handle(self, *args, **options):%0A%0A        if len(args) != 1:%0A            raise CommandError(%22You must provide a destination.%22)%0A%0A        destination = args%5B0%5D%0A%0A        organisation = Organisation.objects.filter(slug='national-assembly').get()%0A%0A        fields = %5B%0A            'name',%0A            'title',%0A            'given_name',%0A            'family_name',%0A            'url',%0A            'start_date',%0A            'end_date',%0A        %5D%0A%0A        with open(os.path.join(destination), 'wb') as output_file:%0A            writer = csv.DictWriter(output_file, fieldnames=fields)%0A%0A            writer.writeheader()%0A%0A            # Get the list of positions%0A            positions = organisation.position_set.filter(person__hidden=False)%0A%0A            # Write all the outputs%0A            for position in positions:%0A                print position%0A                person = position.person%0A                position_output = %7B%0A                    'name': person.name,%0A                    'title': person.title,%0A                    'given_name': person.given_name,%0A                    'family_name': person.family_name,%0A                    'url': 'https://www.pa.org.za/person/%7B%7D/'.format(person.slug),%0A                    'start_date': position.start_date,%0A                    'end_date': position.end_date,%0A                %7D%0A                writer.writerow(position_output)%0A%0A        print %22Done! Exported CSV of %22 + str(len(positions)) + %22 positions.%22%0A

Add script to export NA members and their position start/end dates