some corrective actions

This commit is contained in:
Oskar Hahn 2012-08-13 14:37:49 +02:00
parent df40de67b0
commit 31ca01563e
7 changed files with 46 additions and 48 deletions

View File

@ -21,18 +21,14 @@ from openslides.participant.models import User, Group
class UserCreateForm(forms.ModelForm, CssClassMixin):
first_name = forms.CharField(label=_("First name"))
last_name = forms.CharField(label=_("Last name"))
groups = forms.ModelMultipleChoiceField(
queryset=Group.objects.exclude(name__iexact='anonymous'),
label=_("User groups"), required=False)
is_active = forms.BooleanField(
label=_("Active"), required=False, initial=True)
class Meta:
model = User
fields = ('first_name', 'last_name', 'is_active', 'groups', 'category',
'gender', 'type', 'committee', 'comment', 'firstpassword')
'gender', 'type', 'committee', 'comment', 'default_password')
class UserUpdateForm(UserCreateForm):
@ -40,7 +36,7 @@ class UserUpdateForm(UserCreateForm):
model = User
fields = ('username', 'first_name', 'last_name', 'is_active', 'groups',
'category', 'gender', 'type', 'committee', 'comment',
'firstpassword')
'default_password')
class GroupForm(forms.ModelForm, CssClassMixin):

View File

@ -17,7 +17,7 @@ from django.dispatch import receiver
from django.utils.translation import ugettext_lazy as _, ugettext_noop
from openslides.utils.person import PersonMixin
from openslides.utils.person.signals import receiv_persons
from openslides.utils.person.signals import receive_persons
from openslides.config.signals import default_config_value
@ -51,27 +51,24 @@ class User(DjangoUser, PersonMixin):
comment = models.TextField(
null=True, blank=True, verbose_name=_('Comment'),
help_text=_('Only for notes.'))
# TODO: Rename this fild to default_password
firstpassword = models.CharField(
default_password = models.CharField(
max_length=100, null=True, blank=True,
verbose_name=_("First Password"))
verbose_name=_("Default password"))
save_user_object = False
def get_name_surfix(self):
def get_name_suffix(self):
return self.category
def set_name_surfix(self, value):
def set_name_suffix(self, value):
self.category = value
name_surfix = property(get_name_surfix, set_name_surfix)
name_suffix = property(get_name_suffix, set_name_suffix)
def reset_password(self, password=None):
"""
Reset the password for the user to his default-password.
"""
if password is None:
password = self.firstpassword
password = self.default_password
self.set_password(password)
self.save()
@ -90,9 +87,9 @@ class User(DjangoUser, PersonMixin):
return ('user_delete', [str(self.id)])
def __unicode__(self):
name = self.get_full_name() or _("No Name yet")
if self.name_surfix:
return u"%s (%s)" % (name, self.name_surfix)
name = self.get_full_name() or self.username
if self.name_suffix:
return u"%s (%s)" % (name, self.name_suffix)
return u"%s" % name
class Meta:
@ -129,36 +126,38 @@ class Group(DjangoGroup, PersonMixin):
return unicode(self.name)
class UsersConnecter(object):
def __init__(self, person_prefix=None, id=None):
self.person_prefix = person_prefix
self.id = id
class UsersConnector(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()
self.groups = Group.objects.filter(group_as_person=True)
def __iter__(self):
if (not self.person_prefix or
self.person_prefix == User.person_prefix):
if self.id:
yield User.objects.get(pk=self.id)
if (not self.person_prefix_filter or
self.person_prefix_filter == User.person_prefix):
if self.id_filter:
yield users.get(pk=self.id_filter)
else:
for user in User.objects.all():
for user in self.users:
yield user
if (not self.person_prefix or
self.person_prefix == Group.person_prefix):
if self.id:
yield Group.objects.filter(group_as_person=True).get(pk=self.id)
if (not self.person_prefix_filter or
self.person_prefix_filter == Group.person_prefix):
if self.id_filter:
yield groups.get(pk=self.id_filter)
else:
for group in Group.objects.filter(group_as_person=True):
for group in self.groups:
yield group
def __getitem__(self, key):
return User.objects.get(pk=key)
@receiver(receiv_persons, dispatch_uid="participant")
def receiv_persons(sender, **kwargs):
return UsersConnecter(person_prefix=kwargs['person_prefix'],
id=kwargs['id'])
@receiver(receive_persons, dispatch_uid="participant")
def receive_persons(sender, **kwargs):
return UsersConnecter(person_prefix_filter=kwargs['person_prefix_filter'],
id=kwargs['id_filter'])
@receiver(default_config_value, dispatch_uid="participant_default_config")

View File

@ -70,4 +70,7 @@ class GroupTest(TestCase):
self.assertTrue(hasattr(self.group1, 'person_id'))
person_id = "group:%d" % self.group1.id
self.assertEqual(self.group1.person_id, person_id)
self.assertRaises(Group.DoesNotExist)
self.group1.group_as_person = True
self.group1.save()
self.assertEqual(get_person(person_id), self.group1)

View File

@ -149,8 +149,8 @@ class UserCreateView(CreateView):
def manipulate_object(self, form):
self.object.username = gen_username(form.cleaned_data['first_name'],
form.cleaned_data['last_name'])
if not self.object.firstpassword:
self.object.firstpassword = gen_password()
if not self.object.default_password:
self.object.default_password = gen_password()
class UserUpdateView(UpdateView):

View File

@ -10,7 +10,7 @@
:license: GNU GPL, see LICENSE for more details.
"""
from openslides.utils.person.signals import receiv_persons
from openslides.utils.person.signals import receive_persons
from openslides.utils.person.api import generate_person_id, get_person, Persons
from openslides.utils.person.forms import PersonFormField, MultiplePersonFormField
from openslides.utils.person.models import PersonField, PersonMixin

View File

@ -10,16 +10,16 @@
:license: GNU GPL, see LICENSE for more details.
"""
from openslides.utils.person.signals import receiv_persons
from openslides.utils.person.signals import receive_persons
class Persons(object):
"""
A Storage for a multiplicity of different Person-Objects.
"""
def __init__(self, person_prefix=None, id=None):
self.person_prefix = person_prefix
self.id = id
def __init__(self, person_prefix_filter=None, id_filter=None):
self.person_prefix_filter = person_prefix_filter
self.id_filter = id_filter
def __iter__(self):
try:
@ -35,8 +35,8 @@ class Persons(object):
def iter_persons(self):
self._cache = list()
for receiver, persons in receiv_persons.send(
sender='persons', person_prefix=self.person_prefix, id=self.id):
for receiver, persons in receive_persons.send(
sender='persons', person_prefix_filter=self.person_prefix_filter, id_filter=self.id_filter):
for person in persons:
self._cache.append(person)
yield person
@ -63,4 +63,4 @@ def get_person(person_id):
except TypeError:
from openslides.utils.person import EmtyPerson
return EmtyPerson()
return Persons(person_prefix=person_prefix, id=id)[0]
return Persons(person_prefix_filter=person_prefix, id_filter=id)[0]

View File

@ -12,4 +12,4 @@
from django.dispatch import Signal
receiv_persons = Signal(providing_args=['person_prefix', 'id'])
receive_persons = Signal(providing_args=['person_prefix_filter', 'id_filter'])