2018-08-22 22:00:08 +02:00
|
|
|
from typing import Any, Dict
|
2018-01-20 09:54:46 +01:00
|
|
|
|
2016-09-18 16:00:31 +02:00
|
|
|
from django.contrib.contenttypes.fields import GenericRelation
|
2016-09-18 22:14:24 +02:00
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
from ..agenda.models import Item
|
2017-07-28 15:42:58 +02:00
|
|
|
from ..core.models import Projector
|
2016-09-18 22:14:24 +02:00
|
|
|
from ..mediafiles.models import Mediafile
|
|
|
|
from ..utils.models import RESTModelMixin
|
|
|
|
from .access_permissions import TopicAccessPermissions
|
|
|
|
|
|
|
|
|
2016-09-18 16:00:31 +02:00
|
|
|
class TopicManager(models.Manager):
|
2016-09-30 20:42:58 +02:00
|
|
|
"""
|
|
|
|
Customized model manager to support our get_full_queryset method.
|
|
|
|
"""
|
|
|
|
def get_full_queryset(self):
|
|
|
|
"""
|
|
|
|
Returns the normal queryset with all topics. In the background all
|
|
|
|
attachments and the related agenda item are prefetched from the
|
|
|
|
database.
|
|
|
|
"""
|
|
|
|
return self.get_queryset().prefetch_related('attachments', 'agenda_items')
|
2016-09-18 16:00:31 +02:00
|
|
|
|
|
|
|
|
2016-09-18 22:14:24 +02:00
|
|
|
class Topic(RESTModelMixin, models.Model):
|
|
|
|
"""
|
|
|
|
Model for slides with custom content. Used to be called custom slide.
|
|
|
|
"""
|
|
|
|
access_permissions = TopicAccessPermissions()
|
2016-09-30 20:42:58 +02:00
|
|
|
|
2016-09-18 16:00:31 +02:00
|
|
|
objects = TopicManager()
|
2016-09-18 22:14:24 +02:00
|
|
|
|
|
|
|
title = models.CharField(max_length=256)
|
|
|
|
text = models.TextField(blank=True)
|
|
|
|
attachments = models.ManyToManyField(Mediafile, blank=True)
|
|
|
|
|
2016-09-30 20:42:58 +02:00
|
|
|
# In theory there could be one then more agenda_item. But we support only
|
|
|
|
# one. See the property agenda_item.
|
2016-09-18 16:00:31 +02:00
|
|
|
agenda_items = GenericRelation(Item, related_name='topics')
|
|
|
|
|
2016-09-18 22:14:24 +02:00
|
|
|
class Meta:
|
|
|
|
default_permissions = ()
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.title
|
|
|
|
|
2017-07-28 15:42:58 +02:00
|
|
|
def delete(self, skip_autoupdate=False, *args, **kwargs):
|
|
|
|
"""
|
|
|
|
Customized method to delete a topic. Ensures that a respective
|
|
|
|
topic projector element is disabled.
|
|
|
|
"""
|
|
|
|
Projector.remove_any(
|
|
|
|
skip_autoupdate=skip_autoupdate,
|
|
|
|
name='topics/topic',
|
|
|
|
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
|
|
|
|
2017-08-03 15:49:14 +02:00
|
|
|
"""
|
|
|
|
Container for runtime information for agenda app (on create or update of this instance).
|
|
|
|
"""
|
2018-08-22 22:00:08 +02:00
|
|
|
agenda_item_update_information: Dict[str, Any] = {}
|
2017-08-03 15:49:14 +02:00
|
|
|
|
2016-09-18 22:14:24 +02:00
|
|
|
@property
|
|
|
|
def agenda_item(self):
|
|
|
|
"""
|
|
|
|
Returns the related agenda item.
|
|
|
|
"""
|
2016-09-30 20:42:58 +02:00
|
|
|
# We support only one agenda item so just return the first element of
|
|
|
|
# the queryset.
|
2016-09-18 16:00:31 +02:00
|
|
|
return self.agenda_items.all()[0]
|
2016-09-18 22:14:24 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def agenda_item_id(self):
|
|
|
|
"""
|
|
|
|
Returns the id of the agenda item object related to this object.
|
|
|
|
"""
|
|
|
|
return self.agenda_item.pk
|
|
|
|
|
|
|
|
def get_agenda_title(self):
|
|
|
|
return self.title
|
|
|
|
|
|
|
|
def get_agenda_list_view_title(self):
|
|
|
|
return self.title
|