2015-06-25 09:53:55 +02:00
|
|
|
from collections import defaultdict
|
2013-03-18 12:34:47 +01:00
|
|
|
from datetime import datetime
|
|
|
|
|
2013-06-09 17:51:30 +02: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
|
2014-04-28 01:03:10 +02:00
|
|
|
from django.core.exceptions import ValidationError
|
2013-09-25 10:01:01 +02:00
|
|
|
from django.db import models
|
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
from django.utils.translation import ugettext_lazy, ugettext_noop
|
2012-02-20 00:14:54 +01:00
|
|
|
|
2015-06-29 12:08:15 +02:00
|
|
|
from openslides.core.config import config
|
2014-12-26 13:45:13 +01:00
|
|
|
from openslides.core.models import Tag
|
2015-06-16 10:37:23 +02:00
|
|
|
from openslides.users.models import User
|
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
|
|
|
|
2012-04-14 11:18:47 +02:00
|
|
|
|
2015-06-25 09:53:55 +02:00
|
|
|
class ItemManager(models.Manager):
|
|
|
|
def get_tree(self, only_agenda_items=False, include_content=False):
|
|
|
|
"""
|
|
|
|
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.
|
|
|
|
|
|
|
|
If only_agenda_items is True, the tree hides ORGANIZATIONAL_ITEMs.
|
|
|
|
|
|
|
|
If include_content is True, the yielded dictonaries have no key 'id'
|
|
|
|
but a key 'item' with the entire object.
|
|
|
|
"""
|
|
|
|
item_queryset = self.order_by('weight')
|
|
|
|
if only_agenda_items:
|
|
|
|
item_queryset = item_queryset.filter(type__exact=Item.AGENDA_ITEM)
|
|
|
|
|
|
|
|
# Index the items to get the children for each item
|
|
|
|
item_children = defaultdict(list)
|
|
|
|
for item in item_queryset:
|
|
|
|
if item.parent:
|
|
|
|
item_children[item.parent_id].append(item)
|
|
|
|
|
|
|
|
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]))
|
|
|
|
|
|
|
|
yield from get_children(filter(lambda item: item.parent is None, item_queryset))
|
|
|
|
|
|
|
|
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'])
|
|
|
|
|
|
|
|
touched_items = set()
|
|
|
|
for item_pk, parent_pk, weight in walk_items(tree):
|
|
|
|
# Check that the item is only once in the tree to prevent invalid trees
|
|
|
|
if item_pk in touched_items:
|
|
|
|
raise ValueError("Item %d is more then once in the tree" % item_pk)
|
|
|
|
touched_items.add(item_pk)
|
|
|
|
|
|
|
|
Item.objects.filter(pk=item_pk).update(
|
|
|
|
parent_id=parent_pk,
|
|
|
|
weight=weight)
|
|
|
|
|
|
|
|
|
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
|
|
|
"""
|
2015-06-25 09:53:55 +02:00
|
|
|
objects = ItemManager()
|
2013-08-04 12:59:11 +02:00
|
|
|
slide_callback_name = 'agenda'
|
2012-02-09 02:29:38 +01:00
|
|
|
|
2013-02-01 15:13:40 +01:00
|
|
|
AGENDA_ITEM = 1
|
|
|
|
ORGANIZATIONAL_ITEM = 2
|
|
|
|
|
2013-01-05 23:52:29 +01:00
|
|
|
ITEM_TYPE = (
|
2013-04-22 19:59:05 +02:00
|
|
|
(AGENDA_ITEM, ugettext_lazy('Agenda item')),
|
|
|
|
(ORGANIZATIONAL_ITEM, ugettext_lazy('Organizational item')))
|
2013-01-05 23:52:29 +01:00
|
|
|
|
2014-04-28 01:03:10 +02:00
|
|
|
item_number = models.CharField(blank=True, max_length=255, verbose_name=ugettext_lazy("Number"))
|
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
|
|
|
|
2014-04-28 01:03:10 +02:00
|
|
|
title = models.CharField(null=True, max_length=255, verbose_name=ugettext_lazy("Title"))
|
2014-04-27 21:01:23 +02:00
|
|
|
"""
|
2014-04-28 01:03:10 +02:00
|
|
|
Title of the agenda item.
|
2014-04-27 21:01:23 +02:00
|
|
|
"""
|
|
|
|
|
2013-04-22 19:59:05 +02:00
|
|
|
text = models.TextField(null=True, blank=True, verbose_name=ugettext_lazy("Text"))
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
|
|
|
The optional text of the agenda item.
|
|
|
|
"""
|
2013-03-18 12:34:47 +01:00
|
|
|
|
2013-04-22 19:59:05 +02:00
|
|
|
comment = models.TextField(null=True, blank=True, verbose_name=ugettext_lazy("Comment"))
|
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
|
|
|
|
2013-04-22 19:59:05 +02:00
|
|
|
closed = models.BooleanField(default=False, verbose_name=ugettext_lazy("Closed"))
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
|
|
|
Flag, if the item is finished.
|
|
|
|
"""
|
2013-03-18 12:34:47 +01:00
|
|
|
|
2015-06-30 02:37:57 +02:00
|
|
|
type = models.IntegerField(choices=ITEM_TYPE, default=AGENDA_ITEM, verbose_name=ugettext_lazy("Type"))
|
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
|
|
|
"""
|
|
|
|
|
2013-11-22 09:01:52 +01:00
|
|
|
duration = models.CharField(null=True, blank=True, max_length=5)
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
|
|
|
The intended duration for the topic.
|
|
|
|
"""
|
2013-03-18 12:34:47 +01:00
|
|
|
|
2015-06-16 10:37:23 +02:00
|
|
|
parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
|
2013-06-03 19:02:27 +02:00
|
|
|
"""
|
|
|
|
The parent item in the agenda tree.
|
|
|
|
"""
|
|
|
|
|
|
|
|
weight = models.IntegerField(default=0, verbose_name=ugettext_lazy("Weight"))
|
|
|
|
"""
|
|
|
|
Weight to sort the item in the agenda.
|
|
|
|
"""
|
|
|
|
|
2013-09-07 00:18:13 +02:00
|
|
|
content_type = models.ForeignKey(ContentType, null=True, blank=True)
|
|
|
|
"""
|
|
|
|
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(
|
2013-04-22 19:59:05 +02:00
|
|
|
default=False, verbose_name=ugettext_lazy("List of speakers is closed"))
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
|
|
|
True, if the list of speakers is closed.
|
|
|
|
"""
|
2012-04-19 12:46:04 +02:00
|
|
|
|
2014-12-26 13:45:13 +01:00
|
|
|
tags = models.ManyToManyField(Tag, blank=True)
|
|
|
|
"""
|
|
|
|
Tags to categorise agenda items.
|
|
|
|
"""
|
|
|
|
|
2013-04-29 20:03:50 +02:00
|
|
|
class Meta:
|
|
|
|
permissions = (
|
2015-03-26 05:36:10 +01:00
|
|
|
('can_see', ugettext_noop("Can see agenda")),
|
|
|
|
('can_manage', ugettext_noop("Can manage agenda")),
|
2013-04-29 20:03:50 +02:00
|
|
|
('can_see_orga_items', ugettext_noop("Can see orga items and time scheduling of agenda")))
|
|
|
|
|
2015-06-16 10:37:23 +02:00
|
|
|
def __str__(self):
|
|
|
|
return self.get_title()
|
2013-04-29 20:03:50 +02:00
|
|
|
|
2014-04-28 01:03:10 +02:00
|
|
|
def clean(self):
|
|
|
|
"""
|
|
|
|
Ensures that the children of orga items are only orga items.
|
|
|
|
"""
|
2015-06-16 10:37:23 +02:00
|
|
|
if (self.type == self.AGENDA_ITEM and
|
|
|
|
self.parent is not None and
|
|
|
|
self.parent.type == self.ORGANIZATIONAL_ITEM):
|
2014-05-12 21:09:09 +02:00
|
|
|
raise ValidationError(_('Agenda items can not be child elements of an organizational item.'))
|
2015-06-16 10:37:23 +02:00
|
|
|
if (self.type == self.ORGANIZATIONAL_ITEM and
|
|
|
|
self.children.filter(type=self.AGENDA_ITEM).exists()):
|
2014-05-12 21:09:09 +02:00
|
|
|
raise ValidationError(_('Organizational items can not have agenda items as child elements.'))
|
2015-01-17 14:01:44 +01:00
|
|
|
return super().clean()
|
2014-04-28 01:03:10 +02:00
|
|
|
|
2015-06-16 10:37:23 +02:00
|
|
|
def delete(self, with_children=False):
|
2013-04-29 20:03:50 +02:00
|
|
|
"""
|
2015-06-16 10:37:23 +02:00
|
|
|
Delete the Item.
|
2013-04-29 20:03:50 +02:00
|
|
|
|
2015-06-16 10:37:23 +02:00
|
|
|
If with_children is True, all children of the item will be deleted as
|
|
|
|
well. If with_children is False, all children will be children of the
|
|
|
|
parent of the item.
|
2013-04-29 20:03:50 +02:00
|
|
|
"""
|
2015-06-16 10:37:23 +02:00
|
|
|
if not with_children:
|
|
|
|
for child in self.children.all():
|
|
|
|
child.parent = self.parent
|
|
|
|
child.save()
|
|
|
|
super().delete()
|
2013-04-29 20:03:50 +02:00
|
|
|
|
2012-04-19 12:46:04 +02:00
|
|
|
def get_title(self):
|
2012-07-04 12:50:33 +02:00
|
|
|
"""
|
2013-04-29 20:03:50 +02:00
|
|
|
Return the title of this item.
|
2012-07-04 12:50:33 +02:00
|
|
|
"""
|
2013-09-07 00:18:13 +02:00
|
|
|
if not self.content_object:
|
2015-05-05 10:42:31 +02:00
|
|
|
agenda_title = self.title or ""
|
2015-02-06 23:57:52 +01:00
|
|
|
else:
|
|
|
|
try:
|
|
|
|
agenda_title = self.content_object.get_agenda_title()
|
|
|
|
except AttributeError:
|
|
|
|
raise NotImplementedError('You have to provide a get_agenda_title '
|
|
|
|
'method on your related model.')
|
|
|
|
return '%s %s' % (self.item_no, agenda_title) if self.item_no else agenda_title
|
2012-04-19 12:46:04 +02:00
|
|
|
|
2012-07-20 11:22:09 +02:00
|
|
|
def get_title_supplement(self):
|
|
|
|
"""
|
2013-04-29 20:03:50 +02:00
|
|
|
Return a supplement for the title.
|
2012-07-20 11:22:09 +02:00
|
|
|
"""
|
2013-09-07 00:18:13 +02:00
|
|
|
if not self.content_object:
|
2012-07-20 11:22:09 +02:00
|
|
|
return ''
|
|
|
|
try:
|
2013-09-07 00:18:13 +02:00
|
|
|
return self.content_object.get_agenda_title_supplement()
|
2012-07-20 11:22:09 +02:00
|
|
|
except AttributeError:
|
2013-09-07 00:18:13 +02:00
|
|
|
raise NotImplementedError('You have to provide a get_agenda_title_supplement method on your related model.')
|
2012-07-20 11:22:09 +02:00
|
|
|
|
2013-04-29 20:03:50 +02:00
|
|
|
def get_list_of_speakers(self, old_speakers_count=None, coming_speakers_count=None):
|
2011-07-31 10:46:29 +02:00
|
|
|
"""
|
2013-04-29 20:03:50 +02:00
|
|
|
Returns the list of speakers as a list of dictionaries. Each
|
|
|
|
dictionary contains a prefix, the speaker and its type. Types
|
|
|
|
are old_speaker, actual_speaker and coming_speaker.
|
2011-07-31 10:46:29 +02:00
|
|
|
"""
|
2013-04-29 20:03:50 +02:00
|
|
|
list_of_speakers = []
|
|
|
|
|
|
|
|
# Parse old speakers
|
2015-07-06 09:19:42 +02:00
|
|
|
old_speakers = self.speakers.exclude(begin_time=None).exclude(end_time=None).order_by('end_time')
|
2013-04-29 20:03:50 +02:00
|
|
|
if old_speakers_count is None:
|
|
|
|
old_speakers_count = old_speakers.count()
|
|
|
|
last_old_speakers_count = max(0, old_speakers.count() - old_speakers_count)
|
|
|
|
old_speakers = old_speakers[last_old_speakers_count:]
|
|
|
|
for number, speaker in enumerate(old_speakers):
|
|
|
|
prefix = old_speakers_count - number
|
|
|
|
speaker_dict = {
|
|
|
|
'prefix': '-%d' % prefix,
|
|
|
|
'speaker': speaker,
|
|
|
|
'type': 'old_speaker',
|
|
|
|
'first_in_group': False,
|
|
|
|
'last_in_group': False}
|
|
|
|
if number == 0:
|
|
|
|
speaker_dict['first_in_group'] = True
|
|
|
|
if number == old_speakers_count - 1:
|
|
|
|
speaker_dict['last_in_group'] = True
|
|
|
|
list_of_speakers.append(speaker_dict)
|
|
|
|
|
|
|
|
# Parse actual speaker
|
|
|
|
try:
|
2015-07-06 09:19:42 +02:00
|
|
|
actual_speaker = self.speakers.filter(end_time=None).exclude(begin_time=None).get()
|
2013-04-29 20:03:50 +02:00
|
|
|
except Speaker.DoesNotExist:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
list_of_speakers.append({
|
|
|
|
'prefix': '0',
|
|
|
|
'speaker': actual_speaker,
|
|
|
|
'type': 'actual_speaker',
|
|
|
|
'first_in_group': True,
|
|
|
|
'last_in_group': True})
|
|
|
|
|
|
|
|
# Parse coming speakers
|
2015-07-06 09:19:42 +02:00
|
|
|
coming_speakers = self.speakers.filter(begin_time=None).order_by('weight')
|
2013-04-29 20:03:50 +02:00
|
|
|
if coming_speakers_count is None:
|
|
|
|
coming_speakers_count = coming_speakers.count()
|
|
|
|
coming_speakers = coming_speakers[:max(0, coming_speakers_count)]
|
|
|
|
for number, speaker in enumerate(coming_speakers):
|
|
|
|
speaker_dict = {
|
|
|
|
'prefix': number + 1,
|
|
|
|
'speaker': speaker,
|
|
|
|
'type': 'coming_speaker',
|
|
|
|
'first_in_group': False,
|
|
|
|
'last_in_group': False}
|
|
|
|
if number == 0:
|
|
|
|
speaker_dict['first_in_group'] = True
|
|
|
|
if number == coming_speakers_count - 1:
|
|
|
|
speaker_dict['last_in_group'] = True
|
|
|
|
list_of_speakers.append(speaker_dict)
|
|
|
|
|
|
|
|
return list_of_speakers
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2013-05-24 01:44:58 +02:00
|
|
|
def get_next_speaker(self):
|
|
|
|
"""
|
2014-10-11 14:34:49 +02:00
|
|
|
Returns the speaker object of the user 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
|
|
|
|
|
2014-04-27 21:01:23 +02:00
|
|
|
@property
|
|
|
|
def item_no(self):
|
2014-10-10 21:30:22 +02:00
|
|
|
item_no = None
|
2014-05-03 19:38:12 +02:00
|
|
|
if self.item_number:
|
2014-10-10 21:30:22 +02:00
|
|
|
if config['agenda_number_prefix']:
|
|
|
|
item_no = '%s %s' % (config['agenda_number_prefix'], self.item_number)
|
|
|
|
else:
|
|
|
|
item_no = str(self.item_number)
|
2014-04-28 01:03:10 +02:00
|
|
|
return item_no
|
2014-04-27 21:01:23 +02:00
|
|
|
|
|
|
|
def calc_item_no(self):
|
|
|
|
"""
|
2014-04-28 01:03:10 +02:00
|
|
|
Returns the number of this agenda item.
|
2014-04-27 21:01:23 +02:00
|
|
|
"""
|
|
|
|
if self.type == self.AGENDA_ITEM:
|
2015-06-16 10:37:23 +02:00
|
|
|
if self.parent is None:
|
|
|
|
sibling_no = self.sibling_no()
|
2014-04-28 01:03:10 +02:00
|
|
|
if config['agenda_numeral_system'] == 'arabic':
|
2015-06-16 10:37:23 +02:00
|
|
|
return str(sibling_no)
|
2014-04-28 01:03:10 +02:00
|
|
|
else: # config['agenda_numeral_system'] == 'roman'
|
2015-06-16 10:37:23 +02:00
|
|
|
return to_roman(sibling_no)
|
2014-04-27 21:01:23 +02:00
|
|
|
else:
|
2015-06-16 10:37:23 +02:00
|
|
|
return '%s.%s' % (self.parent.calc_item_no(), self.sibling_no())
|
2014-05-04 13:41:55 +02:00
|
|
|
else:
|
|
|
|
return ''
|
2014-04-27 21:01:23 +02:00
|
|
|
|
2015-06-16 10:37:23 +02:00
|
|
|
def sibling_no(self):
|
2014-04-27 21:01:23 +02:00
|
|
|
"""
|
2015-06-16 10:37:23 +02:00
|
|
|
Counts how many AGENDA_ITEMS with the same parent (siblings) have a
|
|
|
|
smaller weight then this item.
|
|
|
|
|
|
|
|
Returns this number + 1 or 0 when self is not an AGENDA_ITEM.
|
2014-04-27 21:01:23 +02:00
|
|
|
"""
|
2015-06-16 10:37:23 +02:00
|
|
|
return Item.objects.filter(
|
|
|
|
parent=self.parent,
|
|
|
|
type=self.AGENDA_ITEM,
|
|
|
|
weight__lte=self.weight).count()
|
2014-04-27 21:01:23 +02:00
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2013-03-18 12:34:47 +01:00
|
|
|
class SpeakerManager(models.Manager):
|
2014-10-11 14:34:49 +02:00
|
|
|
def add(self, user, item):
|
|
|
|
if self.filter(user=user, item=item, begin_time=None).exists():
|
2013-06-09 17:51:30 +02:00
|
|
|
raise OpenSlidesError(_(
|
2014-10-11 14:34:49 +02:00
|
|
|
'%(user)s is already on the list of speakers of item %(id)s.')
|
|
|
|
% {'user': user, 'id': item.id})
|
|
|
|
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)
|
2014-10-11 14:34:49 +02:00
|
|
|
return self.create(item=item, user=user, weight=weight + 1)
|
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()
|
|
|
|
|
2014-10-11 14:34:49 +02:00
|
|
|
user = models.ForeignKey(User)
|
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
|
|
|
"""
|
|
|
|
|
2015-07-06 09:19:42 +02:00
|
|
|
item = models.ForeignKey(Item, related_name='speakers')
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
2014-10-11 14:34:49 +02:00
|
|
|
ForeinKey to the AgendaItem 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
|
|
|
|
|
|
|
class Meta:
|
|
|
|
permissions = (
|
2013-04-22 19:59:05 +02:00
|
|
|
('can_be_speaker', ugettext_noop('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:
|
|
|
|
actual_speaker = Speaker.objects.filter(item=self.item, end_time=None).exclude(begin_time=None).get()
|
|
|
|
except Speaker.DoesNotExist:
|
|
|
|
pass
|
|
|
|
else:
|
2015-09-04 18:24:41 +02:00
|
|
|
actual_speaker.end_speech()
|
2013-03-18 12:34:47 +01:00
|
|
|
self.weight = None
|
2013-04-25 16:18:16 +02:00
|
|
|
self.begin_time = datetime.now()
|
|
|
|
self.save()
|
2013-10-07 08:52:18 +02:00
|
|
|
# start countdown
|
|
|
|
if config['agenda_couple_countdown_and_speakers']:
|
2015-06-16 10:37:23 +02:00
|
|
|
# TODO: Fix me with the new countdown api
|
|
|
|
# reset_countdown()
|
|
|
|
# start_countdown()
|
|
|
|
pass
|
2013-04-25 16:18:16 +02:00
|
|
|
|
2015-09-04 18:24:41 +02:00
|
|
|
def end_speech(self):
|
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
|
|
|
"""
|
|
|
|
self.end_time = datetime.now()
|
2013-03-18 12:34:47 +01:00
|
|
|
self.save()
|
2013-10-07 08:52:18 +02:00
|
|
|
# stop countdown
|
|
|
|
if config['agenda_couple_countdown_and_speakers']:
|
2015-06-16 10:37:23 +02:00
|
|
|
# TODO: Fix me with the new countdown api
|
|
|
|
# stop_countdown()
|
|
|
|
pass
|
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
|