sort persons

This commit is contained in:
Oskar Hahn 2012-11-22 16:19:09 +01:00
parent f40f091658
commit fbf81e7780
4 changed files with 16 additions and 2 deletions

View File

@ -161,6 +161,7 @@ class Assignment(models.Model, SlideMixin):
participants = [] participants = []
for candidate in candidates.all(): for candidate in candidates.all():
participants.append(candidate.person) participants.append(candidate.person)
participants.sort(key=lambda person: person.sort_name)
return participants return participants
#return candidates.values_list('person', flat=True) #return candidates.values_list('person', flat=True)
@ -179,7 +180,6 @@ class Assignment(models.Model, SlideMixin):
poll.set_options([{'candidate': person} for person in self.candidates]) poll.set_options([{'candidate': person} for person in self.candidates])
return poll return poll
def vote_results(self, only_published): def vote_results(self, only_published):
""" """
returns a table represented as a list with all candidates from all returns a table represented as a list with all candidates from all

View File

@ -537,7 +537,7 @@ class AssignmentPollPDF(PDFView):
stylesheet['Ballot_title'])) stylesheet['Ballot_title']))
cell.append(Paragraph(self.poll.assignment.polldescription, cell.append(Paragraph(self.poll.assignment.polldescription,
stylesheet['Ballot_subtitle'])) stylesheet['Ballot_subtitle']))
options = self.poll.get_options().order_by('candidate') options = self.poll.get_options()
ballot_string = _("%d. ballot") % self.poll.get_ballot() ballot_string = _("%d. ballot") % self.poll.get_ballot()
candidate_string = ungettext("%d candidate", "%d candidates", candidate_string = ungettext("%d candidate", "%d candidates",

View File

@ -83,6 +83,12 @@ class User(DjangoUser, PersonMixin, Person, SlideMixin):
self.set_password(password) self.set_password(password)
self.save() self.save()
@property
def sort_name(self):
if config['participant_sort_users_by_first_name']:
return self.first_name
return self.last_name
@models.permalink @models.permalink
def get_absolute_url(self, link='view'): def get_absolute_url(self, link='view'):
""" """

View File

@ -29,6 +29,14 @@ class Person(object):
""" """
return str(self.person_id) return str(self.person_id)
@property
def sort_name(self):
"""
Return the part of the name, which is used for sorting.
For example the pre-name or the last-name
"""
return self.__repr__()
@property @property
def clean_name(self): def clean_name(self):
""" """