some corrective actions
This commit is contained in:
parent
df40de67b0
commit
31ca01563e
@ -21,18 +21,14 @@ from openslides.participant.models import User, Group
|
|||||||
|
|
||||||
|
|
||||||
class UserCreateForm(forms.ModelForm, CssClassMixin):
|
class UserCreateForm(forms.ModelForm, CssClassMixin):
|
||||||
first_name = forms.CharField(label=_("First name"))
|
|
||||||
last_name = forms.CharField(label=_("Last name"))
|
|
||||||
groups = forms.ModelMultipleChoiceField(
|
groups = forms.ModelMultipleChoiceField(
|
||||||
queryset=Group.objects.exclude(name__iexact='anonymous'),
|
queryset=Group.objects.exclude(name__iexact='anonymous'),
|
||||||
label=_("User groups"), required=False)
|
label=_("User groups"), required=False)
|
||||||
is_active = forms.BooleanField(
|
|
||||||
label=_("Active"), required=False, initial=True)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
fields = ('first_name', 'last_name', 'is_active', 'groups', 'category',
|
fields = ('first_name', 'last_name', 'is_active', 'groups', 'category',
|
||||||
'gender', 'type', 'committee', 'comment', 'firstpassword')
|
'gender', 'type', 'committee', 'comment', 'default_password')
|
||||||
|
|
||||||
|
|
||||||
class UserUpdateForm(UserCreateForm):
|
class UserUpdateForm(UserCreateForm):
|
||||||
@ -40,7 +36,7 @@ class UserUpdateForm(UserCreateForm):
|
|||||||
model = User
|
model = User
|
||||||
fields = ('username', 'first_name', 'last_name', 'is_active', 'groups',
|
fields = ('username', 'first_name', 'last_name', 'is_active', 'groups',
|
||||||
'category', 'gender', 'type', 'committee', 'comment',
|
'category', 'gender', 'type', 'committee', 'comment',
|
||||||
'firstpassword')
|
'default_password')
|
||||||
|
|
||||||
|
|
||||||
class GroupForm(forms.ModelForm, CssClassMixin):
|
class GroupForm(forms.ModelForm, CssClassMixin):
|
||||||
|
@ -17,7 +17,7 @@ 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
|
||||||
|
|
||||||
from openslides.utils.person import PersonMixin
|
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
|
from openslides.config.signals import default_config_value
|
||||||
|
|
||||||
@ -51,27 +51,24 @@ class User(DjangoUser, PersonMixin):
|
|||||||
comment = models.TextField(
|
comment = models.TextField(
|
||||||
null=True, blank=True, verbose_name=_('Comment'),
|
null=True, blank=True, verbose_name=_('Comment'),
|
||||||
help_text=_('Only for notes.'))
|
help_text=_('Only for notes.'))
|
||||||
# TODO: Rename this fild to default_password
|
default_password = models.CharField(
|
||||||
firstpassword = models.CharField(
|
|
||||||
max_length=100, null=True, blank=True,
|
max_length=100, null=True, blank=True,
|
||||||
verbose_name=_("First Password"))
|
verbose_name=_("Default password"))
|
||||||
|
|
||||||
save_user_object = False
|
def get_name_suffix(self):
|
||||||
|
|
||||||
def get_name_surfix(self):
|
|
||||||
return self.category
|
return self.category
|
||||||
|
|
||||||
def set_name_surfix(self, value):
|
def set_name_suffix(self, value):
|
||||||
self.category = 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):
|
def reset_password(self, password=None):
|
||||||
"""
|
"""
|
||||||
Reset the password for the user to his default-password.
|
Reset the password for the user to his default-password.
|
||||||
"""
|
"""
|
||||||
if password is None:
|
if password is None:
|
||||||
password = self.firstpassword
|
password = self.default_password
|
||||||
self.set_password(password)
|
self.set_password(password)
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
@ -90,9 +87,9 @@ class User(DjangoUser, PersonMixin):
|
|||||||
return ('user_delete', [str(self.id)])
|
return ('user_delete', [str(self.id)])
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
name = self.get_full_name() or _("No Name yet")
|
name = self.get_full_name() or self.username
|
||||||
if self.name_surfix:
|
if self.name_suffix:
|
||||||
return u"%s (%s)" % (name, self.name_surfix)
|
return u"%s (%s)" % (name, self.name_suffix)
|
||||||
return u"%s" % name
|
return u"%s" % name
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -129,36 +126,38 @@ class Group(DjangoGroup, PersonMixin):
|
|||||||
return unicode(self.name)
|
return unicode(self.name)
|
||||||
|
|
||||||
|
|
||||||
class UsersConnecter(object):
|
class UsersConnector(object):
|
||||||
def __init__(self, person_prefix=None, id=None):
|
def __init__(self, person_prefix_filter=None, id_filter=None):
|
||||||
self.person_prefix = person_prefix
|
self.person_prefix_filter = person_prefix_filter
|
||||||
self.id = id
|
self.id_filter = id_filter
|
||||||
|
self.users = User.objects.all()
|
||||||
|
self.groups = Group.objects.filter(group_as_person=True)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
if (not self.person_prefix or
|
if (not self.person_prefix_filter or
|
||||||
self.person_prefix == User.person_prefix):
|
self.person_prefix_filter == User.person_prefix):
|
||||||
if self.id:
|
if self.id_filter:
|
||||||
yield User.objects.get(pk=self.id)
|
yield users.get(pk=self.id_filter)
|
||||||
else:
|
else:
|
||||||
for user in User.objects.all():
|
for user in self.users:
|
||||||
yield user
|
yield user
|
||||||
|
|
||||||
if (not self.person_prefix or
|
if (not self.person_prefix_filter or
|
||||||
self.person_prefix == Group.person_prefix):
|
self.person_prefix_filter == Group.person_prefix):
|
||||||
if self.id:
|
if self.id_filter:
|
||||||
yield Group.objects.filter(group_as_person=True).get(pk=self.id)
|
yield groups.get(pk=self.id_filter)
|
||||||
else:
|
else:
|
||||||
for group in Group.objects.filter(group_as_person=True):
|
for group in self.groups:
|
||||||
yield group
|
yield group
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
return User.objects.get(pk=key)
|
return User.objects.get(pk=key)
|
||||||
|
|
||||||
|
|
||||||
@receiver(receiv_persons, dispatch_uid="participant")
|
@receiver(receive_persons, dispatch_uid="participant")
|
||||||
def receiv_persons(sender, **kwargs):
|
def receive_persons(sender, **kwargs):
|
||||||
return UsersConnecter(person_prefix=kwargs['person_prefix'],
|
return UsersConnecter(person_prefix_filter=kwargs['person_prefix_filter'],
|
||||||
id=kwargs['id'])
|
id=kwargs['id_filter'])
|
||||||
|
|
||||||
|
|
||||||
@receiver(default_config_value, dispatch_uid="participant_default_config")
|
@receiver(default_config_value, dispatch_uid="participant_default_config")
|
||||||
|
@ -70,4 +70,7 @@ class GroupTest(TestCase):
|
|||||||
self.assertTrue(hasattr(self.group1, 'person_id'))
|
self.assertTrue(hasattr(self.group1, 'person_id'))
|
||||||
person_id = "group:%d" % self.group1.id
|
person_id = "group:%d" % self.group1.id
|
||||||
self.assertEqual(self.group1.person_id, person_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)
|
self.assertEqual(get_person(person_id), self.group1)
|
||||||
|
@ -149,8 +149,8 @@ class UserCreateView(CreateView):
|
|||||||
def manipulate_object(self, form):
|
def manipulate_object(self, form):
|
||||||
self.object.username = gen_username(form.cleaned_data['first_name'],
|
self.object.username = gen_username(form.cleaned_data['first_name'],
|
||||||
form.cleaned_data['last_name'])
|
form.cleaned_data['last_name'])
|
||||||
if not self.object.firstpassword:
|
if not self.object.default_password:
|
||||||
self.object.firstpassword = gen_password()
|
self.object.default_password = gen_password()
|
||||||
|
|
||||||
|
|
||||||
class UserUpdateView(UpdateView):
|
class UserUpdateView(UpdateView):
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
:license: GNU GPL, see LICENSE for more details.
|
: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.api import generate_person_id, get_person, Persons
|
||||||
from openslides.utils.person.forms import PersonFormField, MultiplePersonFormField
|
from openslides.utils.person.forms import PersonFormField, MultiplePersonFormField
|
||||||
from openslides.utils.person.models import PersonField, PersonMixin
|
from openslides.utils.person.models import PersonField, PersonMixin
|
||||||
|
@ -10,16 +10,16 @@
|
|||||||
:license: GNU GPL, see LICENSE for more details.
|
: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):
|
class Persons(object):
|
||||||
"""
|
"""
|
||||||
A Storage for a multiplicity of different Person-Objects.
|
A Storage for a multiplicity of different Person-Objects.
|
||||||
"""
|
"""
|
||||||
def __init__(self, person_prefix=None, id=None):
|
def __init__(self, person_prefix_filter=None, id_filter=None):
|
||||||
self.person_prefix = person_prefix
|
self.person_prefix_filter = person_prefix_filter
|
||||||
self.id = id
|
self.id_filter = id_filter
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
try:
|
try:
|
||||||
@ -35,8 +35,8 @@ class Persons(object):
|
|||||||
|
|
||||||
def iter_persons(self):
|
def iter_persons(self):
|
||||||
self._cache = list()
|
self._cache = list()
|
||||||
for receiver, persons in receiv_persons.send(
|
for receiver, persons in receive_persons.send(
|
||||||
sender='persons', person_prefix=self.person_prefix, id=self.id):
|
sender='persons', person_prefix_filter=self.person_prefix_filter, id_filter=self.id_filter):
|
||||||
for person in persons:
|
for person in persons:
|
||||||
self._cache.append(person)
|
self._cache.append(person)
|
||||||
yield person
|
yield person
|
||||||
@ -63,4 +63,4 @@ def get_person(person_id):
|
|||||||
except TypeError:
|
except TypeError:
|
||||||
from openslides.utils.person import EmtyPerson
|
from openslides.utils.person import EmtyPerson
|
||||||
return EmtyPerson()
|
return EmtyPerson()
|
||||||
return Persons(person_prefix=person_prefix, id=id)[0]
|
return Persons(person_prefix_filter=person_prefix, id_filter=id)[0]
|
||||||
|
@ -12,4 +12,4 @@
|
|||||||
|
|
||||||
from django.dispatch import Signal
|
from django.dispatch import Signal
|
||||||
|
|
||||||
receiv_persons = Signal(providing_args=['person_prefix', 'id'])
|
receive_persons = Signal(providing_args=['person_prefix_filter', 'id_filter'])
|
||||||
|
Loading…
Reference in New Issue
Block a user