From 77ae543ff201c314e93b96435e758bfd3a52f87d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Fri, 14 Sep 2012 00:21:59 +0200 Subject: [PATCH 1/8] Using Meta Class for ordering assignments by name --- openslides/assignment/models.py | 1 + openslides/assignment/views.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) 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')] From cb3b26c45de218ec75fbfb0432827ab3651ced84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Fri, 14 Sep 2012 01:14:25 +0200 Subject: [PATCH 2/8] Default sorting of applications using Meta Class --- openslides/application/models.py | 1 + openslides/application/views.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) 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..ba073bb51 100644 --- a/openslides/application/views.py +++ b/openslides/application/views.py @@ -103,7 +103,7 @@ def overview(request): # 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') + pass if 'reverse' in sortfilter: query = query.reverse() @@ -681,7 +681,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 +899,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')] From 811b780fb9ddc3c1a971e6ebd4aad0526235c9bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Fri, 14 Sep 2012 01:52:20 +0200 Subject: [PATCH 3/8] Fix typo TYPE_CHOICE to TYPE_CHOICES --- openslides/participant/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openslides/participant/models.py b/openslides/participant/models.py index b97ed119c..2e2c21ebc 100644 --- a/openslides/participant/models.py +++ b/openslides/participant/models.py @@ -28,7 +28,7 @@ class User(DjangoUser, PersonMixin): ('male', _('Male')), ('female', _('Female')), ) - TYPE_CHOICE = ( + TYPE_CHOICES = ( ('delegate', _('Delegate')), ('observer', _('Observer')), ('staff', _('Staff')), @@ -43,7 +43,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"), From f8d3390c78219b280b89325478dc646ed4f29101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Fri, 14 Sep 2012 02:24:02 +0200 Subject: [PATCH 4/8] Docstrings and sorting of Users and Groups in the UsersAndGroupsToPersons class object (was: UsersConnector) --- openslides/participant/models.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/openslides/participant/models.py b/openslides/participant/models.py index 2e2c21ebc..f0b420f05 100644 --- a/openslides/participant/models.py +++ b/openslides/participant/models.py @@ -126,12 +126,16 @@ class Group(DjangoGroup, PersonMixin): return unicode(self.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() - self.groups = Group.objects.filter(group_as_person=True) + self.users = User.objects.all().order_by('last_name') + self.groups = Group.objects.filter(group_as_person=True).order_by('name') def __iter__(self): if (not self.person_prefix_filter or @@ -150,13 +154,17 @@ class UsersConnector(object): for group in self.groups: yield group + # Are the following two lines superfluous? They only return Users not Groups. def __getitem__(self, key): return User.objects.get(pk=key) @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']) From f41fe87656e09f99c6b8c5aa3531d516f9d9fb85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Fri, 14 Sep 2012 02:40:40 +0200 Subject: [PATCH 5/8] Insert new config var for sorting Users by first_name --- openslides/participant/forms.py | 3 +++ openslides/participant/models.py | 1 + openslides/participant/views.py | 5 ++++- 3 files changed, 8 insertions(+), 1 deletion(-) 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 f0b420f05..99581cd37 100644 --- a/openslides/participant/models.py +++ b/openslides/participant/models.py @@ -177,6 +177,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..1cc4dbc72 100644 --- a/openslides/participant/views.py +++ b/openslides/participant/views.py @@ -412,13 +412,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.')) From e5c132e34cdea1d97b4456bdf7a05ef64a7298e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Fri, 14 Sep 2012 02:46:43 +0200 Subject: [PATCH 6/8] Use new config var for sorting users --- openslides/participant/models.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/openslides/participant/models.py b/openslides/participant/models.py index 99581cd37..662dcf9e3 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 @@ -134,7 +135,10 @@ class UsersAndGroupsToPersons(object): 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().order_by('last_name') + if config['participant_sort_users_by_first_name']: + self.users = User.objects.all().order_by('first_name') + else: + self.users = User.objects.all().order_by('last_name') self.groups = Group.objects.filter(group_as_person=True).order_by('name') def __iter__(self): From 269b093b28d2157d16d88c80e7db4e8cb29d0016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Fri, 14 Sep 2012 03:02:00 +0200 Subject: [PATCH 7/8] Enhence use of config var and Meta Class for default sorting of users --- openslides/participant/models.py | 8 ++++++-- openslides/participant/views.py | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/openslides/participant/models.py b/openslides/participant/models.py index 662dcf9e3..1eef00093 100644 --- a/openslides/participant/models.py +++ b/openslides/participant/models.py @@ -100,6 +100,7 @@ class User(DjangoUser, PersonMixin): ('can_manage_participant', ugettext_noop("Can manage participant")), ) + ordering = ('last_name',) class Group(DjangoGroup, PersonMixin): @@ -126,6 +127,9 @@ class Group(DjangoGroup, PersonMixin): def __unicode__(self): return unicode(self.name) + class Meta: + ordering = ('name',) + class UsersAndGroupsToPersons(object): """ @@ -138,8 +142,8 @@ class UsersAndGroupsToPersons(object): if config['participant_sort_users_by_first_name']: self.users = User.objects.all().order_by('first_name') else: - self.users = User.objects.all().order_by('last_name') - self.groups = Group.objects.filter(group_as_person=True).order_by('name') + self.users = User.objects.all() + self.groups = Group.objects.filter(group_as_person=True) def __iter__(self): if (not self.person_prefix_filter or diff --git a/openslides/participant/views.py b/openslides/participant/views.py index 1cc4dbc72..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() From 0db8af15b79ad2e9cda5ea4c03405a2d01c3b35b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Fri, 14 Sep 2012 23:53:59 +0200 Subject: [PATCH 8/8] Clean up the code for pull request --- openslides/application/views.py | 2 -- openslides/participant/models.py | 4 ---- 2 files changed, 6 deletions(-) diff --git a/openslides/application/views.py b/openslides/application/views.py index ba073bb51..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: - pass if 'reverse' in sortfilter: query = query.reverse() diff --git a/openslides/participant/models.py b/openslides/participant/models.py index 1eef00093..a94fcdb41 100644 --- a/openslides/participant/models.py +++ b/openslides/participant/models.py @@ -162,10 +162,6 @@ class UsersAndGroupsToPersons(object): for group in self.groups: yield group - # Are the following two lines superfluous? They only return Users not Groups. - def __getitem__(self, key): - return User.objects.get(pk=key) - @receiver(receive_persons, dispatch_uid="participant") def receive_persons(sender, **kwargs):