rename openslidesuser to user and openslidesgroup to group
This commit is contained in:
parent
0a8ee9cbad
commit
df40de67b0
@ -1,6 +1,6 @@
|
||||
[
|
||||
{
|
||||
"pk": 2,
|
||||
"pk": 1,
|
||||
"model": "auth.group",
|
||||
"fields": {
|
||||
"name": "Beobachter",
|
||||
@ -38,7 +38,7 @@
|
||||
[
|
||||
"can_see_participant",
|
||||
"participant",
|
||||
"openslidesuser"
|
||||
"user"
|
||||
],
|
||||
[
|
||||
"can_see_projector",
|
||||
@ -49,7 +49,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 3,
|
||||
"pk": 2,
|
||||
"model": "auth.group",
|
||||
"fields": {
|
||||
"name": "Delegierter",
|
||||
@ -92,7 +92,7 @@
|
||||
[
|
||||
"can_see_participant",
|
||||
"participant",
|
||||
"openslidesuser"
|
||||
"user"
|
||||
],
|
||||
[
|
||||
"can_see_projector",
|
||||
@ -103,7 +103,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 4,
|
||||
"pk": 3,
|
||||
"model": "auth.group",
|
||||
"fields": {
|
||||
"name": "Versammlungsleitung",
|
||||
@ -161,12 +161,12 @@
|
||||
[
|
||||
"can_manage_participant",
|
||||
"participant",
|
||||
"openslidesuser"
|
||||
"user"
|
||||
],
|
||||
[
|
||||
"can_see_participant",
|
||||
"participant",
|
||||
"openslidesuser"
|
||||
"user"
|
||||
],
|
||||
[
|
||||
"can_manage_projector",
|
||||
@ -182,7 +182,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 5,
|
||||
"pk": 4,
|
||||
"model": "auth.group",
|
||||
"fields": {
|
||||
"name": "Teilnehmerverwaltung",
|
||||
@ -195,12 +195,12 @@
|
||||
[
|
||||
"can_manage_participant",
|
||||
"participant",
|
||||
"openslidesuser"
|
||||
"user"
|
||||
],
|
||||
[
|
||||
"can_see_participant",
|
||||
"participant",
|
||||
"openslidesuser"
|
||||
"user"
|
||||
],
|
||||
[
|
||||
"can_see_projector",
|
||||
|
@ -12,7 +12,6 @@
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.db import models
|
||||
from django.db.models import Max
|
||||
@ -26,8 +25,6 @@ from openslides.utils.person import PersonField
|
||||
from openslides.config.models import config
|
||||
from openslides.config.signals import default_config_value
|
||||
|
||||
from openslides.participant.models import OpenSlidesUser
|
||||
|
||||
from openslides.poll.models import (BaseOption, BasePoll, CountVotesCast,
|
||||
CountInvalid, BaseVote)
|
||||
|
||||
@ -360,15 +357,6 @@ class Application(models.Model, SlideMixin):
|
||||
Return a list of all the allowed status.
|
||||
"""
|
||||
actions = []
|
||||
is_admin = False
|
||||
if user:
|
||||
try:
|
||||
user = user.openslidesuser
|
||||
except OpenSlidesUser.DoesNotExist:
|
||||
is_admin = True
|
||||
except AttributeError:
|
||||
# For the anonymous-user
|
||||
pass
|
||||
|
||||
# check if user allowed to withdraw an application
|
||||
if ((self.status == "pub"
|
||||
@ -405,11 +393,10 @@ class Application(models.Model, SlideMixin):
|
||||
|
||||
# Check if the user can delete the application (admin, manager, owner)
|
||||
# reworked as requiered in #100
|
||||
if is_admin \
|
||||
or (user.has_perm("application.can_manage_application") \
|
||||
and (self.status == "pub" or self.number is None)) \
|
||||
or (self.submitter == user \
|
||||
and (self.status == "pub" or self.number is None)):
|
||||
if (user.has_perm("applicatoin.can_delete_all_applications") or
|
||||
(user.has_perm("application.can_manage_application") and
|
||||
self.number is None) or
|
||||
(self.submitter == user and self.number is None)):
|
||||
actions.append("delete")
|
||||
|
||||
#For the rest, all actions need the manage permission
|
||||
@ -543,6 +530,7 @@ class Application(models.Model, SlideMixin):
|
||||
('can_create_application', ugettext_noop("Can create application")),
|
||||
('can_support_application', ugettext_noop("Can support application")),
|
||||
('can_manage_application', ugettext_noop("Can manage application")),
|
||||
('can_delete_all_applications', ugettext_noop("Can delete all applications")),
|
||||
)
|
||||
|
||||
|
||||
|
@ -12,15 +12,17 @@
|
||||
|
||||
from django.test import TestCase
|
||||
from django.test.client import Client
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from openslides.participant.models import User
|
||||
from openslides.application.models import Application, AVersion
|
||||
|
||||
class ApplicationTest(TestCase):
|
||||
def setUp(self):
|
||||
self.admin = User.objects.create_user('testadmin', '', 'default')
|
||||
self.anonym = User.objects.create_user('testanoym', '', 'default')
|
||||
self.app1 = Application(submitter=self.admin.openslidesuser)
|
||||
self.admin = User(username='testadmin')
|
||||
self.admin.save()
|
||||
self.anonym = User(username='testanoym')
|
||||
self.anonym.save()
|
||||
self.app1 = Application(submitter=self.admin)
|
||||
self.app1.save()
|
||||
|
||||
def refresh(self):
|
||||
|
@ -51,7 +51,7 @@ from openslides.projector.projector import Widget
|
||||
from openslides.poll.views import PollFormView
|
||||
|
||||
from openslides.participant.api import gen_username, gen_password
|
||||
from openslides.participant.models import OpenSlidesUser
|
||||
from openslides.participant.models import User
|
||||
|
||||
from openslides.agenda.models import Item
|
||||
|
||||
@ -124,7 +124,7 @@ def overview(request):
|
||||
for (i, application) in enumerate(applications):
|
||||
try:
|
||||
applications[i] = {
|
||||
'actions' : application.get_allowed_actions(request.user.openslidesuser),
|
||||
'actions' : application.get_allowed_actions(request.user),
|
||||
'application' : application
|
||||
}
|
||||
except:
|
||||
@ -152,8 +152,7 @@ def view(request, application_id, newest=False):
|
||||
else:
|
||||
version = application.public_version
|
||||
revisions = application.versions
|
||||
user = request.user.openslidesuser
|
||||
actions = application.get_allowed_actions(user=user)
|
||||
actions = application.get_allowed_actions(user=request.user)
|
||||
|
||||
return {
|
||||
'application': application,
|
||||
@ -183,11 +182,11 @@ def edit(request, application_id=None):
|
||||
if application_id is not None:
|
||||
application = Application.objects.get(id=application_id)
|
||||
if (not hasattr(application.submitter, 'user') or
|
||||
not request.user.openslidesuser == application.submitter.user) \
|
||||
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.openslidesuser)
|
||||
actions = application.get_allowed_actions(user=request.user)
|
||||
else:
|
||||
application = None
|
||||
actions = None
|
||||
@ -221,7 +220,7 @@ def edit(request, application_id=None):
|
||||
original_supporters = []
|
||||
application = managerform.save(commit=False)
|
||||
elif application_id is None:
|
||||
application = Application(submitter=request.user.openslidesuser)
|
||||
application = Application(submitter=request.user)
|
||||
application.title = dataform.cleaned_data['title']
|
||||
application.text = dataform.cleaned_data['text']
|
||||
application.reason = dataform.cleaned_data['reason']
|
||||
@ -231,7 +230,7 @@ def edit(request, application_id=None):
|
||||
and dataform.cleaned_data['trivial_change']
|
||||
except KeyError:
|
||||
trivial_change = False
|
||||
application.save(request.user.openslidesuser, trivial_change=trivial_change)
|
||||
application.save(request.user, trivial_change=trivial_change)
|
||||
if is_manager:
|
||||
try:
|
||||
new_supporters = set(managerform.cleaned_data['supporter'])
|
||||
@ -273,7 +272,7 @@ def edit(request, application_id=None):
|
||||
dataform = formclass(initial=initial, prefix="data")
|
||||
if is_manager:
|
||||
if application_id is None:
|
||||
initial = {'submitter': request.user.openslidesuser.person_id}
|
||||
initial = {'submitter': request.user.person_id}
|
||||
else:
|
||||
initial = {'submitter': application.submitter.person_id,
|
||||
'supporter': [supporter.person_id for supporter in application.supporters]}
|
||||
@ -296,7 +295,7 @@ def set_number(request, application_id):
|
||||
set a number for an application.
|
||||
"""
|
||||
try:
|
||||
Application.objects.get(pk=application_id).set_number(user=request.user.openslidesuser)
|
||||
Application.objects.get(pk=application_id).set_number(user=request.user)
|
||||
messages.success(request, _("Application number was successfully set."))
|
||||
except Application.DoesNotExist:
|
||||
pass
|
||||
@ -312,7 +311,7 @@ def permit(request, application_id):
|
||||
permit an application.
|
||||
"""
|
||||
try:
|
||||
Application.objects.get(pk=application_id).permit(user=request.user.openslidesuser)
|
||||
Application.objects.get(pk=application_id).permit(user=request.user)
|
||||
messages.success(request, _("Application was successfully permitted."))
|
||||
except Application.DoesNotExist:
|
||||
pass
|
||||
@ -327,7 +326,7 @@ def notpermit(request, application_id):
|
||||
reject (not permit) an application.
|
||||
"""
|
||||
try:
|
||||
Application.objects.get(pk=application_id).notpermit(user=request.user.openslidesuser)
|
||||
Application.objects.get(pk=application_id).notpermit(user=request.user)
|
||||
messages.success(request, _("Application was successfully rejected."))
|
||||
except Application.DoesNotExist:
|
||||
pass
|
||||
@ -343,7 +342,7 @@ def set_status(request, application_id=None, status=None):
|
||||
try:
|
||||
if status is not None:
|
||||
application = Application.objects.get(pk=application_id)
|
||||
application.set_status(user=request.user.openslidesuser, status=status)
|
||||
application.set_status(user=request.user, status=status)
|
||||
messages.success(request, _("Application status was set to: <b>%s</b>.") % application.get_status_display())
|
||||
except Application.DoesNotExist:
|
||||
pass
|
||||
@ -387,7 +386,7 @@ def unsupport(request, application_id):
|
||||
unsupport an application.
|
||||
"""
|
||||
try:
|
||||
Application.objects.get(pk=application_id).unsupport(user=request.user.openslidesuser)
|
||||
Application.objects.get(pk=application_id).unsupport(user=request.user)
|
||||
messages.success(request, _("You have unsupport the application successfully.") )
|
||||
except Application.DoesNotExist:
|
||||
pass
|
||||
@ -401,7 +400,7 @@ def gen_poll(request, application_id):
|
||||
gen a poll for this application.
|
||||
"""
|
||||
try:
|
||||
poll = Application.objects.get(pk=application_id).gen_poll(user=request.user.openslidesuser)
|
||||
poll = Application.objects.get(pk=application_id).gen_poll(user=request.user)
|
||||
messages.success(request, _("New vote was successfully created.") )
|
||||
except Application.DoesNotExist:
|
||||
pass # TODO: do not call poll after this excaption
|
||||
@ -418,7 +417,7 @@ def delete_poll(request, poll_id):
|
||||
count = application.polls.filter(id__lte=poll_id).count()
|
||||
if request.method == 'POST':
|
||||
poll.delete()
|
||||
application.writelog(_("Poll deleted"), request.user.openslidesuser)
|
||||
application.writelog(_("Poll deleted"), request.user)
|
||||
messages.success(request, _('Poll was successfully deleted.'))
|
||||
else:
|
||||
del_confirm_form(request, poll, name=_("the %s. poll") % count, delete_link=reverse('application_poll_delete', args=[poll_id]))
|
||||
@ -458,7 +457,7 @@ class ApplicationDelete(DeleteView):
|
||||
|
||||
if len(self.applications):
|
||||
for application in self.applications:
|
||||
if not 'delete' in application.get_allowed_actions(user=request.user.openslidesuser):
|
||||
if not 'delete' in application.get_allowed_actions(user=request.user):
|
||||
messages.error(request, _("You can not delete application <b>%s</b>.") % application)
|
||||
continue
|
||||
|
||||
@ -467,7 +466,7 @@ class ApplicationDelete(DeleteView):
|
||||
messages.success(request, _("Application <b>%s</b> was successfully deleted.") % title)
|
||||
|
||||
elif self.object:
|
||||
if not 'delete' in self.object.get_allowed_actions(user=request.user.openslidesuser):
|
||||
if not 'delete' in self.object.get_allowed_actions(user=request.user):
|
||||
messages.error(request, _("You can not delete application <b>%s</b>.") % self.object)
|
||||
else:
|
||||
title = self.object.title
|
||||
@ -508,12 +507,12 @@ class ViewPoll(PollFormView):
|
||||
self.application = self.poll.get_application()
|
||||
context['application'] = self.application
|
||||
context['ballot'] = self.poll.get_ballot()
|
||||
context['actions'] = self.application.get_allowed_actions(user=self.request.user.openslidesuser)
|
||||
context['actions'] = self.application.get_allowed_actions(user=self.request.user)
|
||||
return context
|
||||
|
||||
def get_modelform_class(self):
|
||||
cls = super(ViewPoll, self).get_modelform_class()
|
||||
user = self.request.user.openslidesuser
|
||||
user = self.request.user
|
||||
|
||||
class ViewPollFormClass(cls):
|
||||
def save(self, commit = True):
|
||||
@ -535,7 +534,7 @@ def permit_version(request, aversion_id):
|
||||
aversion = AVersion.objects.get(pk=aversion_id)
|
||||
application = aversion.application
|
||||
if request.method == 'POST':
|
||||
application.accept_version(aversion, user=request.user.openslidesuser)
|
||||
application.accept_version(aversion, user=request.user)
|
||||
messages.success(request, _("Version <b>%s</b> accepted.") % (aversion.aid))
|
||||
else:
|
||||
gen_confirm_form(request, _('Do you really want to permit version <b>%s</b>?') % aversion.aid, reverse('application_version_permit', args=[aversion.id]))
|
||||
@ -547,7 +546,7 @@ def reject_version(request, aversion_id):
|
||||
aversion = AVersion.objects.get(pk=aversion_id)
|
||||
application = aversion.application
|
||||
if request.method == 'POST':
|
||||
if application.reject_version(aversion, user=request.user.openslidesuser):
|
||||
if application.reject_version(aversion, user=request.user):
|
||||
messages.success(request, _("Version <b>%s</b> rejected.") % (aversion.aid))
|
||||
else:
|
||||
messages.error(request, _("ERROR by rejecting the version.") )
|
||||
@ -559,17 +558,6 @@ def reject_version(request, aversion_id):
|
||||
@permission_required('application.can_manage_application')
|
||||
@template('application/import.html')
|
||||
def application_import(request):
|
||||
try:
|
||||
request.user.openslidesuser
|
||||
except OpenSlidesUser.DoesNotExist:
|
||||
pass
|
||||
except AttributeError:
|
||||
# AnonymousUser
|
||||
pass
|
||||
else:
|
||||
messages.error(request, _('The import function is available for the admin (without user profile) only.'))
|
||||
return redirect(reverse('application_overview'))
|
||||
|
||||
if request.method == 'POST':
|
||||
form = ApplicationImportForm(request.POST, request.FILES)
|
||||
if form.is_valid():
|
||||
|
@ -34,7 +34,7 @@ from openslides.utils.person import get_person
|
||||
|
||||
from openslides.config.models import config
|
||||
|
||||
from openslides.participant.models import OpenSlidesUser
|
||||
from openslides.participant.models import User
|
||||
|
||||
from openslides.projector.projector import Widget
|
||||
|
||||
@ -97,13 +97,12 @@ def view(request, assignment_id=None):
|
||||
polls = assignment.poll_set.all()
|
||||
vote_results = assignment.vote_results(only_published=False)
|
||||
|
||||
user = request.user.openslidesuser
|
||||
return {
|
||||
'assignment': assignment,
|
||||
'form': form,
|
||||
'vote_results': vote_results,
|
||||
'polls': polls,
|
||||
'user_is_candidate': assignment.is_candidate(user)
|
||||
'user_is_candidate': assignment.is_candidate(request.user)
|
||||
}
|
||||
|
||||
|
||||
@ -173,7 +172,7 @@ def set_status(request, assignment_id=None, status=None):
|
||||
def run(request, assignment_id):
|
||||
assignment = Assignment.objects.get(pk=assignment_id)
|
||||
try:
|
||||
assignment.run(request.user.openslidesuser, request.user)
|
||||
assignment.run(request.user, request.user)
|
||||
messages.success(request, _('You have set your candidature successfully.') )
|
||||
except NameError, e:
|
||||
messages.error(request, e)
|
||||
@ -185,7 +184,7 @@ def delrun(request, assignment_id):
|
||||
assignment = Assignment.objects.get(pk=assignment_id)
|
||||
try:
|
||||
if assignment.status == 'sea' or user.has_perm("assignment.can_manage_assignment"):
|
||||
assignment.delrun(request.user.openslidesuser)
|
||||
assignment.delrun(request.user)
|
||||
else:
|
||||
messages.error(request, _('The candidate list is already closed.'))
|
||||
except Exception, e:
|
||||
|
@ -22,7 +22,7 @@ from django.db import transaction
|
||||
|
||||
from openslides.utils import csv_ext
|
||||
|
||||
from openslides.participant.models import OpenSlidesUser
|
||||
from openslides.participant.models import User
|
||||
|
||||
|
||||
def gen_password():
|
||||
@ -76,7 +76,7 @@ def import_users(csv_file):
|
||||
except ValueError:
|
||||
error_messages.append(_('Ignoring malformed line %d in import file.') % line_no + 1)
|
||||
continue
|
||||
user = OpenSlidesUser()
|
||||
user = User()
|
||||
user.last_name = last_name
|
||||
user.first_name = first_name
|
||||
user.username = gen_username(first_name, last_name)
|
||||
|
@ -17,27 +17,27 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from openslides.utils.forms import (
|
||||
CssClassMixin, LocalizedModelMultipleChoiceField)
|
||||
|
||||
from openslides.participant.models import OpenSlidesUser, OpenSlidesGroup
|
||||
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=OpenSlidesGroup.objects.exclude(name__iexact='anonymous'),
|
||||
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 = OpenSlidesUser
|
||||
model = User
|
||||
fields = ('first_name', 'last_name', 'is_active', 'groups', 'category',
|
||||
'gender', 'type', 'committee', 'comment', 'firstpassword')
|
||||
|
||||
|
||||
class UserUpdateForm(UserCreateForm):
|
||||
class Meta:
|
||||
model = OpenSlidesUser
|
||||
model = User
|
||||
fields = ('username', 'first_name', 'last_name', 'is_active', 'groups',
|
||||
'category', 'gender', 'type', 'committee', 'comment',
|
||||
'firstpassword')
|
||||
@ -48,14 +48,13 @@ class GroupForm(forms.ModelForm, CssClassMixin):
|
||||
queryset=Permission.objects.all(), label=_("Persmissions"),
|
||||
required=False)
|
||||
users = forms.ModelMultipleChoiceField(
|
||||
queryset=OpenSlidesUser.objects.all(),
|
||||
label=_("Users"), required=False)
|
||||
queryset=User.objects.all(), label=_("Users"), required=False)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
# Initial users
|
||||
if kwargs.get('instance', None) is not None:
|
||||
initial = kwargs.setdefault('initial', {})
|
||||
initial['users'] = [user.pk for user in kwargs['instance'].user_set.all()]
|
||||
initial['users'] = [django_user.user.pk for django_user in kwargs['instance'].user_set.all()]
|
||||
|
||||
super(GroupForm, self).__init__(*args, **kwargs)
|
||||
|
||||
@ -93,12 +92,12 @@ class GroupForm(forms.ModelForm, CssClassMixin):
|
||||
return data
|
||||
|
||||
class Meta:
|
||||
model = OpenSlidesGroup
|
||||
model = Group
|
||||
|
||||
|
||||
class UsersettingsForm(forms.ModelForm, CssClassMixin):
|
||||
class Meta:
|
||||
model = OpenSlidesUser
|
||||
model = User
|
||||
fields = ('username', 'first_name', 'last_name', 'email')
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
openslides.utils.middleware
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Additional definitions for OpenSlides forms.
|
||||
|
||||
@ -19,4 +19,4 @@ class AuthenticationMiddleware(_AuthenticationMiddleware):
|
||||
super(AuthenticationMiddleware, self).process_request(request)
|
||||
|
||||
if not isinstance(request.user, AnonymousUser):
|
||||
request.user = request.user.openslidesuser
|
||||
request.user = request.user.user
|
||||
|
@ -10,7 +10,7 @@
|
||||
:license: GNU GPL, see LICENSE for more details.
|
||||
"""
|
||||
|
||||
from django.contrib.auth.models import User, Group
|
||||
from django.contrib.auth.models import User as DjangoUser, Group as DjangoGroup
|
||||
from django.db import models
|
||||
from django.db.models import signals
|
||||
from django.dispatch import receiver
|
||||
@ -22,8 +22,8 @@ from openslides.utils.person.signals import receiv_persons
|
||||
from openslides.config.signals import default_config_value
|
||||
|
||||
|
||||
class OpenSlidesUser(User, PersonMixin):
|
||||
person_prefix = 'openslides_user'
|
||||
class User(DjangoUser, PersonMixin):
|
||||
person_prefix = 'user'
|
||||
GENDER_CHOICES = (
|
||||
('male', _('Male')),
|
||||
('female', _('Female')),
|
||||
@ -35,7 +35,7 @@ class OpenSlidesUser(User, PersonMixin):
|
||||
('guest', _('Guest')),
|
||||
)
|
||||
|
||||
user = models.OneToOneField(User, editable=False, parent_link=True)
|
||||
django_user = models.OneToOneField(DjangoUser, editable=False, parent_link=True)
|
||||
category = models.CharField(
|
||||
max_length=100, null=True, blank=True, verbose_name=_("Category"),
|
||||
help_text=_('Will be shown behind the name.'))
|
||||
@ -72,8 +72,8 @@ class OpenSlidesUser(User, PersonMixin):
|
||||
"""
|
||||
if password is None:
|
||||
password = self.firstpassword
|
||||
self.user.set_password(password)
|
||||
self.user.save()
|
||||
self.set_password(password)
|
||||
self.save()
|
||||
|
||||
@models.permalink
|
||||
def get_absolute_url(self, link='edit'):
|
||||
@ -104,10 +104,10 @@ class OpenSlidesUser(User, PersonMixin):
|
||||
)
|
||||
|
||||
|
||||
class OpenSlidesGroup(Group, PersonMixin):
|
||||
person_prefix = 'openslides_group'
|
||||
class Group(DjangoGroup, PersonMixin):
|
||||
person_prefix = 'group'
|
||||
|
||||
group = models.OneToOneField(Group, editable=False, parent_link=True)
|
||||
django_group = models.OneToOneField(DjangoGroup, editable=False, parent_link=True)
|
||||
group_as_person = models.BooleanField(default=False)
|
||||
description = models.TextField(blank=True)
|
||||
|
||||
@ -126,38 +126,38 @@ class OpenSlidesGroup(Group, PersonMixin):
|
||||
return ('user_group_delete', [str(self.id)])
|
||||
|
||||
def __unicode__(self):
|
||||
return unicode(self.group)
|
||||
return unicode(self.name)
|
||||
|
||||
|
||||
class OpenSlidesUsersConnecter(object):
|
||||
class UsersConnecter(object):
|
||||
def __init__(self, person_prefix=None, id=None):
|
||||
self.person_prefix = person_prefix
|
||||
self.id = id
|
||||
|
||||
def __iter__(self):
|
||||
if (not self.person_prefix or
|
||||
self.person_prefix == OpenSlidesUser.person_prefix):
|
||||
self.person_prefix == User.person_prefix):
|
||||
if self.id:
|
||||
yield OpenSlidesUser.objects.get(pk=self.id)
|
||||
yield User.objects.get(pk=self.id)
|
||||
else:
|
||||
for user in OpenSlidesUser.objects.all():
|
||||
for user in User.objects.all():
|
||||
yield user
|
||||
|
||||
if (not self.person_prefix or
|
||||
self.person_prefix == OpenSlidesGroup.person_prefix):
|
||||
self.person_prefix == Group.person_prefix):
|
||||
if self.id:
|
||||
yield OpenSlidesGroup.objects.get(pk=self.id)
|
||||
yield Group.objects.filter(group_as_person=True).get(pk=self.id)
|
||||
else:
|
||||
for group in OpenSlidesGroup.objects.all():
|
||||
for group in Group.objects.filter(group_as_person=True):
|
||||
yield group
|
||||
|
||||
def __getitem__(self, key):
|
||||
return OpenSlidesUser.objects.get(pk=key)
|
||||
return User.objects.get(pk=key)
|
||||
|
||||
|
||||
@receiver(receiv_persons, dispatch_uid="participant")
|
||||
def receiv_persons(sender, **kwargs):
|
||||
return OpenSlidesUsersConnecter(person_prefix=kwargs['person_prefix'],
|
||||
return UsersConnecter(person_prefix=kwargs['person_prefix'],
|
||||
id=kwargs['id'])
|
||||
|
||||
|
||||
@ -174,17 +174,17 @@ def default_config(sender, key, **kwargs):
|
||||
}.get(key)
|
||||
|
||||
|
||||
@receiver(signals.post_save, sender=User)
|
||||
@receiver(signals.post_save, sender=DjangoUser)
|
||||
def user_post_save(sender, instance, signal, *args, **kwargs):
|
||||
try:
|
||||
instance.openslidesuser
|
||||
except OpenSlidesUser.DoesNotExist:
|
||||
OpenSlidesUser(user=instance).save_base(raw=True)
|
||||
instance.user
|
||||
except User.DoesNotExist:
|
||||
User(django_user=instance).save_base(raw=True)
|
||||
|
||||
|
||||
@receiver(signals.post_save, sender=Group)
|
||||
@receiver(signals.post_save, sender=DjangoGroup)
|
||||
def group_post_save(sender, instance, signal, *args, **kwargs):
|
||||
try:
|
||||
instance.openslidesgroup
|
||||
except OpenSlidesGroup.DoesNotExist:
|
||||
OpenSlidesGroup(group=instance).save_base(raw=True)
|
||||
instance.group
|
||||
except Group.DoesNotExist:
|
||||
Group(django_group=instance).save_base(raw=True)
|
||||
|
@ -78,11 +78,11 @@
|
||||
<tr class="{% cycle '' 'odd' %}">
|
||||
<td>{{ user.first_name }}</td>
|
||||
<td>{{ user.last_name }}</td>
|
||||
<td>{{ user.openslidesuser.category }}</td>
|
||||
<td>{{ user.openslidesuser.get_type_display }}</td>
|
||||
<td>{{ user.openslidesuser.committee }}</td>
|
||||
<td>{{ user.category }}</td>
|
||||
<td>{{ user.get_type_display }}</td>
|
||||
<td>{{ user.committee }}</td>
|
||||
{% if perms.participant.can_manage_participant %}
|
||||
<td>{{ user.openslidesuser.comment|first_line }}</td>
|
||||
<td>{{ user.comment|first_line }}</td>
|
||||
<td>
|
||||
{% if user.last_login > user.date_joined %}
|
||||
{{ user.last_login }}
|
||||
|
@ -16,57 +16,58 @@ from django.contrib.auth.hashers import check_password
|
||||
|
||||
from openslides.utils.person import get_person, Persons
|
||||
from openslides.participant.api import gen_username, gen_password
|
||||
from openslides.participant.models import OpenSlidesUser, OpenSlidesGroup
|
||||
from openslides.participant.models import User, Group
|
||||
|
||||
|
||||
class OpenSlidesUserTest(TestCase):
|
||||
class UserTest(TestCase):
|
||||
def setUp(self):
|
||||
self.openslidesuser1 = OpenSlidesUser()
|
||||
self.openslidesuser1.first_name = u'Max'
|
||||
self.openslidesuser1.last_name = u'Mustermann'
|
||||
self.openslidesuser1.username = gen_username(
|
||||
self.openslidesuser1.first_name, self.openslidesuser1.last_name)
|
||||
self.openslidesuser1.firstpassword = gen_password()
|
||||
self.openslidesuser1.save()
|
||||
self.user1 = self.openslidesuser1.user
|
||||
self.user1 = User()
|
||||
self.user1.first_name = u'Max'
|
||||
self.user1.last_name = u'Mustermann'
|
||||
self.user1.username = gen_username(
|
||||
self.user1.first_name, self.user1.last_name)
|
||||
self.user1.firstpassword = gen_password()
|
||||
self.user1.save()
|
||||
self.django_user1 = self.user1.django_user
|
||||
|
||||
def test_participant_user(self):
|
||||
self.assertEqual(self.user1.openslidesuser, self.openslidesuser1)
|
||||
self.assertEqual(self.user1, self.openslidesuser1.user)
|
||||
self.assertEqual(self.django_user1.user, self.user1)
|
||||
self.assertEqual(self.django_user1, self.user1.django_user)
|
||||
|
||||
def test_repr(self):
|
||||
self.assertEqual(unicode(self.openslidesuser1), u'Max Mustermann')
|
||||
self.assertEqual(unicode(self.user1), u'Max Mustermann')
|
||||
|
||||
def test_name_surfix(self):
|
||||
self.openslidesuser1.category = u'München'
|
||||
self.openslidesuser1.save()
|
||||
self.assertEqual(unicode(self.openslidesuser1), u'Max Mustermann (München)')
|
||||
self.user1.category = u'München'
|
||||
self.user1.save()
|
||||
self.assertEqual(unicode(self.user1), u'Max Mustermann (München)')
|
||||
|
||||
def test_reset_password(self):
|
||||
self.assertIsInstance(self.openslidesuser1.firstpassword, basestring)
|
||||
self.assertEqual(len(self.openslidesuser1.firstpassword), 8)
|
||||
self.assertIsInstance(self.user1.firstpassword, basestring)
|
||||
self.assertEqual(len(self.user1.firstpassword), 8)
|
||||
self.user1.set_unusable_password()
|
||||
self.assertFalse(self.user1.check_password(self.openslidesuser1.firstpassword))
|
||||
self.openslidesuser1.reset_password()
|
||||
self.assertTrue(self.user1.check_password(self.openslidesuser1.firstpassword))
|
||||
self.assertFalse(self.user1.check_password(self.user1.firstpassword))
|
||||
self.user1.reset_password()
|
||||
self.assertTrue(self.user1.check_password(self.user1.firstpassword))
|
||||
|
||||
def test_person_api(self):
|
||||
self.assertTrue(hasattr(self.openslidesuser1, 'person_id'))
|
||||
self.assertEqual(self.openslidesuser1.person_id, 'openslides_user:1')
|
||||
self.assertEqual(get_person('openslides_user:1'), self.openslidesuser1)
|
||||
self.assertEqual(len(Persons(person_prefix='openslides_user')), 1)
|
||||
self.assertTrue(hasattr(self.user1, 'person_id'))
|
||||
self.assertEqual(self.user1.person_id, 'user:1')
|
||||
self.assertEqual(get_person('user:1'), self.user1)
|
||||
self.assertEqual(len(Persons(person_prefix='user')), 1)
|
||||
|
||||
|
||||
class OpenSlidesGroupTest(TestCase):
|
||||
class GroupTest(TestCase):
|
||||
def setUp(self):
|
||||
self.openslidesgroup1 = OpenSlidesGroup.objects.create(name='Test Group')
|
||||
self.group1 = self.openslidesgroup1.group
|
||||
self.group1 = Group.objects.create(name='Test Group')
|
||||
self.django_group1 = self.group1.django_group
|
||||
|
||||
def test_group_openslidesgroup(self):
|
||||
self.assertEqual(self.openslidesgroup1.group, self.group1)
|
||||
def test_group_group(self):
|
||||
self.assertEqual(self.group1.django_group, self.django_group1)
|
||||
self.assertEqual(self.group1, self.django_group1.group)
|
||||
|
||||
def test_person_api(self):
|
||||
self.assertTrue(hasattr(self.openslidesgroup1, 'person_id'))
|
||||
person_id = "openslides_group:%d" % self.openslidesgroup1.id
|
||||
self.assertEqual(self.openslidesgroup1.person_id, person_id)
|
||||
self.assertEqual(get_person(person_id), self.openslidesgroup1)
|
||||
self.assertTrue(hasattr(self.group1, 'person_id'))
|
||||
person_id = "group:%d" % self.group1.id
|
||||
self.assertEqual(self.group1.person_id, person_id)
|
||||
self.assertEqual(get_person(person_id), self.group1)
|
||||
|
@ -48,7 +48,7 @@ from openslides.participant.api import gen_username, gen_password, import_users
|
||||
from openslides.participant.forms import (
|
||||
UserCreateForm, UserUpdateForm, UsersettingsForm,
|
||||
UserImportForm, GroupForm, ConfigForm)
|
||||
from openslides.participant.models import OpenSlidesUser, OpenSlidesGroup
|
||||
from openslides.participant.models import User, Group
|
||||
|
||||
|
||||
class Overview(ListView):
|
||||
@ -77,7 +77,7 @@ class Overview(ListView):
|
||||
else:
|
||||
sortfilter[value] = [self.request.REQUEST[value]]
|
||||
|
||||
query = OpenSlidesUser.objects
|
||||
query = User.objects
|
||||
if 'gender' in sortfilter:
|
||||
query = query.filter(gender__iexact=sortfilter['gender'][0])
|
||||
if 'category' in sortfilter:
|
||||
@ -94,7 +94,7 @@ class Overview(ListView):
|
||||
elif (sortfilter['sort'][0] in
|
||||
['category', 'type', 'committee', 'comment']):
|
||||
query = query.order_by(
|
||||
'openslidesuser__%s' % sortfilter['sort'][0])
|
||||
'%s' % sortfilter['sort'][0])
|
||||
else:
|
||||
query = query.order_by('last_name')
|
||||
|
||||
@ -108,7 +108,7 @@ class Overview(ListView):
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(Overview, self).get_context_data(**kwargs)
|
||||
|
||||
all_users = OpenSlidesUser.objects.count()
|
||||
all_users = User.objects.count()
|
||||
|
||||
# quotient of selected users and all users
|
||||
if all_users > 0:
|
||||
@ -117,11 +117,11 @@ class Overview(ListView):
|
||||
percent = 0
|
||||
|
||||
# list of all existing categories
|
||||
categories = [p['category'] for p in OpenSlidesUser.objects.values('category')
|
||||
categories = [p['category'] for p in User.objects.values('category')
|
||||
.exclude(category='').distinct()]
|
||||
|
||||
# list of all existing committees
|
||||
committees = [p['committee'] for p in OpenSlidesUser.objects.values('committee')
|
||||
committees = [p['committee'] for p in User.objects.values('committee')
|
||||
.exclude(committee='').distinct()]
|
||||
context.update({
|
||||
'allusers': all_users,
|
||||
@ -140,7 +140,7 @@ class UserCreateView(CreateView):
|
||||
"""
|
||||
permission_required = 'participant.can_manage_participant'
|
||||
template_name = 'participant/edit.html'
|
||||
model = OpenSlidesUser
|
||||
model = User
|
||||
context_object_name = 'edit_user'
|
||||
form_class = UserCreateForm
|
||||
success_url = 'user_overview'
|
||||
@ -159,7 +159,7 @@ class UserUpdateView(UpdateView):
|
||||
"""
|
||||
permission_required = 'participant.can_manage_participant'
|
||||
template_name = 'participant/edit.html'
|
||||
model = OpenSlidesUser
|
||||
model = User
|
||||
context_object_name = 'edit_user'
|
||||
form_class = UserUpdateForm
|
||||
success_url = 'user_overview'
|
||||
@ -171,7 +171,7 @@ class UserDeleteView(DeleteView):
|
||||
Delete an participant.
|
||||
"""
|
||||
permission_required = 'participant.can_manage_participant'
|
||||
model = OpenSlidesUser
|
||||
model = User
|
||||
url = 'user_overview'
|
||||
|
||||
|
||||
@ -182,7 +182,7 @@ class SetUserStatusView(RedirectView, SingleObjectMixin):
|
||||
permission_required = 'participant.can_manage_participant'
|
||||
allow_ajax = True
|
||||
url = 'user_overview'
|
||||
model = OpenSlidesUser
|
||||
model = User
|
||||
|
||||
def pre_redirect(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
@ -215,7 +215,7 @@ class ParticipantsListPDF(PDFView):
|
||||
_('Committee')]]
|
||||
sort = 'last_name'
|
||||
counter = 0
|
||||
for user in OpenSlidesUser.objects.all().order_by(sort):
|
||||
for user in User.objects.all().order_by(sort):
|
||||
counter += 1
|
||||
data.append([
|
||||
counter,
|
||||
@ -255,7 +255,7 @@ class ParticipantsPasswordsPDF(PDFView):
|
||||
data = []
|
||||
participant_pdf_system_url = config["participant_pdf_system_url"]
|
||||
participant_pdf_welcometext = config["participant_pdf_welcometext"]
|
||||
for user in OpenSlidesUser.objects.all().order_by('last_name'):
|
||||
for user in User.objects.all().order_by('last_name'):
|
||||
cell = []
|
||||
cell.append(Spacer(0, 0.8 * cm))
|
||||
cell.append(Paragraph(_("Account for OpenSlides"),
|
||||
@ -323,7 +323,7 @@ class ResetPasswordView(RedirectView, SingleObjectMixin, QuestionMixin):
|
||||
Set the Passwort for a user to his firstpassword.
|
||||
"""
|
||||
permission_required = 'participant.can_manage_participant'
|
||||
model = OpenSlidesUser
|
||||
model = User
|
||||
allow_ajax = True
|
||||
question = ugettext_lazy('Do you really want to reset the password?')
|
||||
|
||||
@ -354,7 +354,7 @@ class GroupOverviewView(ListView):
|
||||
permission_required = 'participant.can_manage_participant'
|
||||
template_name = 'participant/group_overview.html'
|
||||
context_object_name = 'groups'
|
||||
model = OpenSlidesGroup
|
||||
model = Group
|
||||
|
||||
|
||||
class GroupCreateView(CreateView):
|
||||
@ -364,7 +364,7 @@ class GroupCreateView(CreateView):
|
||||
permission_required = 'participant.can_manage_participant'
|
||||
template_name = 'participant/group_edit.html'
|
||||
context_object_name = 'group'
|
||||
model = OpenSlidesGroup
|
||||
model = Group
|
||||
form_class = GroupForm
|
||||
success_url = 'user_group_overview'
|
||||
apply_url = 'user_group_edit'
|
||||
@ -380,7 +380,7 @@ class GroupUpdateView(UpdateView):
|
||||
"""
|
||||
permission_required = 'participant.can_manage_participant'
|
||||
template_name = 'participant/group_edit.html'
|
||||
model = OpenSlidesGroup
|
||||
model = Group
|
||||
context_object_name = 'group'
|
||||
form_class = GroupForm
|
||||
success_url = 'user_group_overview'
|
||||
@ -396,7 +396,7 @@ class GroupDeleteView(DeleteView):
|
||||
Delete a Group.
|
||||
"""
|
||||
permission_required = 'participant.can_manage_participant'
|
||||
model = OpenSlidesGroup
|
||||
model = Group
|
||||
url = 'user_group_overview'
|
||||
|
||||
|
||||
|
@ -55,7 +55,6 @@ for plugin in settings.INSTALLED_PLUGINS:
|
||||
|
||||
|
||||
urlpatterns += patterns('',
|
||||
(r'^500/$', 'openslides.utils.views.server_error'),
|
||||
(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
|
||||
|
||||
url(r'^login/$',
|
||||
|
@ -43,6 +43,8 @@ class Persons(object):
|
||||
|
||||
|
||||
def generate_person_id(prefix, id):
|
||||
assert prefix is not None
|
||||
assert id is not None
|
||||
if ':' in prefix:
|
||||
raise ValueError("':' is not allowed in a the 'person_prefix'")
|
||||
return "%s:%d" % (prefix, id)
|
||||
|
@ -57,7 +57,7 @@ class PersonMixin(object):
|
||||
try:
|
||||
return generate_person_id(self.person_prefix, self.pk)
|
||||
except AttributeError:
|
||||
raise AttributeError("%s has to have a attribute 'user_prefix'"
|
||||
raise AttributeError("%s has to have a attribute 'person_prefix'"
|
||||
% self)
|
||||
|
||||
def __repr__(self):
|
||||
|
Loading…
Reference in New Issue
Block a user