mark group to be teated as user

This commit is contained in:
Oskar Hahn 2012-08-03 12:44:34 +02:00
parent 4ffb701397
commit 93020f9ead
5 changed files with 31 additions and 11 deletions

View File

@ -180,7 +180,9 @@ def edit(request, application_id=None):
return redirect(reverse('application_overview'))
if application_id is not None:
application = Application.objects.get(id=application_id)
if not request.user == application.submitter.user and not is_manager:
if (not hasattr(application.submitter, 'user') or
not request.user == application.submitter.user) \
and not is_manager:
messages.error(request, _("You can not edit this application. You are not the submitter."))
return redirect(reverse('application_view', args=[application.id]))
actions = application.get_allowed_actions(user=request.user)

View File

@ -14,6 +14,7 @@ from django import forms
from django.utils.translation import ugettext_lazy as _, ugettext_noop
from openslides.utils.forms import CssClassMixin
from openslides.utils.user import UserFormField
from openslides.participant.models import Profile
from openslides.assignment.models import Assignment
@ -29,9 +30,8 @@ class AssignmentForm(forms.ModelForm, CssClassMixin):
class AssignmentRunForm(forms.Form, CssClassMixin):
candidate = forms.ModelChoiceField(
candidate = UserFormField(
widget=forms.Select(attrs={'class': 'medium-input'}),
queryset=Profile.objects.all().order_by('user__first_name'),
label=_("Nominate a participant"),
)

View File

@ -68,6 +68,9 @@ class ProfileForm(forms.ModelForm, CssClassMixin):
class GroupForm(forms.ModelForm, CssClassMixin):
as_user = forms.BooleanField(initial=False, required=False,
label=_("Treat Group as User"),
help_text=_("The Group will appear on any place, other user does."))
permissions = LocalizedModelMultipleChoiceField(
queryset=Permission.objects.all(), label=_("Persmissions"))

View File

@ -46,7 +46,7 @@ from openslides.utils.views import FormView, PDFView
from openslides.config.models import config
from openslides.participant.models import Profile
from openslides.participant.models import Profile, DjangoGroup
from openslides.participant.api import gen_username, gen_password
from openslides.participant.forms import (UserNewForm, UserEditForm,
ProfileForm, UsersettingsForm, UserImportForm, GroupForm,
@ -269,6 +269,7 @@ def group_edit(request, group_id=None):
try:
group = Group.objects.get(id=group_id)
except Group.DoesNotExist:
# TODO: return a 404 Object
raise NameError("There is no group %d" % group_id)
else:
group = None
@ -277,14 +278,18 @@ def group_edit(request, group_id=None):
if request.method == 'POST':
form = GroupForm(request.POST, instance=group)
if form.is_valid():
# TODO: This can be done inside the form
group_name = form.cleaned_data['name'].lower()
# TODO: Why is this code called on any request and not only, if the
# anonymous_group is edited?
try:
anonymous_group = Group.objects.get(name='Anonymous')
except Group.DoesNotExist:
anonymous_group = None
# special handling for anonymous auth
# TODO: This code should be a form validator.
if group is None and group_name.strip().lower() == 'anonymous':
# don't allow to create this group
messages.error(request,
@ -296,6 +301,16 @@ def group_edit(request, group_id=None):
}
group = form.save()
try:
django_group = DjangoGroup.objects.get(group=group)
except DjangoGroup.DoesNotExist:
django_group = None
if form.cleaned_data['as_user'] and django_group is None:
DjangoGroup(group=group).save()
elif not form.cleaned_data['as_user'] and django_group:
django_group.delete()
if anonymous_group is not None and \
anonymous_group.id == group.id:
# prevent name changes -
@ -315,7 +330,12 @@ def group_edit(request, group_id=None):
else:
messages.error(request, _('Please check the form for errors.'))
else:
form = GroupForm(instance=group)
if group and DjangoGroup.objects.filter(group=group).exists():
initial = {'as_user': True}
else:
initial = {'as_user': False}
form = GroupForm(instance=group, initial=initial)
return {
'form': form,
'group': group,

View File

@ -16,7 +16,7 @@ from django import forms
from openslides.utils.user.signals import receiv_users
class UserChoices():
class UserChoices(object):
def __init__(self, field):
self.field = field
@ -29,7 +29,6 @@ class UserChoices():
class UserFormField(forms.fields.ChoiceField):
def __init__(self, required=True, initial=None, empty_label=u"---------", *args, **kwargs):
if required and (initial is not None):
self.empty_label = None
else:
@ -38,7 +37,6 @@ class UserFormField(forms.fields.ChoiceField):
super(UserFormField, self).__init__(choices=UserChoices(field=self), required=required, initial=initial, *args, **kwargs)
def to_python(self, value):
print value
return get_user(value)
def valid_value(self, value):
@ -109,9 +107,7 @@ class Users(object):
for receiver, users_list in receiv_users.send(sender='users'):
for users in users_list:
# Does iter(users) work?
print users
for user in users:
print user
yield user
@ -122,7 +118,6 @@ def generate_uid(prefix, id):
return "%s:%d" % (prefix, id)
# TODO: I dont need this object any more
class UserMixin(object):
@property
def uid(self):