Removed imports from openslides.users in other apps: Cleaned up agenda, assignments and motions.

This commit is contained in:
Norman Jäckel 2015-09-07 17:09:29 +02:00
parent d79bad80f6
commit c8dfb9437b
6 changed files with 44 additions and 31 deletions

View File

@ -1,6 +1,7 @@
from collections import defaultdict from collections import defaultdict
from datetime import datetime from datetime import datetime
from django.conf import settings
from django.contrib.auth.models import AnonymousUser from django.contrib.auth.models import AnonymousUser
from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
@ -12,7 +13,6 @@ from django.utils.translation import ugettext_lazy, ugettext_noop
from openslides.core.config import config from openslides.core.config import config
from openslides.core.models import Tag from openslides.core.models import Tag
from openslides.core.projector import Countdown from openslides.core.projector import Countdown
from openslides.users.models import User
from openslides.utils.exceptions import OpenSlidesError from openslides.utils.exceptions import OpenSlidesError
from openslides.utils.models import RESTModelMixin from openslides.utils.models import RESTModelMixin
from openslides.utils.utils import to_roman from openslides.utils.utils import to_roman
@ -304,7 +304,7 @@ class Item(RESTModelMixin, models.Model):
def get_next_speaker(self): def get_next_speaker(self):
""" """
Returns the speaker object of the user who is next. Returns the speaker object of the speaker who is next.
""" """
try: try:
return self.speakers.filter(begin_time=None).order_by('weight')[0] return self.speakers.filter(begin_time=None).order_by('weight')[0]
@ -352,10 +352,18 @@ class Item(RESTModelMixin, models.Model):
class SpeakerManager(models.Manager): class SpeakerManager(models.Manager):
"""
Manager for Speaker model. Provides a customized add method.
"""
def add(self, user, item): def add(self, user, item):
"""
Customized manager method to prevent anonymous users to be on the
list of speakers and that someone is twice on one list (off coming
speakers). Cares also initial sorting of the coming speakers.
"""
if self.filter(user=user, item=item, begin_time=None).exists(): if self.filter(user=user, item=item, begin_time=None).exists():
raise OpenSlidesError(_( raise OpenSlidesError(
'%(user)s is already on the list of speakers of item %(id)s.') _('%(user)s is already on the list of speakers of item %(id)s.')
% {'user': user, 'id': item.id}) % {'user': user, 'id': item.id})
if isinstance(user, AnonymousUser): if isinstance(user, AnonymousUser):
raise OpenSlidesError( raise OpenSlidesError(
@ -372,14 +380,14 @@ class Speaker(RESTModelMixin, models.Model):
objects = SpeakerManager() objects = SpeakerManager()
user = models.ForeignKey(User) user = models.ForeignKey(settings.AUTH_USER_MODEL)
""" """
ForeinKey to the user who speaks. ForeinKey to the user who speaks.
""" """
item = models.ForeignKey(Item, related_name='speakers') item = models.ForeignKey(Item, related_name='speakers')
""" """
ForeinKey to the AgendaItem to which the user want to speak. ForeinKey to the agenda item to which the user want to speak.
""" """
begin_time = models.DateTimeField(null=True) begin_time = models.DateTimeField(null=True)

View File

@ -1,3 +1,4 @@
from django.conf import settings
from django.contrib.contenttypes.fields import GenericRelation from django.contrib.contenttypes.fields import GenericRelation
from django.db import models from django.db import models
from django.utils.datastructures import SortedDict from django.utils.datastructures import SortedDict
@ -14,7 +15,6 @@ from openslides.poll.models import (
CollectDefaultVotesMixin, CollectDefaultVotesMixin,
PublishPollMixin, PublishPollMixin,
) )
from openslides.users.models import User
from openslides.utils.exceptions import OpenSlidesError from openslides.utils.exceptions import OpenSlidesError
from openslides.utils.models import RESTModelMixin from openslides.utils.models import RESTModelMixin
@ -36,7 +36,7 @@ class AssignmentRelatedUser(RESTModelMixin, models.Model):
'Assignment', 'Assignment',
db_index=True, db_index=True,
related_name='assignment_related_users') related_name='assignment_related_users')
user = models.ForeignKey(User, db_index=True) user = models.ForeignKey(settings.AUTH_USER_MODEL, db_index=True)
status = models.IntegerField( status = models.IntegerField(
choices=STATUSES, choices=STATUSES,
default=STATUS_CANDIDATE) default=STATUS_CANDIDATE)
@ -103,7 +103,7 @@ class Assignment(RESTModelMixin, models.Model):
""" """
related_users = models.ManyToManyField( related_users = models.ManyToManyField(
User, settings.AUTH_USER_MODEL,
through='AssignmentRelatedUser') through='AssignmentRelatedUser')
""" """
Users that a candidates, elected or blocked as candidate. Users that a candidates, elected or blocked as candidate.
@ -324,7 +324,7 @@ class AssignmentVote(RESTModelMixin, BaseVote):
class AssignmentOption(RESTModelMixin, BaseOption): class AssignmentOption(RESTModelMixin, BaseOption):
poll = models.ForeignKey('AssignmentPoll') poll = models.ForeignKey('AssignmentPoll')
candidate = models.ForeignKey(User) candidate = models.ForeignKey(settings.AUTH_USER_MODEL)
vote_class = AssignmentVote vote_class = AssignmentVote
def __str__(self): def __str__(self):

View File

@ -1,5 +1,7 @@
from cgi import escape from cgi import escape
from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import transaction from django.db import transaction
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.utils.translation import ungettext from django.utils.translation import ungettext
@ -16,7 +18,6 @@ from reportlab.platypus import (
) )
from openslides.core.config import config from openslides.core.config import config
from openslides.users.models import Group, User # TODO: remove this
from openslides.utils.pdf import stylesheet from openslides.utils.pdf import stylesheet
from openslides.utils.rest_api import ( from openslides.utils.rest_api import (
DestroyModelMixin, DestroyModelMixin,
@ -134,8 +135,8 @@ class AssignmentViewSet(ModelViewSet):
except ValueError: except ValueError:
raise ValidationError({'detail': _('Invalid data. Expected something like {"user": <id>}.')}) raise ValidationError({'detail': _('Invalid data. Expected something like {"user": <id>}.')})
try: try:
user = User.objects.get(pk=user_pk) user = get_user_model().objects.get(pk=user_pk)
except User.DoesNotExist: except get_user_model().DoesNotExist:
raise ValidationError({'detail': _('Invalid data. User %d does not exist.') % user_pk}) raise ValidationError({'detail': _('Invalid data. User %d does not exist.') % user_pk})
return user return user
@ -480,13 +481,17 @@ class AssignmentPollPDF(PDFView):
# set number of ballot papers # set number of ballot papers
if ballot_papers_selection == "NUMBER_OF_DELEGATES": if ballot_papers_selection == "NUMBER_OF_DELEGATES":
try: if 'openslides.users' in settings.INSTALLED_APPS:
if Group.objects.get(pk=3): from openslides.users.models import Group
number = User.objects.filter(groups__pk=3).count() try:
except Group.DoesNotExist: if Group.objects.get(pk=3):
number = get_user_model().objects.filter(groups__pk=3).count()
except Group.DoesNotExist:
number = 0
else:
number = 0 number = 0
elif ballot_papers_selection == "NUMBER_OF_ALL_PARTICIPANTS": elif ballot_papers_selection == "NUMBER_OF_ALL_PARTICIPANTS":
number = int(User.objects.count()) number = int(get_user_model().objects.count())
else: # ballot_papers_selection == "CUSTOM_NUMBER" else: # ballot_papers_selection == "CUSTOM_NUMBER"
number = int(ballot_papers_number) number = int(ballot_papers_number)
number = max(1, number) number = max(1, number)

View File

@ -15,7 +15,6 @@ from openslides.poll.models import (
BaseVote, BaseVote,
CollectDefaultVotesMixin, CollectDefaultVotesMixin,
) )
from openslides.users.models import User
from openslides.utils.models import RESTModelMixin from openslides.utils.models import RESTModelMixin
from .exceptions import WorkflowError from .exceptions import WorkflowError
@ -599,8 +598,8 @@ class MotionLog(RESTModelMixin, models.Model):
The log message. It should be a list of strings in English. The log message. It should be a list of strings in English.
""" """
person = models.ForeignKey(User, null=True) person = models.ForeignKey(settings.AUTH_USER_MODEL, null=True)
"""A person object, who created the log message. Optional.""" """A user object, who created the log message. Optional."""
time = models.DateTimeField(auto_now=True) time = models.DateTimeField(auto_now=True)
"""The Time, when the loged action was performed.""" """The Time, when the loged action was performed."""

View File

@ -3,6 +3,8 @@ from cgi import escape
from operator import attrgetter from operator import attrgetter
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from django.conf import settings
from django.contrib.auth import get_user_model
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from natsort import natsorted from natsort import natsorted
from reportlab.lib import colors from reportlab.lib import colors
@ -10,7 +12,6 @@ from reportlab.lib.units import cm
from reportlab.platypus import PageBreak, Paragraph, Spacer, Table, TableStyle from reportlab.platypus import PageBreak, Paragraph, Spacer, Table, TableStyle
from openslides.core.config import config from openslides.core.config import config
from openslides.users.models import Group, User # TODO: remove this line
from openslides.utils.pdf import stylesheet from openslides.utils.pdf import stylesheet
from .models import Category from .models import Category
@ -278,15 +279,17 @@ def motion_poll_to_pdf(pdf, poll):
# set number of ballot papers # set number of ballot papers
if ballot_papers_selection == "NUMBER_OF_DELEGATES": if ballot_papers_selection == "NUMBER_OF_DELEGATES":
# TODO: get this number from users if 'openslides.users' in settings.INSTALLED_APPS:
try: from openslides.users.models import Group
if Group.objects.get(pk=3): # TODO: Find a better way try:
number = User.objects.filter(groups__pk=3).count() if Group.objects.get(pk=3):
except Group.DoesNotExist: number = get_user_model().objects.filter(groups__pk=3).count()
except Group.DoesNotExist:
number = 0
else:
number = 0 number = 0
elif ballot_papers_selection == "NUMBER_OF_ALL_PARTICIPANTS": elif ballot_papers_selection == "NUMBER_OF_ALL_PARTICIPANTS":
# TODO: get the number from the persons number = int(get_user_model().objects.count())
number = int(User.objects.count())
else: # ballot_papers_selection == "CUSTOM_NUMBER" else: # ballot_papers_selection == "CUSTOM_NUMBER"
number = int(ballot_papers_number) number = int(ballot_papers_number)
number = max(1, number) number = max(1, number)

View File

@ -1,5 +1,3 @@
# TODO: Check every app, that they do not import Group or User from here.
from random import choice from random import choice
from django.contrib.auth.hashers import make_password from django.contrib.auth.hashers import make_password