From fbf81e77801a0ab5c787a23e85ad41a3ba4406f5 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Thu, 22 Nov 2012 16:19:09 +0100 Subject: [PATCH] sort persons --- openslides/assignment/models.py | 2 +- openslides/assignment/views.py | 2 +- openslides/participant/models.py | 6 ++++++ openslides/utils/person/api.py | 8 ++++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/openslides/assignment/models.py b/openslides/assignment/models.py index 4b86b75cf..6ee41a9ef 100644 --- a/openslides/assignment/models.py +++ b/openslides/assignment/models.py @@ -161,6 +161,7 @@ class Assignment(models.Model, SlideMixin): participants = [] for candidate in candidates.all(): participants.append(candidate.person) + participants.sort(key=lambda person: person.sort_name) return participants #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]) return poll - def vote_results(self, only_published): """ returns a table represented as a list with all candidates from all diff --git a/openslides/assignment/views.py b/openslides/assignment/views.py index fde043889..7d2275371 100644 --- a/openslides/assignment/views.py +++ b/openslides/assignment/views.py @@ -537,7 +537,7 @@ class AssignmentPollPDF(PDFView): stylesheet['Ballot_title'])) cell.append(Paragraph(self.poll.assignment.polldescription, stylesheet['Ballot_subtitle'])) - options = self.poll.get_options().order_by('candidate') + options = self.poll.get_options() ballot_string = _("%d. ballot") % self.poll.get_ballot() candidate_string = ungettext("%d candidate", "%d candidates", diff --git a/openslides/participant/models.py b/openslides/participant/models.py index 6f90709f4..9dffca2de 100644 --- a/openslides/participant/models.py +++ b/openslides/participant/models.py @@ -83,6 +83,12 @@ class User(DjangoUser, PersonMixin, Person, SlideMixin): self.set_password(password) 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 def get_absolute_url(self, link='view'): """ diff --git a/openslides/utils/person/api.py b/openslides/utils/person/api.py index 5c842dea2..92fd7f23a 100644 --- a/openslides/utils/person/api.py +++ b/openslides/utils/person/api.py @@ -29,6 +29,14 @@ class Person(object): """ 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 def clean_name(self): """