some pep8 corections for the participant app

This commit is contained in:
Oskar Hahn 2012-08-08 10:34:23 +02:00
parent f22362df9d
commit d1ab2f2e85
3 changed files with 103 additions and 94 deletions

View File

@ -15,7 +15,8 @@ from django.contrib.auth.forms import AdminPasswordChangeForm
from django.contrib.auth.models import User, Group, Permission
from django.utils.translation import ugettext_lazy as _, ugettext_noop
from openslides.utils.forms import CssClassMixin, LocalizedModelMultipleChoiceField
from openslides.utils.forms import (
CssClassMixin, LocalizedModelMultipleChoiceField)
from openslides.participant.models import OpenSlidesUser
@ -30,10 +31,10 @@ USER_APPLICATION_IMPORT_OPTIONS = [
class UserNewForm(forms.ModelForm, CssClassMixin):
first_name = forms.CharField(label=_("First name"))
last_name = forms.CharField(label=_("Last name"))
groups = forms.ModelMultipleChoiceField(queryset=Group.objects.all(),
label=_("User groups"), required=False)
is_active = forms.BooleanField(label=_("Active"), required=False,
initial=True)
groups = forms.ModelMultipleChoiceField(
queryset=Group.objects.all(), label=_("User groups"), required=False)
is_active = forms.BooleanField(
label=_("Active"), required=False, initial=True)
class Meta:
model = User
@ -44,8 +45,8 @@ class UserNewForm(forms.ModelForm, CssClassMixin):
class UserEditForm(forms.ModelForm, CssClassMixin):
first_name = forms.CharField(label=_("First name"))
last_name = forms.CharField(label=_("Last name"))
groups = forms.ModelMultipleChoiceField(queryset=Group.objects.all(),
label=_("User groups"), required=False)
groups = forms.ModelMultipleChoiceField(
queryset=Group.objects.all(), label=_("User groups"), required=False)
is_active = forms.BooleanField(label=_("Active"), required=False)
class Meta:
@ -58,8 +59,8 @@ class UsernameForm(forms.ModelForm, CssClassMixin):
class Meta:
model = User
exclude = ('first_name', 'last_name', 'email', 'is_active',
'is_superuser', 'groups', 'password', 'is_staff', 'last_login',
'date_joined', 'user_permissions')
'is_superuser', 'groups', 'password', 'is_staff',
'last_login', 'date_joined', 'user_permissions')
class OpenSlidesUserForm(forms.ModelForm, CssClassMixin):
@ -68,8 +69,8 @@ class OpenSlidesUserForm(forms.ModelForm, CssClassMixin):
class GroupForm(forms.ModelForm, CssClassMixin):
as_user = forms.BooleanField(initial=False, required=False,
label=_("Treat Group as User"),
as_user = forms.BooleanField(
initial=False, required=False, label=_("Treat Group as User"),
help_text=_("The Group will appear on any place, other user does."))
permissions = LocalizedModelMultipleChoiceField(
queryset=Permission.objects.all(), label=_("Persmissions"))
@ -77,8 +78,8 @@ class GroupForm(forms.ModelForm, CssClassMixin):
def __init__(self, *args, **kwargs):
super(GroupForm, self).__init__(*args, **kwargs)
if kwargs.get('instance', None) is not None:
self.fields['permissions'].initial = \
[p.pk for p in kwargs['instance'].permissions.all()]
self.fields['permissions'].initial = (
[p.pk for p in kwargs['instance'].permissions.all()])
class Meta:
model = Group
@ -95,10 +96,8 @@ class UserImportForm(forms.Form, CssClassMixin):
csvfile = forms.FileField(widget=forms.FileInput(attrs={'size': '50'}),
label=_("CSV File"))
application_handling = forms.ChoiceField(
required=True,
choices=USER_APPLICATION_IMPORT_OPTIONS,
label=_("For existing applications"),
)
required=True, choices=USER_APPLICATION_IMPORT_OPTIONS,
label=_("For existing applications"))
class ConfigForm(forms.Form, CssClassMixin):
@ -106,11 +105,9 @@ class ConfigForm(forms.Form, CssClassMixin):
widget=forms.TextInput(),
required=False,
label=_("System URL"),
help_text=_("Printed in PDF of first time passwords only."),
)
help_text=_("Printed in PDF of first time passwords only."))
participant_pdf_welcometext = forms.CharField(
widget=forms.Textarea(),
required=False,
label=_("Welcome text"),
help_text=_("Printed in PDF of first time passwords only."),
)
help_text=_("Printed in PDF of first time passwords only."))

View File

@ -36,19 +36,23 @@ class OpenSlidesUser(models.Model, PersonMixin):
)
user = models.OneToOneField(User, unique=True, editable=False)
name_surfix = models.CharField(max_length=100, null=True, blank=True,
verbose_name = _("Name Surfix"), help_text=_('Shown behind the name.'))
gender = models.CharField(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,
name_surfix = models.CharField(
max_length=100, null=True, blank=True, verbose_name=_("Name Surfix"),
help_text=_('Shown behind the name.'))
gender = models.CharField(
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,
verbose_name=_("Typ"), help_text=_('Only for filter the userlist.'))
committee = models.CharField(max_length=100, null=True, blank=True,
verbose_name = _("Committee"),
committee = models.CharField(
max_length=100, null=True, blank=True, verbose_name=_("Committee"),
help_text=_('Only for filter the userlist.'))
comment = models.TextField(null=True, blank=True,
verbose_name = _('Comment'), help_text=_('Only for notes.'))
firstpassword = models.CharField(max_length=100, null=True, blank=True,
comment = models.TextField(
null=True, blank=True, verbose_name=_('Comment'),
help_text=_('Only for notes.'))
firstpassword = models.CharField(
max_length=100, null=True, blank=True,
verbose_name=_("First Password"))
def reset_password(self, password=None):
@ -82,12 +86,12 @@ class OpenSlidesUser(models.Model, PersonMixin):
return "%s (%s)" % (self.user.get_full_name(), self.name_surfix)
return "%s" % self.user.get_full_name()
class Meta:
# Rename permissions
permissions = (
('can_see_participant', ugettext_noop("Can see participant")),
('can_manage_participant', ugettext_noop("Can manage participant")),
('can_manage_participant',
ugettext_noop("Can manage participant")),
)
@ -107,14 +111,16 @@ class OpenSlidesUsersConnecter(object):
self.id = id
def __iter__(self):
if not self.person_prefix or self.person_prefix == OpenSlidesUser.person_prefix:
if (not self.person_prefix or
self.person_prefix == OpenSlidesUser.person_prefix):
if self.id:
yield OpenSlidesUser.objects.get(pk=self.id)
else:
for user in OpenSlidesUser.objects.all():
yield user
if not self.person_prefix or self.person_prefix == OpenSlidesGroup.person_prefix:
if (not self.person_prefix or
self.person_prefix == OpenSlidesGroup.person_prefix):
if self.id:
yield OpenSlidesGroup.objects.get(pk=self.id)
else:
@ -127,7 +133,8 @@ class OpenSlidesUsersConnecter(object):
@receiver(receiv_persons, dispatch_uid="participant")
def receiv_persons(sender, **kwargs):
return OpenSlidesUsersConnecter(person_prefix=kwargs['person_prefix'], id=kwargs['id'])
return OpenSlidesUsersConnecter(person_prefix=kwargs['person_prefix'],
id=kwargs['id'])
@receiver(default_config_value, dispatch_uid="participant_default_config")

View File

@ -23,8 +23,9 @@ except ImportError: # python <= 2.5 grab it from cgi
from reportlab.lib import colors
from reportlab.lib.units import cm
from reportlab.platypus import (SimpleDocTemplate, PageBreak, Paragraph,
LongTable, Spacer, Table, TableStyle)
from reportlab.platypus import (
SimpleDocTemplate, PageBreak, Paragraph, LongTable, Spacer, Table,
TableStyle)
from django.db import transaction
from django.contrib import messages
@ -39,18 +40,18 @@ from django.utils.translation import ugettext as _, ungettext, ugettext_lazy
from openslides.utils import csv_ext
from openslides.utils.pdf import stylesheet
from openslides.utils.template import Tab
from openslides.utils.utils import (template, permission_required,
gen_confirm_form, ajax_request, decodedict, encodedict,
delete_default_permissions, html_strong)
from openslides.utils.utils import (
template, permission_required, gen_confirm_form, ajax_request, decodedict,
encodedict, delete_default_permissions, html_strong)
from openslides.utils.views import FormView, PDFView
from openslides.config.models import config
from openslides.participant.models import OpenSlidesUser, OpenSlidesGroup
from openslides.participant.api import gen_username, gen_password
from openslides.participant.forms import (UserNewForm, UserEditForm,
OpenSlidesUserForm, UsersettingsForm, UserImportForm, GroupForm,
AdminPasswordChangeForm, ConfigForm)
from openslides.participant.forms import (
UserNewForm, UserEditForm, OpenSlidesUserForm, UsersettingsForm,
UserImportForm, GroupForm, AdminPasswordChangeForm, ConfigForm)
@permission_required('participant.can_see_participant')
@ -78,21 +79,26 @@ def get_overview(request):
query = User.objects
if 'gender' in sortfilter:
query = query.filter(openslidesuser__gender__iexact=sortfilter['gender'][0])
query = query.filter(
openslidesuser__gender__iexact=sortfilter['gender'][0])
if 'group' in sortfilter:
query = query.filter(openslidesuser__group__iexact=sortfilter['name_surfix'][0])
query = query.filter(
openslidesuser__group__iexact=sortfilter['name_surfix'][0])
if 'type' in sortfilter:
query = query.filter(openslidesuser__type__iexact=sortfilter['type'][0])
query = query.filter(
openslidesuser__type__iexact=sortfilter['type'][0])
if 'committee' in sortfilter:
query = query. \
filter(openslidesuser__committee__iexact=sortfilter['committee'][0])
query = query.filter(
openslidesuser__committee__iexact=sortfilter['committee'][0])
if 'status' in sortfilter:
query = query.filter(is_active=sortfilter['status'][0])
if 'sort' in sortfilter:
if sortfilter['sort'][0] in ['first_name', 'last_name', 'last_login']:
query = query.order_by(sortfilter['sort'][0])
elif sortfilter['sort'][0] in ['name_surfix', 'type', 'committee', 'comment']:
query = query.order_by('openslidesuser__%s' % sortfilter['sort'][0])
elif (sortfilter['sort'][0] in
['name_surfix', 'type', 'committee', 'comment']):
query = query.order_by(
'openslidesuser__%s' % sortfilter['sort'][0])
else:
query = query.order_by('last_name')
if 'reverse' in sortfilter:
@ -123,10 +129,10 @@ def get_overview(request):
else:
percent = 0
# list of all existing groups
groups = [p['name_surfix'] for p in OpenSlidesUser.objects.values('name_surfix') \
groups = [p['name_surfix'] for p in OpenSlidesUser.objects.values('name_surfix')
.exclude(name_surfix='').distinct()]
# list of all existing committees
committees = [p['committee'] for p in OpenSlidesUser.objects.values('committee') \
committees = [p['committee'] for p in OpenSlidesUser.objects.values('committee')
.exclude(committee='').distinct()]
return {
'users': users,
@ -317,7 +323,6 @@ def group_edit(request, group_id=None):
elif not form.cleaned_data['as_user'] and django_group:
django_group.delete()
if anonymous_group is not None and \
anonymous_group.id == group.id:
# prevent name changes -
@ -641,13 +646,14 @@ class ParticipantsListPDF(PDFView):
try:
counter += 1
user.get_profile()
data.append([counter,
data.append([
counter,
Paragraph(user.last_name, stylesheet['Tablecell']),
Paragraph(user.first_name, stylesheet['Tablecell']),
Paragraph(user.profile.group, stylesheet['Tablecell']),
Paragraph(user.profile.get_type_display(),
stylesheet['Tablecell']),
Paragraph(user.profile.committee, stylesheet['Tablecell']),
Paragraph(user.profile.committee, stylesheet['Tablecell'])
])
except Profile.DoesNotExist:
counter -= 1
@ -659,8 +665,7 @@ class ParticipantsListPDF(PDFView):
('LINEABOVE', (0, 1), (-1, 1), 1, colors.black),
('LINEBELOW', (0, -1), (-1, -1), 2, colors.black),
('ROWBACKGROUNDS', (0, 1), (-1, -1),
(colors.white, (.9, .9, .9))),
])
(colors.white, (.9, .9, .9)))])
t._argW[0] = 0.75 * cm
story.append(t)
@ -711,7 +716,7 @@ class ParticipantsPasswordsPDF(PDFView):
stylesheet['Ballot_subtitle']))
data.append([cell, cell2])
except Profile.DoesNotExist:
except OpenSlidesUser.DoesNotExist:
pass
# add empty table line if no participants available
if data == []: