change the users in the groupform
This commit is contained in:
parent
cdf160dfc3
commit
6795ccd25b
@ -47,14 +47,39 @@ class GroupForm(forms.ModelForm, CssClassMixin):
|
||||
permissions = LocalizedModelMultipleChoiceField(
|
||||
queryset=Permission.objects.all(), label=_("Persmissions"),
|
||||
required=False)
|
||||
users = forms.ModelMultipleChoiceField(
|
||||
queryset=OpenSlidesUser.objects.all(),
|
||||
label=_("Users"), required=False)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(GroupForm, self).__init__(*args, **kwargs)
|
||||
# Initial users
|
||||
if kwargs.get('instance', None) is not None:
|
||||
self.fields['permissions'].initial = (
|
||||
[p.pk for p in kwargs['instance'].permissions.all()])
|
||||
initial = kwargs.setdefault('initial', {})
|
||||
initial['users'] = [user.pk for user in kwargs['instance'].user_set.all()]
|
||||
|
||||
super(GroupForm, self).__init__(*args, **kwargs)
|
||||
|
||||
def save(self, commit=True):
|
||||
instance = forms.ModelForm.save(self, False)
|
||||
|
||||
old_save_m2m = self.save_m2m
|
||||
def save_m2m():
|
||||
old_save_m2m()
|
||||
|
||||
instance.user_set.clear()
|
||||
for user in self.cleaned_data['users']:
|
||||
instance.user_set.add(user)
|
||||
self.save_m2m = save_m2m
|
||||
|
||||
if commit:
|
||||
instance.save()
|
||||
self.save_m2m()
|
||||
|
||||
return instance
|
||||
|
||||
def clean_name(self):
|
||||
# Do not allow to change the name "anonymous" or give another group
|
||||
# this name
|
||||
data = self.cleaned_data['name']
|
||||
if self.instance.name.lower() == 'anonymous':
|
||||
# Editing the anonymous-user
|
||||
|
@ -90,9 +90,10 @@ class OpenSlidesUser(User, 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)" % (self.get_full_name(), self.name_surfix)
|
||||
return u"%s" % self.get_full_name()
|
||||
return u"%s (%s)" % (name, self.name_surfix)
|
||||
return u"%s" % name
|
||||
|
||||
class Meta:
|
||||
# Rename permissions
|
||||
|
@ -357,16 +357,7 @@ class GroupOverviewView(ListView):
|
||||
model = OpenSlidesGroup
|
||||
|
||||
|
||||
class GroupEditMixin(object):
|
||||
"""
|
||||
Methodes for the GroupCreateView and GroupUpdateView.
|
||||
"""
|
||||
def get_form_class(self):
|
||||
delete_default_permissions()
|
||||
return self.form_class
|
||||
|
||||
|
||||
class GroupCreateView(CreateView, GroupEditMixin):
|
||||
class GroupCreateView(CreateView):
|
||||
"""
|
||||
Create a new group.
|
||||
"""
|
||||
@ -378,8 +369,12 @@ class GroupCreateView(CreateView, GroupEditMixin):
|
||||
success_url = 'user_group_overview'
|
||||
apply_url = 'user_group_edit'
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
delete_default_permissions()
|
||||
return super(GroupCreateView, self).get(request, *args, **kwargs)
|
||||
|
||||
class GroupUpdateView(UpdateView, GroupEditMixin):
|
||||
|
||||
class GroupUpdateView(UpdateView):
|
||||
"""
|
||||
Update an existing group.
|
||||
"""
|
||||
@ -391,6 +386,10 @@ class GroupUpdateView(UpdateView, GroupEditMixin):
|
||||
success_url = 'user_group_overview'
|
||||
apply_url = 'user_group_edit'
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
delete_default_permissions()
|
||||
return super(GroupUpdateView, self).get(request, *args, **kwargs)
|
||||
|
||||
|
||||
class GroupDeleteView(DeleteView):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user