From fbf81e77801a0ab5c787a23e85ad41a3ba4406f5 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Thu, 22 Nov 2012 16:19:09 +0100 Subject: [PATCH 1/2] 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): """ From 1dc7d45670c8207d5de1420707cfc1f2d13a67c6 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Thu, 22 Nov 2012 16:54:56 +0100 Subject: [PATCH 2/2] sort persons in motions --- openslides/motion/models.py | 4 ++-- openslides/participant/models.py | 4 ++-- openslides/utils/person/api.py | 2 +- openslides/utils/person/forms.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/openslides/motion/models.py b/openslides/motion/models.py index c29133ebf..380b7de3a 100644 --- a/openslides/motion/models.py +++ b/openslides/motion/models.py @@ -162,8 +162,8 @@ class Motion(models.Model, SlideMixin): @property def supporters(self): - for object in self.motionsupporter_set.all(): - yield object.person + return sorted([object.person for object in self.motionsupporter_set.all()], + key=lambda person: person.sort_name) def is_supporter(self, person): try: diff --git a/openslides/participant/models.py b/openslides/participant/models.py index cadc82d5e..14758a16d 100644 --- a/openslides/participant/models.py +++ b/openslides/participant/models.py @@ -86,8 +86,8 @@ class User(DjangoUser, PersonMixin, Person, SlideMixin): @property def sort_name(self): if config['participant_sort_users_by_first_name']: - return self.first_name - return self.last_name + return self.first_name.lower() + return self.last_name.lower() @models.permalink def get_absolute_url(self, link='view'): diff --git a/openslides/utils/person/api.py b/openslides/utils/person/api.py index 92fd7f23a..1dff34d3d 100644 --- a/openslides/utils/person/api.py +++ b/openslides/utils/person/api.py @@ -35,7 +35,7 @@ class Person(object): Return the part of the name, which is used for sorting. For example the pre-name or the last-name """ - return self.__repr__() + return self.clean_name.lower() @property def clean_name(self): diff --git a/openslides/utils/person/forms.py b/openslides/utils/person/forms.py index 2330443dc..cee080bce 100644 --- a/openslides/utils/person/forms.py +++ b/openslides/utils/person/forms.py @@ -22,7 +22,7 @@ class PersonChoices(object): def __iter__(self): if self.field.empty_label is not None: yield (u"", self.field.empty_label) - for person in Persons(): + for person in sorted(Persons(), key=lambda person: person.sort_name): yield (person.person_id, person)