From a23164a9062f51f16f290d029476a60f7c8a6a44 Mon Sep 17 00:00:00 2001 From: Emanuel Schuetze Date: Tue, 1 Nov 2011 06:47:10 +0100 Subject: [PATCH] Order submitter and supporter fields by full name in ApplicationManagerForm. --- openslides/application/forms.py | 24 +++++++++++++++++++++++- openslides/application/views.py | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/openslides/application/forms.py b/openslides/application/forms.py index 33d0f5c25..b1b5ca132 100644 --- a/openslides/application/forms.py +++ b/openslides/application/forms.py @@ -10,12 +10,30 @@ :license: GNU GPL, see LICENSE for more details. """ -from django.forms import ModelForm, Form, CharField, Textarea, TextInput +from django.forms import ModelForm, Form, CharField, Textarea, TextInput, ModelMultipleChoiceField, ModelChoiceField +from django.contrib.auth.models import User from django.utils.translation import ugettext as _ from openslides.application.models import Application +class UserModelChoiceField(ModelChoiceField): + """ + Extend ModelChoiceField for users so that the choices are + listed as 'first_name last_name' instead of just 'username'. + """ + def label_from_instance(self, obj): + return obj.get_full_name() + +class UserModelMultipleChoiceField(ModelMultipleChoiceField): + """ + Extend ModelMultipleChoiceField for users so that the choices are + listed as 'first_name last_name' instead of just 'username'. + """ + def label_from_instance(self, obj): + return obj.get_full_name() + + class ApplicationForm(Form): error_css_class = 'error' required_css_class = 'required' @@ -29,6 +47,10 @@ class ApplicationManagerForm(ModelForm): error_css_class = 'error' required_css_class = 'required' + users = User.objects.all().exclude(profile=None).order_by("first_name") + submitter = UserModelChoiceField(queryset=users, label=_("Submitter")) + supporter = UserModelMultipleChoiceField(queryset=users, label=_("Supporters")) + class Meta: model = Application exclude = ('number', 'status', 'permitted', 'log') diff --git a/openslides/application/views.py b/openslides/application/views.py index be8fa7654..0342713c7 100644 --- a/openslides/application/views.py +++ b/openslides/application/views.py @@ -75,7 +75,7 @@ def view(request, application_id, newest=False): version = application.public_version revisions = application.versions actions = application.get_allowed_actions(user=request.user) - + return { 'application': application, 'revisions': revisions,