Skip to content

Commit

Permalink
Merge pull request #213 from OpenUpSA/feature/add-current-and-former-…
Browse files Browse the repository at this point in the history
…positions-to-downloads

Added Current Positions and Previous Positions
  • Loading branch information
paulmwatson authored Apr 2, 2024
2 parents 27bfdc7 + cfcd511 commit 81fddd9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
30 changes: 30 additions & 0 deletions pombola/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
13 changes: 12 additions & 1 deletion pombola/south_africa/views/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
),
)


Expand Down Expand Up @@ -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",)
)

Expand Down
Binary file modified pombola/south_africa/views/mp-download-template.xlsx
Binary file not shown.

0 comments on commit 81fddd9

Please sign in to comment.