diff --git a/openslides/assignment/models.py b/openslides/assignment/models.py index 749296470..b70972234 100644 --- a/openslides/assignment/models.py +++ b/openslides/assignment/models.py @@ -160,6 +160,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) @@ -178,7 +179,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 4abf2fb80..5adbf0188 100644 --- a/openslides/assignment/views.py +++ b/openslides/assignment/views.py @@ -539,7 +539,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/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 2437ceba7..14758a16d 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.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 5c842dea2..1dff34d3d 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.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)