diff --git a/openslides/application/models.py b/openslides/application/models.py index 06ad330bc..df1d8195f 100644 --- a/openslides/application/models.py +++ b/openslides/application/models.py @@ -534,6 +534,7 @@ class Application(models.Model, SlideMixin): ('can_support_application', ugettext_noop("Can support motions")), ('can_manage_application', ugettext_noop("Can manage motions")), ) + ordering = ('number',) class AVersion(models.Model): diff --git a/openslides/application/views.py b/openslides/application/views.py index 35ff3345a..87eca0f1a 100644 --- a/openslides/application/views.py +++ b/openslides/application/views.py @@ -102,8 +102,6 @@ def overview(request): if sort.startswith('aversion_'): # limit result to last version of an application query = query.filter(aversion__id__in=[x.last_version.id for x in Application.objects.all()]) - else: - query = query.order_by('number') if 'reverse' in sortfilter: query = query.reverse() @@ -681,7 +679,7 @@ class ApplicationPDF(PDFView): if preamble: story.append(Paragraph("%s" % preamble.replace('\r\n','
'), stylesheet['Paragraph'])) story.append(Spacer(0,0.75*cm)) - applications = Application.objects.order_by('number') + applications = Application.objects.all() if not applications: # No applications existing story.append(Paragraph(_("No motions available."), stylesheet['Heading3'])) else: # Print all Applications @@ -899,5 +897,5 @@ def get_widgets(request): Widget( name='applications', template='application/widget.html', - context={'applications': Application.objects.all().order_by('number')}, + context={'applications': Application.objects.all()}, permission_required='application.can_manage_application')] diff --git a/openslides/assignment/models.py b/openslides/assignment/models.py index 2a15f271f..dcd8a6e15 100644 --- a/openslides/assignment/models.py +++ b/openslides/assignment/models.py @@ -253,6 +253,7 @@ class Assignment(models.Model, SlideMixin): ('can_nominate_self', ugettext_noop("Can nominate themselves")), ('can_manage_assignment', ugettext_noop("Can manage assignment")), ) + ordering = ('name',) register_slidemodel(Assignment) diff --git a/openslides/assignment/views.py b/openslides/assignment/views.py index 26a7a0bf5..2b7ff4a71 100644 --- a/openslides/assignment/views.py +++ b/openslides/assignment/views.py @@ -59,7 +59,7 @@ def get_overview(request): if sort in ['name','status']: query = query.order_by(sort) except KeyError: - query = query.order_by('name') + pass if 'reverse' in request.GET: query = query.reverse() @@ -353,7 +353,7 @@ class AssignmentPDF(PDFView): story.append(Paragraph("%s" % preamble.replace('\r\n', '
'), stylesheet['Paragraph'])) story.append(Spacer(0, 0.75 * cm)) - assignments = Assignment.objects.order_by('name') + assignments = Assignment.objects.all() if not assignments: # No assignments existing story.append(Paragraph(_("No assignments available."), stylesheet['Heading3'])) @@ -675,5 +675,5 @@ def get_widgets(request): Widget( name=_('Assignments'), template='assignment/widget.html', - context={'assignments': Assignment.objects.all().order_by('name')}, + context={'assignments': Assignment.objects.all()}, permission_required='assignment.can_manage_assignment')] diff --git a/openslides/participant/forms.py b/openslides/participant/forms.py index aedff5126..4687432fe 100644 --- a/openslides/participant/forms.py +++ b/openslides/participant/forms.py @@ -113,3 +113,6 @@ class ConfigForm(forms.Form, CssClassMixin): required=False, label=_("Welcome text"), help_text=_("Printed in PDF of first time passwords only.")) + participant_sort_users_by_first_name = forms.BooleanField( + required=False, + label=_("Sort users by first name")) diff --git a/openslides/participant/models.py b/openslides/participant/models.py index 4977b3dcf..42b965f69 100644 --- a/openslides/participant/models.py +++ b/openslides/participant/models.py @@ -19,6 +19,7 @@ from django.utils.translation import ugettext_lazy as _, ugettext_noop from openslides.utils.person import PersonMixin from openslides.utils.person.signals import receive_persons +from openslides.config.models import config from openslides.config.signals import default_config_value @@ -28,7 +29,7 @@ class User(DjangoUser, PersonMixin): ('male', _('Male')), ('female', _('Female')), ) - TYPE_CHOICE = ( + TYPE_CHOICES = ( ('delegate', _('Delegate')), ('observer', _('Observer')), ('staff', _('Staff')), @@ -43,7 +44,7 @@ class User(DjangoUser, PersonMixin): max_length=50, choices=GENDER_CHOICES, blank=True, verbose_name=_("Gender"), help_text=_('Only for filter the userlist.')) type = models.CharField( - max_length=100, choices=TYPE_CHOICE, blank=True, + max_length=100, choices=TYPE_CHOICES, blank=True, verbose_name=_("Typ"), help_text=_('Only for filter the userlist.')) committee = models.CharField( max_length=100, null=True, blank=True, verbose_name=_("Committee"), @@ -99,6 +100,7 @@ class User(DjangoUser, PersonMixin): ('can_manage_participant', ugettext_noop("Can manage participant")), ) + ordering = ('last_name',) class Group(DjangoGroup, PersonMixin): @@ -125,12 +127,22 @@ class Group(DjangoGroup, PersonMixin): def __unicode__(self): return unicode(self.name) + class Meta: + ordering = ('name',) -class UsersConnector(object): + +class UsersAndGroupsToPersons(object): + """ + Object to send all Users and Groups or a special User or Group to + the Person-API via receice_persons() + """ def __init__(self, person_prefix_filter=None, id_filter=None): self.person_prefix_filter = person_prefix_filter self.id_filter = id_filter - self.users = User.objects.all() + if config['participant_sort_users_by_first_name']: + self.users = User.objects.all().order_by('first_name') + else: + self.users = User.objects.all() self.groups = Group.objects.filter(group_as_person=True) def __iter__(self): @@ -159,7 +171,10 @@ class UsersConnector(object): @receiver(receive_persons, dispatch_uid="participant") def receive_persons(sender, **kwargs): - return UsersConnector(person_prefix_filter=kwargs['person_prefix_filter'], + """ + Answers to the Person-API + """ + return UsersAndGroupsToPersons(person_prefix_filter=kwargs['person_prefix_filter'], id_filter=kwargs['id_filter']) @@ -172,6 +187,7 @@ def default_config(sender, key, **kwargs): return { 'participant_pdf_system_url': 'http://example.com:8000', 'participant_pdf_welcometext': _('Welcome to OpenSlides!'), + 'participant_sort_users_by_first_name': False, }.get(key) diff --git a/openslides/participant/views.py b/openslides/participant/views.py index f4bbb8448..63d70f77b 100644 --- a/openslides/participant/views.py +++ b/openslides/participant/views.py @@ -53,7 +53,7 @@ from openslides.participant.models import User, Group class Overview(ListView): """ - Show all participants. + Show all participants (users). """ permission_required = 'participant.can_see_participant' template_name = 'participant/overview.html' @@ -96,7 +96,8 @@ class Overview(ListView): query = query.order_by( '%s' % sortfilter['sort'][0]) else: - query = query.order_by('last_name') + if config['participant_sort_users_by_first_name']: + query = query.order_by('first_name') if 'reverse' in sortfilter: query = query.reverse() @@ -412,13 +413,16 @@ class Config(FormView): def get_initial(self): return { 'participant_pdf_system_url': config['participant_pdf_system_url'], - 'participant_pdf_welcometext': config['participant_pdf_welcometext']} + 'participant_pdf_welcometext': config['participant_pdf_welcometext'], + 'participant_sort_users_by_first_name': config['participant_sort_users_by_first_name']} def form_valid(self, form): config['participant_pdf_system_url'] = ( form.cleaned_data['participant_pdf_system_url']) config['participant_pdf_welcometext'] = ( form.cleaned_data['participant_pdf_welcometext']) + config['participant_sort_users_by_first_name'] = ( + form.cleaned_data['participant_sort_users_by_first_name']) messages.success( self.request, _('Participants settings successfully saved.'))