removed unused imports from participant and did some pep8 changes

This commit is contained in:
Oskar Hahn 2012-08-11 10:51:52 +02:00
parent bc3e7fdaab
commit f01fe5a894
5 changed files with 64 additions and 77 deletions

View File

@ -21,7 +21,6 @@ from django.contrib.auth.models import User
from django.db import transaction from django.db import transaction
from openslides.utils import csv_ext from openslides.utils import csv_ext
from openslides.utils.person import get_person
from openslides.participant.models import OpenSlidesUser from openslides.participant.models import OpenSlidesUser
@ -55,6 +54,7 @@ def gen_username(first_name, last_name):
except User.DoesNotExist: except User.DoesNotExist:
return testname return testname
def import_users(csv_file): def import_users(csv_file):
error_messages = [] error_messages = []
count_success = 0 count_success = 0
@ -68,7 +68,8 @@ def import_users(csv_file):
dialect = csv_ext.patchup(dialect) dialect = csv_ext.patchup(dialect)
csv_file.seek(0) csv_file.seek(0)
for (line_no, line) in enumerate(csv.reader(csv_file, dialect=dialect)): for (line_no, line) in enumerate(csv.reader(csv_file,
dialect=dialect)):
if line_no: if line_no:
try: try:
(first_name, last_name, gender, category, type, committee, comment) = line[:7] (first_name, last_name, gender, category, type, committee, comment) = line[:7]

View File

@ -11,9 +11,8 @@
""" """
from django import forms from django import forms
from django.contrib.auth.forms import AdminPasswordChangeForm from django.contrib.auth.models import Permission
from django.contrib.auth.models import User, Group, Permission from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext_lazy as _, ugettext_noop
from openslides.utils.forms import ( from openslides.utils.forms import (
CssClassMixin, LocalizedModelMultipleChoiceField) CssClassMixin, LocalizedModelMultipleChoiceField)
@ -25,7 +24,8 @@ class UserCreateForm(forms.ModelForm, CssClassMixin):
first_name = forms.CharField(label=_("First name")) first_name = forms.CharField(label=_("First name"))
last_name = forms.CharField(label=_("Last name")) last_name = forms.CharField(label=_("Last name"))
groups = forms.ModelMultipleChoiceField( groups = forms.ModelMultipleChoiceField(
queryset=Group.objects.all(), label=_("User groups"), required=False) queryset=OpenSlidesGroup.objects.all(), label=_("User groups"),
required=False)
is_active = forms.BooleanField( is_active = forms.BooleanField(
label=_("Active"), required=False, initial=True) label=_("Active"), required=False, initial=True)
@ -67,14 +67,13 @@ class GroupForm(forms.ModelForm, CssClassMixin):
_('Group name "%s" is reserved for internal use.') % data) _('Group name "%s" is reserved for internal use.') % data)
return data return data
class Meta: class Meta:
model = OpenSlidesGroup model = OpenSlidesGroup
class UsersettingsForm(forms.ModelForm, CssClassMixin): class UsersettingsForm(forms.ModelForm, CssClassMixin):
class Meta: class Meta:
model = User model = OpenSlidesUser
fields = ('username', 'first_name', 'last_name', 'email') fields = ('username', 'first_name', 'last_name', 'email')

View File

@ -12,7 +12,7 @@
from django.contrib.auth.models import User, Group from django.contrib.auth.models import User, Group
from django.db import models from django.db import models
from django.db.models import Q, signals from django.db.models import signals
from django.dispatch import receiver from django.dispatch import receiver
from django.utils.translation import ugettext_lazy as _, ugettext_noop from django.utils.translation import ugettext_lazy as _, ugettext_noop

View File

@ -12,8 +12,6 @@
from django.test import TestCase from django.test import TestCase
from django.test.client import Client from django.test.client import Client
from django.contrib.auth.models import User, Group
from django.db.models.query import EmptyQuerySet
from django.contrib.auth.hashers import check_password from django.contrib.auth.hashers import check_password
from openslides.utils.person import get_person, Persons from openslides.utils.person import get_person, Persons
@ -23,10 +21,11 @@ from openslides.participant.models import OpenSlidesUser, OpenSlidesGroup
class OpenSlidesUserTest(TestCase): class OpenSlidesUserTest(TestCase):
def setUp(self): def setUp(self):
self.user1 = User(first_name=u'Max', last_name=u'Mustermann') self.openslidesuser1 = OpenSlidesUser()
self.user1.username = gen_username(self.user1.first_name, self.user1.last_name) self.openslidesuser1.first_name = u'Max'
self.user1.save() self.openslidesuser1.last_name = u'Mustermann'
self.openslidesuser1 = self.user1.openslidesuser self.openslidesuser1.username = gen_username(
self.openslidesuser1.first_name, self.openslidesuser1.last_name)
self.openslidesuser1.firstpassword = gen_password() self.openslidesuser1.firstpassword = gen_password()
self.openslidesuser1.save() self.openslidesuser1.save()
self.user1 = self.openslidesuser1.user self.user1 = self.openslidesuser1.user
@ -57,27 +56,17 @@ class OpenSlidesUserTest(TestCase):
self.assertEqual(get_person('openslides_user:1'), self.openslidesuser1) self.assertEqual(get_person('openslides_user:1'), self.openslidesuser1)
self.assertEqual(len(Persons(person_prefix='openslides_user')), 1) self.assertEqual(len(Persons(person_prefix='openslides_user')), 1)
def test_save_name(self):
self.assertEqual(self.openslidesuser1.first_name, self.user1.first_name)
self.assertEqual(self.openslidesuser1.last_name, self.user1.last_name)
self.openslidesuser1.first_name = 'foo'
self.openslidesuser1.last_name = 'bar'
self.openslidesuser1.save()
user1 = User.objects.get(pk=1)
self.assertEqual(user1.first_name, 'foo')
self.assertEqual(user1.last_name, 'bar')
self.assertEqual(user1.get_full_name(), 'foo bar')
class OpenSlidesGroupTest(TestCase): class OpenSlidesGroupTest(TestCase):
def setUp(self): def setUp(self):
self.group1 = Group.objects.create(name='Test Group') self.openslidesgroup1 = OpenSlidesGroup.objects.create(name='Test Group')
self.openslidesgroup1 = OpenSlidesGroup.objects.create(group=self.group1) self.group1 = self.openslidesgroup1.group
def test_group_openslidesgroup(self): def test_group_openslidesgroup(self):
self.assertEqual(self.openslidesgroup1.group, self.group1) self.assertEqual(self.openslidesgroup1.group, self.group1)
def test_person_api(self): def test_person_api(self):
self.assertTrue(hasattr(self.openslidesgroup1, 'person_id')) self.assertTrue(hasattr(self.openslidesgroup1, 'person_id'))
self.assertEqual(self.openslidesgroup1.person_id, 'openslides_group:1') person_id = "openslides_group:%d" % self.openslidesgroup1.id
self.assertEqual(get_person('openslides_group:1'), self.openslidesgroup1) self.assertEqual(self.openslidesgroup1.person_id, person_id)
self.assertEqual(get_person(person_id), self.openslidesgroup1)

View File

@ -13,7 +13,6 @@
# for python 2.5 support # for python 2.5 support
from __future__ import with_statement from __future__ import with_statement
import csv
from urllib import urlencode from urllib import urlencode
try: try:
@ -24,36 +23,31 @@ except ImportError: # python <= 2.5 grab it from cgi
from reportlab.lib import colors from reportlab.lib import colors
from reportlab.lib.units import cm from reportlab.lib.units import cm
from reportlab.platypus import ( from reportlab.platypus import (
SimpleDocTemplate, PageBreak, Paragraph, LongTable, Spacer, Table, SimpleDocTemplate, Paragraph, LongTable, Spacer, Table, TableStyle)
TableStyle)
from django.db import transaction
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User, Group
from django.contrib.auth.forms import PasswordChangeForm from django.contrib.auth.forms import PasswordChangeForm
from django.contrib.auth.views import login as django_login from django.contrib.auth.views import login as django_login
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.shortcuts import redirect from django.shortcuts import redirect
from django.utils.translation import ugettext as _, ungettext, ugettext_lazy from django.utils.translation import ugettext as _, ugettext_lazy
from openslides.utils import csv_ext
from openslides.utils.pdf import stylesheet from openslides.utils.pdf import stylesheet
from openslides.utils.template import Tab from openslides.utils.template import Tab
from openslides.utils.utils import ( from openslides.utils.utils import (
template, permission_required, gen_confirm_form, ajax_request, decodedict, template, decodedict, encodedict, delete_default_permissions, html_strong)
encodedict, delete_default_permissions, html_strong)
from openslides.utils.views import ( from openslides.utils.views import (
FormView, PDFView, TemplateView, CreateView, UpdateView, DeleteView, FormView, PDFView, CreateView, UpdateView, DeleteView,
RedirectView, SingleObjectMixin, ListView, QuestionMixin) RedirectView, SingleObjectMixin, ListView, QuestionMixin)
from openslides.config.models import config from openslides.config.models import config
from openslides.participant.models import OpenSlidesUser, OpenSlidesGroup
from openslides.participant.api import gen_username, gen_password, import_users from openslides.participant.api import gen_username, gen_password, import_users
from openslides.participant.forms import ( from openslides.participant.forms import (
UserCreateForm, UserUpdateForm, UsersettingsForm, UserCreateForm, UserUpdateForm, UsersettingsForm,
UserImportForm, GroupForm, AdminPasswordChangeForm, ConfigForm) UserImportForm, GroupForm, ConfigForm)
from openslides.participant.models import OpenSlidesUser, OpenSlidesGroup
class Overview(ListView): class Overview(ListView):
@ -152,7 +146,8 @@ class UserCreateView(CreateView):
apply_url = 'participant_edit' apply_url = 'participant_edit'
def manipulate_object(self, form): def manipulate_object(self, form):
self.object.username = gen_username(form.cleaned_data['first_name'], form.cleaned_data['last_name']) self.object.username = gen_username(form.cleaned_data['first_name'],
form.cleaned_data['last_name'])
if not self.object.firstpassword: if not self.object.firstpassword:
self.object.firstpassword = gen_password() self.object.firstpassword = gen_password()
@ -227,10 +222,8 @@ class ParticipantsListPDF(PDFView):
Paragraph(user.first_name, stylesheet['Tablecell']), Paragraph(user.first_name, stylesheet['Tablecell']),
Paragraph(user.category, stylesheet['Tablecell']), Paragraph(user.category, stylesheet['Tablecell']),
Paragraph(user.type, stylesheet['Tablecell']), Paragraph(user.type, stylesheet['Tablecell']),
Paragraph(user.committee, stylesheet['Tablecell']) Paragraph(user.committee, stylesheet['Tablecell'])])
]) t = LongTable(data, style=[
t = LongTable(data,
style=[
('VALIGN', (0, 0), (-1, -1), 'TOP'), ('VALIGN', (0, 0), (-1, -1), 'TOP'),
('LINEABOVE', (0, 0), (-1, 0), 2, colors.black), ('LINEABOVE', (0, 0), (-1, 0), 2, colors.black),
('LINEABOVE', (0, 1), (-1, 1), 1, colors.black), ('LINEABOVE', (0, 1), (-1, 1), 1, colors.black),
@ -250,7 +243,8 @@ class ParticipantsPasswordsPDF(PDFView):
top_space = 0 top_space = 0
def get_template(self, buffer): def get_template(self, buffer):
return SimpleDocTemplate(buffer, topMargin=-6, bottomMargin=-6, return SimpleDocTemplate(
buffer, topMargin=-6, bottomMargin=-6,
leftMargin=0, rightMargin=0, showBoundary=False) leftMargin=0, rightMargin=0, showBoundary=False)
def build_document(self, pdf_document, story): def build_document(self, pdf_document, story):
@ -270,11 +264,14 @@ class ParticipantsPasswordsPDF(PDFView):
cell.append(Spacer(0, 0.5 * cm)) cell.append(Spacer(0, 0.5 * cm))
cell.append(Paragraph(_("User: %s") % (user.username), cell.append(Paragraph(_("User: %s") % (user.username),
stylesheet['Monotype'])) stylesheet['Monotype']))
cell.append(Paragraph(_("Password: %s") cell.append(
Paragraph(
_("Password: %s")
% (user.firstpassword), stylesheet['Monotype'])) % (user.firstpassword), stylesheet['Monotype']))
cell.append(Spacer(0, 0.5 * cm)) cell.append(Spacer(0, 0.5 * cm))
cell.append(Paragraph(_("URL: %s") cell.append(
% (participant_pdf_system_url), Paragraph(
_("URL: %s") % (participant_pdf_system_url),
stylesheet['Ballot_option'])) stylesheet['Ballot_option']))
cell.append(Spacer(0, 0.5 * cm)) cell.append(Spacer(0, 0.5 * cm))
cell2 = [] cell2 = []
@ -314,7 +311,9 @@ class UserImportView(FormView):
for message in error_messages: for message in error_messages:
messages.error(self.request, message) messages.error(self.request, message)
if success: if success:
messages.success(self.request, _('%d new participants were successfully imported.') % success) messages.success(
self.request,
_('%d new participants were successfully imported.') % success)
return super(UserImportView, self).form_valid(form) return super(UserImportView, self).form_valid(form)
@ -341,7 +340,7 @@ class ResetPasswordView(RedirectView, SingleObjectMixin, QuestionMixin):
if self.get_answer().lower() == 'yes': if self.get_answer().lower() == 'yes':
self.object.reset_password() self.object.reset_password()
messages.success(request, messages.success(request,
_('The Password for <b>%s</b> was successfully reset.') % self.object) _('The Password for %s was successfully reset.') % html_strong(self.object))
def get_answer_url(self): def get_answer_url(self):
return reverse('user_reset_password', args=[self.object.id]) return reverse('user_reset_password', args=[self.object.id])
@ -412,15 +411,15 @@ class Config(FormView):
def get_initial(self): def get_initial(self):
return { return {
'participant_pdf_system_url': config['participant_pdf_system_url'], 'participant_pdf_system_url': config['participant_pdf_system_url'],
'participant_pdf_welcometext': config['participant_pdf_welcometext'] 'participant_pdf_welcometext': config['participant_pdf_welcometext']}
}
def form_valid(self, form): def form_valid(self, form):
config['participant_pdf_system_url'] = \ config['participant_pdf_system_url'] = (
form.cleaned_data['participant_pdf_system_url'] form.cleaned_data['participant_pdf_system_url'])
config['participant_pdf_welcometext'] = \ config['participant_pdf_welcometext'] = (
form.cleaned_data['participant_pdf_welcometext'] form.cleaned_data['participant_pdf_welcometext'])
messages.success(self.request, messages.success(
self.request,
_('Participants settings successfully saved.')) _('Participants settings successfully saved.'))
return super(Config, self).form_valid(form) return super(Config, self).form_valid(form)
@ -478,8 +477,8 @@ def login(request):
"Installation was successfully! Use %(user)s " "Installation was successfully! Use %(user)s "
"(password: %(password)s) for first login.<br>" "(password: %(password)s) for first login.<br>"
"<strong>Important:</strong> Please change the password after " "<strong>Important:</strong> Please change the password after "
"first login! Otherwise this message still appears for everyone " "first login! Otherwise this message still appears for "
"and could be a security risk.") % { "everyone and could be a security risk.") % {
'user': html_strong(admin.username), 'user': html_strong(admin.username),
'password': html_strong(config['admin_password'])} 'password': html_strong(config['admin_password'])}
extra_content['next'] = reverse('password_change') extra_content['next'] = reverse('password_change')
@ -496,7 +495,6 @@ def register_tab(request):
return Tab( return Tab(
title=_('Participants'), title=_('Participants'),
url=reverse('user_overview'), url=reverse('user_overview'),
permission=request.user.has_perm('participant.can_see_participant') permission=request.user.has_perm('participant.can_see_participant') or
or request.user.has_perm('participant.can_manage_participant'), request.user.has_perm('participant.can_manage_participant'),
selected=selected, selected=selected)
)