From a1d92dc1bb356a79811eb37b4843ea0f80d557ad Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sun, 4 Sep 2011 09:57:23 +0200 Subject: [PATCH 1/2] generate username with first and lastname --- openslides/participant/forms.py | 18 +++++++++++++----- openslides/participant/views.py | 31 ++++++++++++++++--------------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/openslides/participant/forms.py b/openslides/participant/forms.py index faca757ab..6063790e5 100644 --- a/openslides/participant/forms.py +++ b/openslides/participant/forms.py @@ -16,7 +16,18 @@ from django.contrib.auth.forms import AdminPasswordChangeForm from django.utils.translation import ugettext as _ from participant.models import Profile -class UserForm(ModelForm): +class UserNewForm(ModelForm): + error_css_class = 'error' + required_css_class = 'required' + + first_name = CharField(label=_("First name")) + last_name = CharField(label=_("Last name")) + + class Meta: + model = User + exclude = ('username', 'password', 'is_staff', 'last_login', 'date_joined', 'user_permissions') + +class UserEditForm(ModelForm): error_css_class = 'error' required_css_class = 'required' @@ -49,10 +60,7 @@ class GroupForm(ModelForm): class Meta: model = Group -class UsersettingsForm(UserForm): - error_css_class = 'error' - required_css_class = 'required' - +class UsersettingsForm(UserEditForm): class Meta: model = User fields = ('username', 'first_name', 'last_name', 'email') diff --git a/openslides/participant/views.py b/openslides/participant/views.py index a9fba59b7..a9f440b46 100644 --- a/openslides/participant/views.py +++ b/openslides/participant/views.py @@ -23,7 +23,7 @@ from django.utils.translation import ugettext as _ from participant.models import Profile, set_first_user_passwords from participant.api import gen_username -from participant.forms import UserForm, UsernameForm, ProfileForm, UsersettingsForm, UserImportForm, GroupForm, AdminPasswordChangeForm +from participant.forms import UserNewForm, UserEditForm, ProfileForm, UsersettingsForm, UserImportForm, GroupForm, AdminPasswordChangeForm from utils.utils import template, permission_required, gen_confirm_form from utils.pdf import print_userlist, print_passwords @@ -81,19 +81,18 @@ def edit(request, user_id=None): user = None if request.method == 'POST': - userform = UserForm(request.POST, instance=user, prefix="user") - try: - profileform = ProfileForm(request.POST, instance=user.profile, prefix="profile") - except: + if user_id is None: + userform = UserNewForm(request.POST, prefix="user") profileform = ProfileForm(request.POST, prefix="profile") + else: + userform = UserEditForm(request.POST, instance=user, prefix="user") + profileform = ProfileForm(request.POST, instance=user.profile, prefix="profile") - formlist = [userform, profileform] - formerror = 0 - for f in formlist: - if not f.is_valid(): - formerror += 1 - if formerror == 0: + if userform.is_valid and profileform.is_valid: user = userform.save() + if user_id is None: + user.username = gen_username(user.first_name, user.last_name) + user.save() profile = profileform.save(commit=False) profile.user = user profile.save() @@ -108,11 +107,13 @@ def edit(request, user_id=None): else: messages.error(request, _('Please check the form for errors.')) else: - userform = UserForm(instance=user, prefix="user") - try: - profileform = ProfileForm(instance=user.profile, prefix="profile") - except AttributeError: + if user_id is None: + userform = UserNewForm(prefix="user") profileform = ProfileForm(prefix="profile") + else: + userform = UserEditForm(instance=user, prefix="user") + profileform = ProfileForm(instance=user.profile, prefix="profile") + return { 'userform': userform, 'profileform': profileform, From 2c6c9b55eea0a182b97c314af0ae2da4a2837c9a Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sun, 4 Sep 2011 10:02:54 +0200 Subject: [PATCH 2/2] accept old application versions --- openslides/application/models.py | 9 ++++----- openslides/application/views.py | 7 ++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/openslides/application/models.py b/openslides/application/models.py index b386663be..e45215fb1 100644 --- a/openslides/application/models.py +++ b/openslides/application/models.py @@ -66,11 +66,10 @@ class Application(models.Model): """ accept a Version """ - if version.id > self.permitted.id: - self.permitted = version - self.save() - return True - return False + self.permitted = version + self.save() + version.rejected = False + version.save() def reject_version(self, version): if version.id > self.permitted.id: diff --git a/openslides/application/views.py b/openslides/application/views.py index 69fc77ea8..416121427 100644 --- a/openslides/application/views.py +++ b/openslides/application/views.py @@ -128,7 +128,7 @@ def edit(request, application_id=None): messages.success(request, _('New application was successfully created.')) else: messages.success(request, _('Application was successfully modified.')) - + if not 'apply' in request.POST: return redirect(reverse('application_view', args=[application.id])) if application_id is None: @@ -362,10 +362,7 @@ def view_poll(request, poll_id): def permit_version(request, aversion_id): aversion = AVersion.objects.get(pk=aversion_id) application = aversion.application - if application.accept_version(aversion): - messages.success(request, _("Version accepted") ) - else: - messages.error(request, _("ERROR by accepting the Version") ) + messages.success(request, _("Version accepted") ) return redirect(reverse('application_view', args=[application.id]))