Removed imports from openslides.users in other apps: Cleaned up agenda, assignments and motions.
This commit is contained in:
parent
d79bad80f6
commit
c8dfb9437b
@ -1,6 +1,7 @@
|
||||
from collections import defaultdict
|
||||
from datetime import datetime
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.contrib.contenttypes.fields import GenericForeignKey
|
||||
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.models import Tag
|
||||
from openslides.core.projector import Countdown
|
||||
from openslides.users.models import User
|
||||
from openslides.utils.exceptions import OpenSlidesError
|
||||
from openslides.utils.models import RESTModelMixin
|
||||
from openslides.utils.utils import to_roman
|
||||
@ -304,7 +304,7 @@ class Item(RESTModelMixin, models.Model):
|
||||
|
||||
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:
|
||||
return self.speakers.filter(begin_time=None).order_by('weight')[0]
|
||||
@ -352,10 +352,18 @@ class Item(RESTModelMixin, models.Model):
|
||||
|
||||
|
||||
class SpeakerManager(models.Manager):
|
||||
"""
|
||||
Manager for Speaker model. Provides a customized add method.
|
||||
"""
|
||||
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():
|
||||
raise OpenSlidesError(_(
|
||||
'%(user)s is already on the list of speakers of item %(id)s.')
|
||||
raise OpenSlidesError(
|
||||
_('%(user)s is already on the list of speakers of item %(id)s.')
|
||||
% {'user': user, 'id': item.id})
|
||||
if isinstance(user, AnonymousUser):
|
||||
raise OpenSlidesError(
|
||||
@ -372,14 +380,14 @@ class Speaker(RESTModelMixin, models.Model):
|
||||
|
||||
objects = SpeakerManager()
|
||||
|
||||
user = models.ForeignKey(User)
|
||||
user = models.ForeignKey(settings.AUTH_USER_MODEL)
|
||||
"""
|
||||
ForeinKey to the user who speaks.
|
||||
"""
|
||||
|
||||
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)
|
||||
|
@ -1,3 +1,4 @@
|
||||
from django.conf import settings
|
||||
from django.contrib.contenttypes.fields import GenericRelation
|
||||
from django.db import models
|
||||
from django.utils.datastructures import SortedDict
|
||||
@ -14,7 +15,6 @@ from openslides.poll.models import (
|
||||
CollectDefaultVotesMixin,
|
||||
PublishPollMixin,
|
||||
)
|
||||
from openslides.users.models import User
|
||||
from openslides.utils.exceptions import OpenSlidesError
|
||||
from openslides.utils.models import RESTModelMixin
|
||||
|
||||
@ -36,7 +36,7 @@ class AssignmentRelatedUser(RESTModelMixin, models.Model):
|
||||
'Assignment',
|
||||
db_index=True,
|
||||
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(
|
||||
choices=STATUSES,
|
||||
default=STATUS_CANDIDATE)
|
||||
@ -103,7 +103,7 @@ class Assignment(RESTModelMixin, models.Model):
|
||||
"""
|
||||
|
||||
related_users = models.ManyToManyField(
|
||||
User,
|
||||
settings.AUTH_USER_MODEL,
|
||||
through='AssignmentRelatedUser')
|
||||
"""
|
||||
Users that a candidates, elected or blocked as candidate.
|
||||
@ -324,7 +324,7 @@ class AssignmentVote(RESTModelMixin, BaseVote):
|
||||
|
||||
class AssignmentOption(RESTModelMixin, BaseOption):
|
||||
poll = models.ForeignKey('AssignmentPoll')
|
||||
candidate = models.ForeignKey(User)
|
||||
candidate = models.ForeignKey(settings.AUTH_USER_MODEL)
|
||||
vote_class = AssignmentVote
|
||||
|
||||
def __str__(self):
|
||||
|
@ -1,5 +1,7 @@
|
||||
from cgi import escape
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.db import transaction
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.utils.translation import ungettext
|
||||
@ -16,7 +18,6 @@ from reportlab.platypus import (
|
||||
)
|
||||
|
||||
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.rest_api import (
|
||||
DestroyModelMixin,
|
||||
@ -134,8 +135,8 @@ class AssignmentViewSet(ModelViewSet):
|
||||
except ValueError:
|
||||
raise ValidationError({'detail': _('Invalid data. Expected something like {"user": <id>}.')})
|
||||
try:
|
||||
user = User.objects.get(pk=user_pk)
|
||||
except User.DoesNotExist:
|
||||
user = get_user_model().objects.get(pk=user_pk)
|
||||
except get_user_model().DoesNotExist:
|
||||
raise ValidationError({'detail': _('Invalid data. User %d does not exist.') % user_pk})
|
||||
return user
|
||||
|
||||
@ -480,13 +481,17 @@ class AssignmentPollPDF(PDFView):
|
||||
|
||||
# set number of ballot papers
|
||||
if ballot_papers_selection == "NUMBER_OF_DELEGATES":
|
||||
try:
|
||||
if Group.objects.get(pk=3):
|
||||
number = User.objects.filter(groups__pk=3).count()
|
||||
except Group.DoesNotExist:
|
||||
if 'openslides.users' in settings.INSTALLED_APPS:
|
||||
from openslides.users.models import Group
|
||||
try:
|
||||
if Group.objects.get(pk=3):
|
||||
number = get_user_model().objects.filter(groups__pk=3).count()
|
||||
except Group.DoesNotExist:
|
||||
number = 0
|
||||
else:
|
||||
number = 0
|
||||
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"
|
||||
number = int(ballot_papers_number)
|
||||
number = max(1, number)
|
||||
|
@ -15,7 +15,6 @@ from openslides.poll.models import (
|
||||
BaseVote,
|
||||
CollectDefaultVotesMixin,
|
||||
)
|
||||
from openslides.users.models import User
|
||||
from openslides.utils.models import RESTModelMixin
|
||||
|
||||
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.
|
||||
"""
|
||||
|
||||
person = models.ForeignKey(User, null=True)
|
||||
"""A person object, who created the log message. Optional."""
|
||||
person = models.ForeignKey(settings.AUTH_USER_MODEL, null=True)
|
||||
"""A user object, who created the log message. Optional."""
|
||||
|
||||
time = models.DateTimeField(auto_now=True)
|
||||
"""The Time, when the loged action was performed."""
|
||||
|
@ -3,6 +3,8 @@ from cgi import escape
|
||||
from operator import attrgetter
|
||||
|
||||
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 natsort import natsorted
|
||||
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 openslides.core.config import config
|
||||
from openslides.users.models import Group, User # TODO: remove this line
|
||||
from openslides.utils.pdf import stylesheet
|
||||
|
||||
from .models import Category
|
||||
@ -278,15 +279,17 @@ def motion_poll_to_pdf(pdf, poll):
|
||||
|
||||
# set number of ballot papers
|
||||
if ballot_papers_selection == "NUMBER_OF_DELEGATES":
|
||||
# TODO: get this number from users
|
||||
try:
|
||||
if Group.objects.get(pk=3): # TODO: Find a better way
|
||||
number = User.objects.filter(groups__pk=3).count()
|
||||
except Group.DoesNotExist:
|
||||
if 'openslides.users' in settings.INSTALLED_APPS:
|
||||
from openslides.users.models import Group
|
||||
try:
|
||||
if Group.objects.get(pk=3):
|
||||
number = get_user_model().objects.filter(groups__pk=3).count()
|
||||
except Group.DoesNotExist:
|
||||
number = 0
|
||||
else:
|
||||
number = 0
|
||||
elif ballot_papers_selection == "NUMBER_OF_ALL_PARTICIPANTS":
|
||||
# TODO: get the number from the persons
|
||||
number = int(User.objects.count())
|
||||
number = int(get_user_model().objects.count())
|
||||
else: # ballot_papers_selection == "CUSTOM_NUMBER"
|
||||
number = int(ballot_papers_number)
|
||||
number = max(1, number)
|
||||
|
@ -1,5 +1,3 @@
|
||||
# TODO: Check every app, that they do not import Group or User from here.
|
||||
|
||||
from random import choice
|
||||
|
||||
from django.contrib.auth.hashers import make_password
|
||||
|
Loading…
Reference in New Issue
Block a user