diff --git a/pombola/core/models.py b/pombola/core/models.py index a73054d7d..7f7f1294e 100644 --- a/pombola/core/models.py +++ b/pombola/core/models.py @@ -390,6 +390,36 @@ def prefetch_active_party_positions(self): to_attr="active_party_positions", ) ) + + # Prefetch current positions + def prefetch_current_positions(self): + """ + Prefetch current positions. + """ + current_positions = Position.objects.currently_active().order_by('-pk').select_related('title', 'organisation') + + return self.prefetch_related( + Prefetch( + "position_set", + queryset=current_positions, + to_attr="current_positions", + ) + ) + + # Prefetch previous positions + def prefetch_previous_positions(self): + """ + Prefetch previous positions. + """ + previous_positions = Position.objects.previous().order_by('-pk').select_related('title', 'organisation') + + return self.prefetch_related( + Prefetch( + "position_set", + queryset=previous_positions, + to_attr="previous_positions", + ) + ) class PersonManager(ManagerBase): def get_queryset(self): diff --git a/pombola/south_africa/views/download.py b/pombola/south_africa/views/download.py index 619325eca..6bdfa9d63 100644 --- a/pombola/south_africa/views/download.py +++ b/pombola/south_africa/views/download.py @@ -28,7 +28,6 @@ def person_row_generator(persons): email addresses and party memberships. """ for person in persons: - email = get_email_addresses_for_person(person) yield ( # Name person.name, @@ -48,6 +47,16 @@ def person_row_generator(persons): ", ".join([contact.value for contact in person.linkedin_contacts]), # Instagram ", ".join([contact.value for contact in person.instagram_contacts]), + # Current Positions, ignore NoneType + ", ".join( + "%s at %s" % ( position.title.name if position.title else "???", position.organisation.name if position.organisation else "???") + for position in person.position_set.currently_active() + ), + # Former Positions + ", ".join( + "%s at %s" % ( position.title.name if position.title else "???", position.organisation.name if position.organisation else "???") + for position in person.position_set.previous() + ), ) @@ -78,6 +87,8 @@ def get_queryset_for_members_download(organisation): .prefetch_contacts_with_kind('facebook') .prefetch_contacts_with_kind('linkedin') .prefetch_contacts_with_kind('instagram') + .prefetch_current_positions() + .prefetch_previous_positions() .prefetch_related("alternative_names",) ) diff --git a/pombola/south_africa/views/mp-download-template.xlsx b/pombola/south_africa/views/mp-download-template.xlsx index f91e70390..6f3e8bf2c 100644 Binary files a/pombola/south_africa/views/mp-download-template.xlsx and b/pombola/south_africa/views/mp-download-template.xlsx differ