diff --git a/openslides/participant/forms.py b/openslides/participant/forms.py index 93e6b22df..4fb13a570 100644 --- a/openslides/participant/forms.py +++ b/openslides/participant/forms.py @@ -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): diff --git a/openslides/participant/models.py b/openslides/participant/models.py index 83b484432..8daf6fcdc 100644 --- a/openslides/participant/models.py +++ b/openslides/participant/models.py @@ -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") diff --git a/openslides/participant/tests.py b/openslides/participant/tests.py index bbcda6cf7..4bba1168d 100644 --- a/openslides/participant/tests.py +++ b/openslides/participant/tests.py @@ -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) diff --git a/openslides/participant/views.py b/openslides/participant/views.py index 27abb541e..64538db49 100644 --- a/openslides/participant/views.py +++ b/openslides/participant/views.py @@ -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): diff --git a/openslides/utils/person/__init__.py b/openslides/utils/person/__init__.py index e54e6258a..da896616f 100644 --- a/openslides/utils/person/__init__.py +++ b/openslides/utils/person/__init__.py @@ -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 diff --git a/openslides/utils/person/api.py b/openslides/utils/person/api.py index 2fe48a4ee..55b4691a8 100644 --- a/openslides/utils/person/api.py +++ b/openslides/utils/person/api.py @@ -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] diff --git a/openslides/utils/person/signals.py b/openslides/utils/person/signals.py index 5d8dba88b..32d5879b4 100644 --- a/openslides/utils/person/signals.py +++ b/openslides/utils/person/signals.py @@ -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'])