2015-06-25 09:53:55 +02:00
|
|
|
from collections import defaultdict
|
2018-08-22 22:00:08 +02:00
|
|
|
from typing import Dict, List, Set
|
2013-03-18 12:34:47 +01:00
|
|
|
|
2015-09-07 17:09:29 +02:00
|
|
|
from django.conf import settings
|
2017-01-26 15:34:24 +01:00
|
|
|
from django.contrib.auth.models import AnonymousUser
|
2015-01-25 15:10:34 +01:00
|
|
|
from django.contrib.contenttypes.fields import GenericForeignKey
|
2013-09-25 10:01:01 +02:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2015-09-06 14:02:15 +02:00
|
|
|
from django.db import models, transaction
|
2016-09-08 11:13:21 +02:00
|
|
|
from django.utils import timezone
|
2018-07-09 23:22:26 +02:00
|
|
|
from django.utils.translation import ugettext as _, ugettext_lazy
|
2012-02-20 00:14:54 +01:00
|
|
|
|
2015-06-29 12:08:15 +02:00
|
|
|
from openslides.core.config import config
|
2017-07-28 15:42:58 +02:00
|
|
|
from openslides.core.models import Countdown, Projector
|
2017-11-03 09:32:43 +01:00
|
|
|
from openslides.utils.autoupdate import inform_changed_data
|
2013-03-18 12:34:47 +01:00
|
|
|
from openslides.utils.exceptions import OpenSlidesError
|
2015-06-29 12:08:15 +02:00
|
|
|
from openslides.utils.models import RESTModelMixin
|
2014-05-04 13:41:55 +02:00
|
|
|
from openslides.utils.utils import to_roman
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2016-02-11 22:58:32 +01:00
|
|
|
from .access_permissions import ItemAccessPermissions
|
|
|
|
|
2012-04-14 11:18:47 +02:00
|
|
|
|
2015-06-25 09:53:55 +02:00
|
|
|
class ItemManager(models.Manager):
|
2015-11-25 10:48:33 +01:00
|
|
|
"""
|
|
|
|
Customized model manager with special methods for agenda tree and
|
|
|
|
numbering.
|
|
|
|
"""
|
2016-09-18 16:00:31 +02:00
|
|
|
def get_full_queryset(self):
|
2016-09-30 20:42:58 +02:00
|
|
|
"""
|
|
|
|
Returns the normal queryset with all items. In the background all
|
|
|
|
speakers and related items (topics, motions, assignments) are
|
|
|
|
prefetched from the database.
|
|
|
|
"""
|
2016-09-18 16:00:31 +02:00
|
|
|
return self.get_queryset().prefetch_related('speakers', 'content_object')
|
|
|
|
|
2018-08-15 11:15:54 +02:00
|
|
|
def get_only_non_public_items(self):
|
2015-10-24 19:02:43 +02:00
|
|
|
"""
|
2018-08-15 11:15:54 +02:00
|
|
|
Generator, which yields only internal and hidden items, that means only items
|
|
|
|
which type is INTERNAL_ITEM or HIDDEN_ITEM or which are children of hidden items.
|
2015-10-24 19:02:43 +02:00
|
|
|
"""
|
2018-08-15 11:15:54 +02:00
|
|
|
# Do not execute non-hidden items because this would create a lot of db queries
|
|
|
|
root_items, item_children = self.get_root_and_children(only_item_type=None)
|
2015-10-24 19:02:43 +02:00
|
|
|
|
2018-08-15 11:15:54 +02:00
|
|
|
def yield_items(items, parent_is_not_public=False):
|
2015-10-24 19:02:43 +02:00
|
|
|
"""
|
|
|
|
Generator that yields a list of items and their children.
|
|
|
|
"""
|
|
|
|
for item in items:
|
2018-08-15 11:15:54 +02:00
|
|
|
if parent_is_not_public or item.type in (item.INTERNAL_ITEM, item.HIDDEN_ITEM):
|
|
|
|
item_is_not_public = True
|
2016-01-25 22:10:00 +01:00
|
|
|
yield item
|
|
|
|
else:
|
2018-08-15 11:15:54 +02:00
|
|
|
item_is_not_public = False
|
|
|
|
yield from yield_items(
|
|
|
|
item_children[item.pk],
|
|
|
|
parent_is_not_public=item_is_not_public)
|
2016-01-25 22:10:00 +01:00
|
|
|
|
2015-10-24 19:02:43 +02:00
|
|
|
yield from yield_items(root_items)
|
|
|
|
|
2018-08-15 11:15:54 +02:00
|
|
|
def get_root_and_children(self, only_item_type=None):
|
2015-10-24 19:02:43 +02:00
|
|
|
"""
|
|
|
|
Returns a list with all root items and a dictonary where the key is an
|
|
|
|
item pk and the value is a list with all children of the item.
|
|
|
|
|
2018-08-15 11:15:54 +02:00
|
|
|
If only_item_type is given, the tree hides items with other types and
|
|
|
|
all of their children.
|
2015-11-25 10:48:33 +01:00
|
|
|
"""
|
|
|
|
queryset = self.order_by('weight')
|
2018-08-22 22:00:08 +02:00
|
|
|
item_children: Dict[int, List[Item]] = defaultdict(list)
|
2015-10-24 19:02:43 +02:00
|
|
|
root_items = []
|
|
|
|
for item in queryset:
|
2018-08-15 11:15:54 +02:00
|
|
|
if only_item_type is not None and item.type != only_item_type:
|
2015-10-24 19:02:43 +02:00
|
|
|
continue
|
|
|
|
if item.parent_id is not None:
|
|
|
|
item_children[item.parent_id].append(item)
|
|
|
|
else:
|
|
|
|
root_items.append(item)
|
|
|
|
return root_items, item_children
|
|
|
|
|
2018-08-15 11:15:54 +02:00
|
|
|
def get_tree(self, only_item_type=None, include_content=False):
|
2015-06-25 09:53:55 +02:00
|
|
|
"""
|
|
|
|
Generator that yields dictonaries. Each dictonary has two keys, id
|
|
|
|
and children, where id is the id of one agenda item and children is a
|
|
|
|
generator that yields dictonaries like the one discribed.
|
|
|
|
|
2018-08-15 11:15:54 +02:00
|
|
|
If only_item_type is given, the tree hides items with other types and
|
|
|
|
all of their children.
|
2015-06-25 09:53:55 +02:00
|
|
|
|
|
|
|
If include_content is True, the yielded dictonaries have no key 'id'
|
|
|
|
but a key 'item' with the entire object.
|
|
|
|
"""
|
2018-08-15 11:15:54 +02:00
|
|
|
root_items, item_children = self.get_root_and_children(only_item_type=only_item_type)
|
2015-06-25 09:53:55 +02:00
|
|
|
|
|
|
|
def get_children(items):
|
|
|
|
"""
|
|
|
|
Generator that yields the descibed diconaries.
|
|
|
|
"""
|
|
|
|
for item in items:
|
|
|
|
if include_content:
|
|
|
|
yield dict(item=item, children=get_children(item_children[item.pk]))
|
|
|
|
else:
|
|
|
|
yield dict(id=item.pk, children=get_children(item_children[item.pk]))
|
|
|
|
|
2015-10-24 19:02:43 +02:00
|
|
|
yield from get_children(root_items)
|
2015-06-25 09:53:55 +02:00
|
|
|
|
2015-09-06 14:02:15 +02:00
|
|
|
@transaction.atomic
|
2015-06-25 09:53:55 +02:00
|
|
|
def set_tree(self, tree):
|
|
|
|
"""
|
|
|
|
Sets the agenda tree.
|
|
|
|
|
|
|
|
The tree has to be a nested object. For example:
|
|
|
|
[{"id": 1}, {"id": 2, "children": [{"id": 3}]}]
|
|
|
|
"""
|
|
|
|
def walk_items(tree, parent=None):
|
|
|
|
"""
|
|
|
|
Generator that returns each item in the tree as tuple.
|
|
|
|
|
|
|
|
This tuples have tree values. The item id, the item parent and the
|
|
|
|
weight of the item.
|
|
|
|
"""
|
|
|
|
for weight, element in enumerate(tree):
|
|
|
|
yield (element['id'], parent, weight)
|
|
|
|
yield from walk_items(element.get('children', []), element['id'])
|
|
|
|
|
2018-08-22 22:00:08 +02:00
|
|
|
touched_items: Set[int] = set()
|
2015-09-06 14:02:15 +02:00
|
|
|
db_items = dict((item.pk, item) for item in Item.objects.all())
|
|
|
|
for item_id, parent_id, weight in walk_items(tree):
|
2015-06-25 09:53:55 +02:00
|
|
|
# Check that the item is only once in the tree to prevent invalid trees
|
2015-09-06 14:02:15 +02:00
|
|
|
if item_id in touched_items:
|
|
|
|
raise ValueError("Item {} is more then once in the tree.".format(item_id))
|
|
|
|
touched_items.add(item_id)
|
|
|
|
|
|
|
|
try:
|
|
|
|
db_item = db_items[item_id]
|
|
|
|
except KeyError:
|
|
|
|
raise ValueError("Item {} is not in the database.".format(item_id))
|
|
|
|
|
|
|
|
# Check if the item has changed and update it
|
|
|
|
# Note: Do not use Item.objects.update, so that the items are sent
|
|
|
|
# to the clients via autoupdate
|
|
|
|
if db_item.parent_id != parent_id or db_item.weight != weight:
|
|
|
|
db_item.parent_id = parent_id
|
|
|
|
db_item.weight = weight
|
|
|
|
db_item.save()
|
2015-06-25 09:53:55 +02:00
|
|
|
|
2015-11-25 10:48:33 +01:00
|
|
|
@transaction.atomic
|
|
|
|
def number_all(self, numeral_system='arabic'):
|
|
|
|
"""
|
|
|
|
Auto numbering of the agenda according to the numeral_system. Manually
|
|
|
|
added item numbers will be overwritten.
|
|
|
|
"""
|
|
|
|
def walk_tree(tree, number=None):
|
|
|
|
for index, tree_element in enumerate(tree):
|
2016-01-25 22:10:00 +01:00
|
|
|
# Calculate number of visable agenda items.
|
2015-11-25 10:48:33 +01:00
|
|
|
if numeral_system == 'roman' and number is None:
|
|
|
|
item_number = to_roman(index + 1)
|
|
|
|
else:
|
|
|
|
item_number = str(index + 1)
|
|
|
|
if number is not None:
|
|
|
|
item_number = '.'.join((number, item_number))
|
2016-01-25 22:10:00 +01:00
|
|
|
# Add prefix.
|
2016-01-09 13:01:46 +01:00
|
|
|
if config['agenda_number_prefix']:
|
|
|
|
item_number_tmp = "%s %s" % (config['agenda_number_prefix'], item_number)
|
|
|
|
else:
|
|
|
|
item_number_tmp = item_number
|
2016-01-25 22:10:00 +01:00
|
|
|
# Save the new value and go down the tree.
|
2016-01-09 13:01:46 +01:00
|
|
|
tree_element['item'].item_number = item_number_tmp
|
2015-11-25 10:48:33 +01:00
|
|
|
tree_element['item'].save()
|
|
|
|
walk_tree(tree_element['children'], item_number)
|
|
|
|
|
2016-01-25 22:10:00 +01:00
|
|
|
# Start numbering visable agenda items.
|
2018-08-15 11:15:54 +02:00
|
|
|
walk_tree(self.get_tree(only_item_type=Item.AGENDA_ITEM, include_content=True))
|
2015-11-25 10:48:33 +01:00
|
|
|
|
2016-01-25 22:10:00 +01:00
|
|
|
# Reset number of hidden items.
|
2018-08-15 11:15:54 +02:00
|
|
|
for item in self.get_only_non_public_items():
|
2016-01-25 22:10:00 +01:00
|
|
|
item.item_number = ''
|
|
|
|
item.save()
|
|
|
|
|
2015-06-25 09:53:55 +02:00
|
|
|
|
2015-06-29 13:31:07 +02:00
|
|
|
class Item(RESTModelMixin, models.Model):
|
2011-07-31 10:46:29 +02:00
|
|
|
"""
|
2012-02-03 23:12:28 +01:00
|
|
|
An Agenda Item
|
2011-07-31 10:46:29 +02:00
|
|
|
"""
|
2016-02-11 22:58:32 +01:00
|
|
|
access_permissions = ItemAccessPermissions()
|
2015-06-25 09:53:55 +02:00
|
|
|
objects = ItemManager()
|
2012-02-09 02:29:38 +01:00
|
|
|
|
2013-02-01 15:13:40 +01:00
|
|
|
AGENDA_ITEM = 1
|
2018-08-15 11:15:54 +02:00
|
|
|
INTERNAL_ITEM = 2
|
|
|
|
HIDDEN_ITEM = 3
|
2013-02-01 15:13:40 +01:00
|
|
|
|
2013-01-05 23:52:29 +01:00
|
|
|
ITEM_TYPE = (
|
2013-04-22 19:59:05 +02:00
|
|
|
(AGENDA_ITEM, ugettext_lazy('Agenda item')),
|
2018-08-15 11:15:54 +02:00
|
|
|
(INTERNAL_ITEM, ugettext_lazy('Internal item')),
|
2015-10-24 19:02:43 +02:00
|
|
|
(HIDDEN_ITEM, ugettext_lazy('Hidden item')))
|
2013-01-05 23:52:29 +01:00
|
|
|
|
2016-01-09 13:32:56 +01:00
|
|
|
item_number = models.CharField(blank=True, max_length=255)
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
2014-04-28 01:03:10 +02:00
|
|
|
Number of agenda item.
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
2013-03-18 12:34:47 +01:00
|
|
|
|
2016-01-09 13:32:56 +01:00
|
|
|
comment = models.TextField(null=True, blank=True)
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
|
|
|
Optional comment to the agenda item. Will not be shoun to normal users.
|
|
|
|
"""
|
2013-03-18 12:34:47 +01:00
|
|
|
|
2016-01-09 13:32:56 +01:00
|
|
|
closed = models.BooleanField(default=False)
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
|
|
|
Flag, if the item is finished.
|
|
|
|
"""
|
2013-03-18 12:34:47 +01:00
|
|
|
|
2015-10-24 19:02:43 +02:00
|
|
|
type = models.IntegerField(
|
|
|
|
choices=ITEM_TYPE,
|
2016-01-22 23:19:41 +01:00
|
|
|
default=HIDDEN_ITEM)
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
|
|
|
Type of the agenda item.
|
|
|
|
|
2013-05-11 16:26:43 +02:00
|
|
|
See Item.ITEM_TYPE for more information.
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
|
|
|
|
2016-09-22 13:19:11 +02:00
|
|
|
duration = models.IntegerField(null=True, blank=True)
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
|
|
|
The intended duration for the topic.
|
|
|
|
"""
|
2013-03-18 12:34:47 +01:00
|
|
|
|
2016-01-09 09:58:22 +01:00
|
|
|
parent = models.ForeignKey(
|
|
|
|
'self',
|
|
|
|
on_delete=models.SET_NULL,
|
|
|
|
null=True,
|
|
|
|
blank=True,
|
|
|
|
related_name='children')
|
2013-06-03 19:02:27 +02:00
|
|
|
"""
|
|
|
|
The parent item in the agenda tree.
|
|
|
|
"""
|
|
|
|
|
2016-01-27 21:31:06 +01:00
|
|
|
weight = models.IntegerField(default=10000)
|
2013-06-03 19:02:27 +02:00
|
|
|
"""
|
|
|
|
Weight to sort the item in the agenda.
|
|
|
|
"""
|
|
|
|
|
2016-01-09 09:58:22 +01:00
|
|
|
content_type = models.ForeignKey(
|
|
|
|
ContentType,
|
|
|
|
on_delete=models.SET_NULL,
|
|
|
|
null=True,
|
|
|
|
blank=True)
|
2013-09-07 00:18:13 +02:00
|
|
|
"""
|
|
|
|
Field for generic relation to a related object. Type of the object.
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
|
|
|
|
2013-09-07 00:18:13 +02:00
|
|
|
object_id = models.PositiveIntegerField(null=True, blank=True)
|
|
|
|
"""
|
|
|
|
Field for generic relation to a related object. Id of the object.
|
|
|
|
"""
|
|
|
|
|
2015-01-25 15:10:34 +01:00
|
|
|
content_object = GenericForeignKey()
|
2013-09-07 00:18:13 +02:00
|
|
|
"""
|
|
|
|
Field for generic relation to a related object. General field to the related object.
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
speaker_list_closed = models.BooleanField(
|
2016-01-09 13:32:56 +01:00
|
|
|
default=False)
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
|
|
|
True, if the list of speakers is closed.
|
|
|
|
"""
|
2012-04-19 12:46:04 +02:00
|
|
|
|
2013-04-29 20:03:50 +02:00
|
|
|
class Meta:
|
2015-12-10 00:20:59 +01:00
|
|
|
default_permissions = ()
|
2013-04-29 20:03:50 +02:00
|
|
|
permissions = (
|
2016-01-27 13:41:19 +01:00
|
|
|
('can_see', 'Can see agenda'),
|
|
|
|
('can_manage', 'Can manage agenda'),
|
2017-08-18 13:13:53 +02:00
|
|
|
('can_manage_list_of_speakers', 'Can manage list of speakers'),
|
2018-08-15 11:15:54 +02:00
|
|
|
('can_see_internal_items', 'Can see internal items and time scheduling of agenda'))
|
2015-10-24 19:02:43 +02:00
|
|
|
unique_together = ('content_type', 'object_id')
|
2013-04-29 20:03:50 +02:00
|
|
|
|
2015-06-16 10:37:23 +02:00
|
|
|
def __str__(self):
|
2015-10-24 19:02:43 +02:00
|
|
|
return self.title
|
2014-04-28 01:03:10 +02:00
|
|
|
|
2017-07-28 15:42:58 +02:00
|
|
|
def delete(self, skip_autoupdate=False, *args, **kwargs):
|
|
|
|
"""
|
|
|
|
Customized method to delete an agenda item. Ensures that a respective
|
|
|
|
list of speakers projector element is disabled.
|
|
|
|
"""
|
|
|
|
Projector.remove_any(
|
|
|
|
skip_autoupdate=skip_autoupdate,
|
|
|
|
name='agenda/list-of-speakers',
|
|
|
|
id=self.pk)
|
2017-08-24 12:26:55 +02:00
|
|
|
return super().delete(skip_autoupdate=skip_autoupdate, *args, **kwargs) # type: ignore
|
2017-07-28 15:42:58 +02:00
|
|
|
|
2015-10-24 19:02:43 +02:00
|
|
|
@property
|
|
|
|
def title(self):
|
2012-07-20 11:22:09 +02:00
|
|
|
"""
|
2015-10-24 19:02:43 +02:00
|
|
|
Return get_agenda_title() from the content_object.
|
2012-07-20 11:22:09 +02:00
|
|
|
"""
|
|
|
|
try:
|
2016-01-09 13:01:46 +01:00
|
|
|
return self.content_object.get_agenda_title()
|
2012-07-20 11:22:09 +02:00
|
|
|
except AttributeError:
|
2015-10-24 19:02:43 +02:00
|
|
|
raise NotImplementedError('You have to provide a get_agenda_title '
|
|
|
|
'method on your related model.')
|
2012-07-20 11:22:09 +02:00
|
|
|
|
2016-01-25 21:22:22 +01:00
|
|
|
@property
|
|
|
|
def list_view_title(self):
|
|
|
|
"""
|
|
|
|
Return get_agenda_list_view_title() from the content_object.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
return self.content_object.get_agenda_list_view_title()
|
|
|
|
except AttributeError:
|
|
|
|
raise NotImplementedError('You have to provide a get_agenda_list_view_title '
|
|
|
|
'method on your related model.')
|
|
|
|
|
2018-08-15 11:15:54 +02:00
|
|
|
def is_internal(self):
|
|
|
|
"""
|
|
|
|
Returns True if the type of this object itself is a internal item or any
|
|
|
|
of its ancestors has such a type.
|
|
|
|
|
|
|
|
Attention! This executes one query for each ancestor of the item.
|
|
|
|
"""
|
|
|
|
return (self.type == self.INTERNAL_ITEM or
|
|
|
|
(self.parent is not None and self.parent.is_internal()))
|
|
|
|
|
2015-10-24 19:02:43 +02:00
|
|
|
def is_hidden(self):
|
2011-07-31 10:46:29 +02:00
|
|
|
"""
|
2015-10-24 19:02:43 +02:00
|
|
|
Returns True if the type of this object itself is a hidden item or any
|
|
|
|
of its ancestors has such a type.
|
|
|
|
|
|
|
|
Attention! This executes one query for each ancestor of the item.
|
2011-07-31 10:46:29 +02:00
|
|
|
"""
|
2015-10-24 19:02:43 +02:00
|
|
|
return (self.type == self.HIDDEN_ITEM or
|
|
|
|
(self.parent is not None and self.parent.is_hidden()))
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2013-05-24 01:44:58 +02:00
|
|
|
def get_next_speaker(self):
|
|
|
|
"""
|
2015-09-07 17:09:29 +02:00
|
|
|
Returns the speaker object of the speaker who is next.
|
2013-05-24 01:44:58 +02:00
|
|
|
"""
|
|
|
|
try:
|
2015-07-06 09:19:42 +02:00
|
|
|
return self.speakers.filter(begin_time=None).order_by('weight')[0]
|
2013-05-24 01:44:58 +02:00
|
|
|
except IndexError:
|
|
|
|
# The list of speakers is empty.
|
|
|
|
return None
|
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2013-03-18 12:34:47 +01:00
|
|
|
class SpeakerManager(models.Manager):
|
2015-09-07 17:09:29 +02:00
|
|
|
"""
|
|
|
|
Manager for Speaker model. Provides a customized add method.
|
|
|
|
"""
|
2017-03-21 11:06:05 +01:00
|
|
|
def add(self, user, item, skip_autoupdate=False):
|
2015-09-07 17:09:29 +02:00
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
2014-10-11 14:34:49 +02:00
|
|
|
if self.filter(user=user, item=item, begin_time=None).exists():
|
2015-09-07 17:09:29 +02:00
|
|
|
raise OpenSlidesError(
|
2016-01-10 09:47:08 +01:00
|
|
|
_('{user} is already on the list of speakers.').format(user=user))
|
2017-01-26 15:34:24 +01:00
|
|
|
if isinstance(user, AnonymousUser):
|
2013-06-09 17:51:30 +02:00
|
|
|
raise OpenSlidesError(
|
2013-06-16 17:29:52 +02:00
|
|
|
_('An anonymous user can not be on lists of speakers.'))
|
2013-03-18 12:34:47 +01:00
|
|
|
weight = (self.filter(item=item).aggregate(
|
|
|
|
models.Max('weight'))['weight__max'] or 0)
|
2017-03-21 11:06:05 +01:00
|
|
|
speaker = self.model(item=item, user=user, weight=weight + 1)
|
|
|
|
speaker.save(force_insert=True, skip_autoupdate=skip_autoupdate)
|
|
|
|
return speaker
|
2013-03-18 12:34:47 +01:00
|
|
|
|
|
|
|
|
2015-06-16 10:37:23 +02:00
|
|
|
class Speaker(RESTModelMixin, models.Model):
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
|
|
|
Model for the Speaker list.
|
|
|
|
"""
|
|
|
|
|
|
|
|
objects = SpeakerManager()
|
|
|
|
|
2016-01-09 09:58:22 +01:00
|
|
|
user = models.ForeignKey(
|
|
|
|
settings.AUTH_USER_MODEL,
|
|
|
|
on_delete=models.CASCADE)
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
2014-10-11 14:34:49 +02:00
|
|
|
ForeinKey to the user who speaks.
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
|
|
|
|
2016-01-09 09:58:22 +01:00
|
|
|
item = models.ForeignKey(
|
|
|
|
Item,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
related_name='speakers')
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
2015-09-07 17:09:29 +02:00
|
|
|
ForeinKey to the agenda item to which the user want to speak.
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
|
|
|
|
2013-04-25 16:18:16 +02:00
|
|
|
begin_time = models.DateTimeField(null=True)
|
|
|
|
"""
|
|
|
|
Saves the time, when the speaker begins to speak. None, if he has not spoken yet.
|
|
|
|
"""
|
|
|
|
|
|
|
|
end_time = models.DateTimeField(null=True)
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
2015-09-04 18:24:41 +02:00
|
|
|
Saves the time, when the speaker ends his speech. None, if he is not finished yet.
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
|
|
|
|
2013-03-18 12:34:47 +01:00
|
|
|
weight = models.IntegerField(null=True)
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
|
|
|
The sort order of the list of speakers. None, if he has already spoken.
|
|
|
|
"""
|
2013-03-18 12:34:47 +01:00
|
|
|
|
2018-02-06 14:52:47 +01:00
|
|
|
marked = models.BooleanField(default=False)
|
|
|
|
"""
|
|
|
|
Marks a speaker.
|
|
|
|
"""
|
|
|
|
|
2013-03-18 12:34:47 +01:00
|
|
|
class Meta:
|
2015-12-10 00:20:59 +01:00
|
|
|
default_permissions = ()
|
2013-03-18 12:34:47 +01:00
|
|
|
permissions = (
|
2016-01-27 13:41:19 +01:00
|
|
|
('can_be_speaker', 'Can put oneself on the list of speakers'),
|
2013-03-18 12:34:47 +01:00
|
|
|
)
|
|
|
|
|
2014-08-16 09:25:18 +02:00
|
|
|
def __str__(self):
|
2014-10-11 14:34:49 +02:00
|
|
|
return str(self.user)
|
2013-03-18 12:34:47 +01:00
|
|
|
|
2015-09-04 18:24:41 +02:00
|
|
|
def begin_speech(self):
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
2014-10-11 14:34:49 +02:00
|
|
|
Let the user speak.
|
2013-03-18 12:34:47 +01:00
|
|
|
|
2013-04-25 16:18:16 +02:00
|
|
|
Set the weight to None and the time to now. If anyone is still
|
2015-09-04 18:24:41 +02:00
|
|
|
speaking, end his speech.
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
2013-04-25 16:18:16 +02:00
|
|
|
try:
|
2015-10-24 19:02:43 +02:00
|
|
|
current_speaker = (Speaker.objects.filter(item=self.item, end_time=None)
|
|
|
|
.exclude(begin_time=None).get())
|
2013-04-25 16:18:16 +02:00
|
|
|
except Speaker.DoesNotExist:
|
|
|
|
pass
|
|
|
|
else:
|
2017-11-03 09:32:43 +01:00
|
|
|
# Do not send an autoupdate for the countdown and the item. This is done
|
|
|
|
# by saving the item and countdown later.
|
|
|
|
current_speaker.end_speech(skip_autoupdate=True)
|
2013-03-18 12:34:47 +01:00
|
|
|
self.weight = None
|
2016-09-08 11:13:21 +02:00
|
|
|
self.begin_time = timezone.now()
|
2017-11-03 09:32:43 +01:00
|
|
|
self.save() # Here, the item is saved and causes an autoupdate.
|
2013-10-07 08:52:18 +02:00
|
|
|
if config['agenda_couple_countdown_and_speakers']:
|
2016-10-21 11:05:24 +02:00
|
|
|
countdown, created = Countdown.objects.get_or_create(pk=1, defaults={
|
|
|
|
'default_time': config['projector_default_countdown'],
|
|
|
|
'countdown_time': config['projector_default_countdown']})
|
|
|
|
if not created:
|
2017-11-03 09:32:43 +01:00
|
|
|
countdown.control(action='reset', skip_autoupdate=True)
|
|
|
|
countdown.control(action='start', skip_autoupdate=True)
|
2013-04-25 16:18:16 +02:00
|
|
|
|
2017-11-03 09:32:43 +01:00
|
|
|
inform_changed_data(countdown) # Here, the autoupdate for the countdown is triggered.
|
|
|
|
|
|
|
|
def end_speech(self, skip_autoupdate=False):
|
2013-04-25 16:18:16 +02:00
|
|
|
"""
|
2015-09-04 18:24:41 +02:00
|
|
|
The speech is finished. Set the time to now.
|
2013-04-25 16:18:16 +02:00
|
|
|
"""
|
2016-09-08 11:13:21 +02:00
|
|
|
self.end_time = timezone.now()
|
2017-11-03 09:32:43 +01:00
|
|
|
self.save(skip_autoupdate=skip_autoupdate)
|
2013-10-07 08:52:18 +02:00
|
|
|
if config['agenda_couple_countdown_and_speakers']:
|
2016-10-21 11:05:24 +02:00
|
|
|
try:
|
|
|
|
countdown = Countdown.objects.get(pk=1)
|
|
|
|
except Countdown.DoesNotExist:
|
|
|
|
pass # Do not create a new countdown on stop action
|
|
|
|
else:
|
2017-11-03 09:32:43 +01:00
|
|
|
countdown.control(action='reset', skip_autoupdate=skip_autoupdate)
|
2015-01-17 14:01:44 +01:00
|
|
|
|
|
|
|
def get_root_rest_element(self):
|
|
|
|
"""
|
2015-01-24 16:35:50 +01:00
|
|
|
Returns the item to this instance which is the root REST element.
|
2015-01-17 14:01:44 +01:00
|
|
|
"""
|
|
|
|
return self.item
|