2018-11-04 14:02:30 +01:00
|
|
|
from asgiref.sync import async_to_sync
|
2015-09-07 16:46:04 +02:00
|
|
|
from django.conf import settings
|
2018-11-04 14:02:30 +01:00
|
|
|
from django.db import models, transaction
|
2016-10-21 11:05:24 +02:00
|
|
|
from django.utils.timezone import now
|
2015-02-18 01:45:39 +01:00
|
|
|
from jsonfield import JSONField
|
2014-01-28 08:32:26 +01:00
|
|
|
|
2019-03-06 14:53:24 +01:00
|
|
|
from ..utils.autoupdate import Element
|
|
|
|
from ..utils.cache import element_cache, get_element_id
|
2019-12-03 08:25:48 +01:00
|
|
|
from ..utils.locking import locking
|
2019-03-26 15:42:43 +01:00
|
|
|
from ..utils.models import SET_NULL_AND_AUTOUPDATE, RESTModelMixin
|
2016-02-11 22:58:32 +01:00
|
|
|
from .access_permissions import (
|
|
|
|
ConfigAccessPermissions,
|
2016-10-21 11:05:24 +02:00
|
|
|
CountdownAccessPermissions,
|
2019-03-26 14:57:04 +01:00
|
|
|
ProjectionDefaultAccessPermissions,
|
2016-02-11 22:58:32 +01:00
|
|
|
ProjectorAccessPermissions,
|
2016-10-21 11:05:24 +02:00
|
|
|
ProjectorMessageAccessPermissions,
|
2016-02-11 22:58:32 +01:00
|
|
|
TagAccessPermissions,
|
|
|
|
)
|
2014-10-11 14:34:49 +02:00
|
|
|
|
2014-01-28 08:32:26 +01:00
|
|
|
|
2016-10-01 01:30:55 +02:00
|
|
|
class ProjectorManager(models.Manager):
|
|
|
|
"""
|
|
|
|
Customized model manager to support our get_full_queryset method.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2016-10-01 01:30:55 +02:00
|
|
|
def get_full_queryset(self):
|
|
|
|
"""
|
|
|
|
Returns the normal queryset with all projectors. In the background
|
|
|
|
projector defaults are prefetched from the database.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
return self.get_queryset().prefetch_related("projectiondefaults")
|
2016-10-01 01:30:55 +02:00
|
|
|
|
|
|
|
|
2015-02-18 01:45:39 +01:00
|
|
|
class Projector(RESTModelMixin, models.Model):
|
2014-01-28 08:32:26 +01:00
|
|
|
"""
|
2016-10-05 18:25:50 +02:00
|
|
|
Model for all projectors.
|
2015-02-18 01:45:39 +01:00
|
|
|
|
2019-01-18 19:11:22 +01:00
|
|
|
The elements field contains a list. Every element must have at least the
|
|
|
|
property "name".
|
2015-09-06 13:28:25 +02:00
|
|
|
|
|
|
|
Example:
|
2019-01-18 19:11:22 +01:00
|
|
|
[
|
|
|
|
{
|
2016-09-18 22:14:24 +02:00
|
|
|
"name": "topics/topic",
|
2019-01-18 19:11:22 +01:00
|
|
|
"id": 1,
|
2015-09-14 23:16:31 +02:00
|
|
|
},
|
2019-01-18 19:11:22 +01:00
|
|
|
{
|
2015-09-06 13:28:25 +02:00
|
|
|
"name": "core/countdown",
|
2019-01-18 19:11:22 +01:00
|
|
|
"id": 1,
|
2015-09-14 23:16:31 +02:00
|
|
|
},
|
2019-01-18 19:11:22 +01:00
|
|
|
{
|
2015-09-06 13:28:25 +02:00
|
|
|
"name": "core/clock",
|
2019-01-18 19:11:22 +01:00
|
|
|
"id": 1,
|
|
|
|
},
|
|
|
|
]
|
2015-09-06 13:28:25 +02:00
|
|
|
|
2015-02-18 01:45:39 +01:00
|
|
|
If the config field is empty or invalid the projector shows a default
|
2015-09-06 13:28:25 +02:00
|
|
|
slide.
|
|
|
|
|
2015-09-14 23:16:31 +02:00
|
|
|
There are two additional fields to control the behavior of the projector
|
|
|
|
view itself: scale and scroll.
|
|
|
|
|
2015-09-06 13:28:25 +02:00
|
|
|
The projector can be controlled using the REST API with POST requests
|
|
|
|
on e. g. the URL /rest/core/projector/1/activate_elements/.
|
2015-02-18 01:45:39 +01:00
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2016-02-11 22:58:32 +01:00
|
|
|
access_permissions = ProjectorAccessPermissions()
|
|
|
|
|
2016-10-01 01:30:55 +02:00
|
|
|
objects = ProjectorManager()
|
|
|
|
|
2019-01-10 15:06:10 +01:00
|
|
|
elements = JSONField(default=list)
|
|
|
|
elements_preview = JSONField(default=list)
|
|
|
|
elements_history = JSONField(default=list)
|
2014-01-28 08:32:26 +01:00
|
|
|
|
2015-09-14 23:16:31 +02:00
|
|
|
scale = models.IntegerField(default=0)
|
|
|
|
scroll = models.IntegerField(default=0)
|
|
|
|
|
2016-08-25 16:40:34 +02:00
|
|
|
width = models.PositiveIntegerField(default=1024)
|
2019-11-22 12:25:12 +01:00
|
|
|
aspect_ratio_numerator = models.PositiveIntegerField(default=16)
|
|
|
|
aspect_ratio_denominator = models.PositiveIntegerField(default=9)
|
2016-08-25 16:40:34 +02:00
|
|
|
|
2019-07-10 12:57:48 +02:00
|
|
|
color = models.CharField(max_length=7, default="#000000")
|
2019-02-21 17:04:59 +01:00
|
|
|
background_color = models.CharField(max_length=7, default="#ffffff")
|
|
|
|
header_background_color = models.CharField(max_length=7, default="#317796")
|
|
|
|
header_font_color = models.CharField(max_length=7, default="#f5f5f5")
|
|
|
|
header_h1_color = models.CharField(max_length=7, default="#317796")
|
2019-05-17 14:10:33 +02:00
|
|
|
chyron_background_color = models.CharField(max_length=7, default="#317796")
|
|
|
|
chyron_font_color = models.CharField(max_length=7, default="#ffffff")
|
2019-02-21 17:04:59 +01:00
|
|
|
show_header_footer = models.BooleanField(default=True)
|
|
|
|
show_title = models.BooleanField(default=True)
|
|
|
|
show_logo = models.BooleanField(default=True)
|
|
|
|
|
2019-04-09 16:13:40 +02:00
|
|
|
name = models.CharField(max_length=255, unique=True)
|
2016-09-12 11:05:34 +02:00
|
|
|
|
2019-01-31 12:31:53 +01:00
|
|
|
reference_projector = models.ForeignKey(
|
|
|
|
"self",
|
|
|
|
on_delete=SET_NULL_AND_AUTOUPDATE,
|
|
|
|
null=True,
|
|
|
|
blank=True,
|
|
|
|
related_name="references",
|
|
|
|
)
|
|
|
|
|
2014-01-28 08:32:26 +01:00
|
|
|
class Meta:
|
|
|
|
"""
|
2015-02-18 01:45:39 +01:00
|
|
|
Contains general permissions that can not be placed in a specific app.
|
2014-01-28 08:32:26 +01:00
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2015-12-10 00:20:59 +01:00
|
|
|
default_permissions = ()
|
2014-01-28 08:32:26 +01:00
|
|
|
permissions = (
|
2019-01-06 16:22:33 +01:00
|
|
|
("can_see_projector", "Can see the projector"),
|
|
|
|
("can_manage_projector", "Can manage the projector"),
|
|
|
|
("can_see_frontpage", "Can see the front page"),
|
|
|
|
)
|
2015-02-18 01:45:39 +01:00
|
|
|
|
|
|
|
|
2016-09-12 11:05:34 +02:00
|
|
|
class ProjectionDefault(RESTModelMixin, models.Model):
|
|
|
|
"""
|
2016-09-29 15:32:58 +02:00
|
|
|
Model for the projection defaults like motions, agenda, list of
|
|
|
|
speakers and thelike. The name is the technical name like 'topics' or
|
|
|
|
'motions'. For apps the name should be the app name to get keep the
|
|
|
|
ProjectionDefault for apps generic. But it is possible to give some
|
|
|
|
special name like 'list_of_speakers'. The display_name is the shown
|
|
|
|
name on the front end for the user.
|
2016-09-12 11:05:34 +02:00
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2019-03-26 14:57:04 +01:00
|
|
|
access_permissions = ProjectionDefaultAccessPermissions()
|
|
|
|
|
2016-09-12 11:05:34 +02:00
|
|
|
name = models.CharField(max_length=256)
|
|
|
|
|
|
|
|
display_name = models.CharField(max_length=256)
|
|
|
|
|
|
|
|
projector = models.ForeignKey(
|
2019-01-19 14:02:13 +01:00
|
|
|
Projector, on_delete=models.PROTECT, related_name="projectiondefaults"
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2016-09-12 11:05:34 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
default_permissions = ()
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.display_name
|
|
|
|
|
|
|
|
|
2015-06-16 10:37:23 +02:00
|
|
|
class Tag(RESTModelMixin, models.Model):
|
2014-12-26 13:45:13 +01:00
|
|
|
"""
|
2015-02-18 01:45:39 +01:00
|
|
|
Model for tags. This tags can be used for other models like agenda items,
|
|
|
|
motions or assignments.
|
2014-12-26 13:45:13 +01:00
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2016-02-11 22:58:32 +01:00
|
|
|
access_permissions = TagAccessPermissions()
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
name = models.CharField(max_length=255, unique=True)
|
2014-12-26 13:45:13 +01:00
|
|
|
|
|
|
|
class Meta:
|
2019-01-06 16:22:33 +01:00
|
|
|
ordering = ("name",)
|
2015-12-10 00:20:59 +01:00
|
|
|
default_permissions = ()
|
2019-01-06 16:22:33 +01:00
|
|
|
permissions = (("can_manage_tags", "Can manage tags"),)
|
2014-12-26 13:45:13 +01:00
|
|
|
|
2015-01-05 17:14:29 +01:00
|
|
|
def __str__(self):
|
2014-12-26 13:45:13 +01:00
|
|
|
return self.name
|
2015-06-29 12:08:15 +02:00
|
|
|
|
|
|
|
|
2016-02-11 22:58:32 +01:00
|
|
|
class ConfigStore(RESTModelMixin, models.Model):
|
2015-06-29 12:08:15 +02:00
|
|
|
"""
|
|
|
|
A model class to store all config variables in the database.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2016-02-11 22:58:32 +01:00
|
|
|
access_permissions = ConfigAccessPermissions()
|
2015-06-29 12:08:15 +02:00
|
|
|
|
|
|
|
key = models.CharField(max_length=255, unique=True, db_index=True)
|
|
|
|
"""A string, the key of the config variable."""
|
|
|
|
|
|
|
|
value = JSONField()
|
|
|
|
"""The value of the config variable. """
|
|
|
|
|
|
|
|
class Meta:
|
2015-12-10 00:20:59 +01:00
|
|
|
default_permissions = ()
|
|
|
|
permissions = (
|
2019-01-06 16:22:33 +01:00
|
|
|
("can_manage_config", "Can manage configuration"),
|
|
|
|
("can_manage_logos_and_fonts", "Can manage logos and fonts"),
|
|
|
|
)
|
2015-09-07 16:46:04 +02:00
|
|
|
|
2016-02-11 22:58:32 +01:00
|
|
|
@classmethod
|
|
|
|
def get_collection_string(cls):
|
2019-01-06 16:22:33 +01:00
|
|
|
return "core/config"
|
2016-02-11 22:58:32 +01:00
|
|
|
|
2015-09-07 16:46:04 +02:00
|
|
|
|
2016-10-21 11:05:24 +02:00
|
|
|
class ProjectorMessage(RESTModelMixin, models.Model):
|
|
|
|
"""
|
|
|
|
Model for ProjectorMessages.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2016-10-21 11:05:24 +02:00
|
|
|
access_permissions = ProjectorMessageAccessPermissions()
|
|
|
|
|
|
|
|
message = models.TextField(blank=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
default_permissions = ()
|
|
|
|
|
|
|
|
|
|
|
|
class Countdown(RESTModelMixin, models.Model):
|
|
|
|
"""
|
|
|
|
Model for countdowns.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2016-10-21 11:05:24 +02:00
|
|
|
access_permissions = CountdownAccessPermissions()
|
|
|
|
|
2019-03-01 12:10:49 +01:00
|
|
|
title = models.CharField(max_length=256, unique=True)
|
2019-02-27 16:08:22 +01:00
|
|
|
|
2016-10-21 11:05:24 +02:00
|
|
|
description = models.CharField(max_length=256, blank=True)
|
|
|
|
|
|
|
|
running = models.BooleanField(default=False)
|
|
|
|
|
|
|
|
default_time = models.PositiveIntegerField(default=60)
|
|
|
|
|
|
|
|
countdown_time = models.FloatField(default=60)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
default_permissions = ()
|
|
|
|
|
2017-11-03 09:32:43 +01:00
|
|
|
def control(self, action, skip_autoupdate=False):
|
2019-01-06 16:22:33 +01:00
|
|
|
if action not in ("start", "stop", "reset"):
|
|
|
|
raise ValueError(
|
2019-01-12 23:01:42 +01:00
|
|
|
f"Action must be 'start', 'stop' or 'reset', not {action}."
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2016-10-21 11:05:24 +02:00
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
if action == "start":
|
2016-10-21 11:05:24 +02:00
|
|
|
self.running = True
|
|
|
|
self.countdown_time = now().timestamp() + self.default_time
|
2019-01-06 16:22:33 +01:00
|
|
|
elif action == "stop" and self.running:
|
2016-10-21 11:05:24 +02:00
|
|
|
self.running = False
|
|
|
|
self.countdown_time = self.countdown_time - now().timestamp()
|
|
|
|
else: # reset
|
|
|
|
self.running = False
|
|
|
|
self.countdown_time = self.default_time
|
2017-11-03 09:32:43 +01:00
|
|
|
self.save(skip_autoupdate=skip_autoupdate)
|
2018-11-04 14:02:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
class HistoryData(models.Model):
|
|
|
|
"""
|
|
|
|
Django model to save the history of OpenSlides.
|
|
|
|
|
|
|
|
This is not a RESTModel. It is not cachable and can only be reached by a
|
|
|
|
special viewset.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2018-11-04 14:02:30 +01:00
|
|
|
full_data = JSONField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
default_permissions = ()
|
|
|
|
|
|
|
|
|
|
|
|
class HistoryManager(models.Manager):
|
|
|
|
"""
|
|
|
|
Customized model manager for the history model.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2018-11-04 14:02:30 +01:00
|
|
|
def add_elements(self, elements):
|
|
|
|
"""
|
|
|
|
Method to add elements to the history. This does not trigger autoupdate.
|
|
|
|
"""
|
|
|
|
with transaction.atomic():
|
|
|
|
instances = []
|
2019-01-12 20:49:28 +01:00
|
|
|
history_time = now()
|
2018-11-04 14:02:30 +01:00
|
|
|
for element in elements:
|
2019-05-30 12:50:28 +02:00
|
|
|
if element.get("disable_history"):
|
|
|
|
# Do not update history if history is disabled.
|
2018-11-04 14:02:30 +01:00
|
|
|
continue
|
|
|
|
# HistoryData is not a root rest element so there is no autoupdate and not history saving here.
|
2019-01-06 16:22:33 +01:00
|
|
|
data = HistoryData.objects.create(full_data=element["full_data"])
|
2018-11-04 14:02:30 +01:00
|
|
|
instance = self.model(
|
2019-01-06 16:22:33 +01:00
|
|
|
element_id=get_element_id(
|
|
|
|
element["collection_string"], element["id"]
|
|
|
|
),
|
2019-01-12 20:49:28 +01:00
|
|
|
now=history_time,
|
2019-01-19 15:49:46 +01:00
|
|
|
information=element.get("information", []),
|
2019-01-19 14:02:13 +01:00
|
|
|
user_id=element.get("user_id"),
|
2018-11-04 14:02:30 +01:00
|
|
|
full_data=data,
|
|
|
|
)
|
2019-05-30 12:50:28 +02:00
|
|
|
instance.save()
|
2018-11-04 14:02:30 +01:00
|
|
|
instances.append(instance)
|
|
|
|
return instances
|
|
|
|
|
|
|
|
def build_history(self):
|
|
|
|
"""
|
|
|
|
Method to add all cachables to the history.
|
|
|
|
"""
|
2019-12-03 08:25:48 +01:00
|
|
|
async_to_sync(self.async_build_history)()
|
|
|
|
|
|
|
|
async def async_build_history(self):
|
|
|
|
lock_name = "build_cache"
|
|
|
|
if await locking.set(lock_name):
|
|
|
|
try:
|
|
|
|
if self.all().count() == 0:
|
|
|
|
elements = []
|
|
|
|
all_full_data = await element_cache.get_all_data_list()
|
|
|
|
for collection_string, data in all_full_data.items():
|
|
|
|
for full_data in data:
|
|
|
|
elements.append(
|
|
|
|
Element(
|
|
|
|
id=full_data["id"],
|
|
|
|
collection_string=collection_string,
|
|
|
|
full_data=full_data,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.add_elements(elements)
|
|
|
|
finally:
|
|
|
|
await locking.delete(lock_name)
|
2018-11-04 14:02:30 +01:00
|
|
|
|
|
|
|
|
2019-05-30 12:50:28 +02:00
|
|
|
class History(models.Model):
|
2018-11-04 14:02:30 +01:00
|
|
|
"""
|
|
|
|
Django model to save the history of OpenSlides.
|
|
|
|
|
|
|
|
This model itself is not part of the history. This means that if you
|
|
|
|
delete a user you may lose the information of the user field here.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2018-11-04 14:02:30 +01:00
|
|
|
objects = HistoryManager()
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
element_id = models.CharField(max_length=255)
|
2018-11-04 14:02:30 +01:00
|
|
|
|
2019-01-12 20:49:28 +01:00
|
|
|
now = models.DateTimeField()
|
2018-11-04 14:02:30 +01:00
|
|
|
|
2019-01-19 15:49:46 +01:00
|
|
|
information = JSONField()
|
|
|
|
|
2018-11-04 14:02:30 +01:00
|
|
|
user = models.ForeignKey(
|
2019-05-30 12:50:28 +02:00
|
|
|
settings.AUTH_USER_MODEL, null=True, on_delete=models.SET_NULL
|
2018-11-04 14:02:30 +01:00
|
|
|
)
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
full_data = models.OneToOneField(HistoryData, on_delete=models.CASCADE)
|
|
|
|
|
2018-11-04 14:02:30 +01:00
|
|
|
class Meta:
|
|
|
|
default_permissions = ()
|
2019-02-19 20:24:48 +01:00
|
|
|
permissions = (("can_see_history", "Can see history"),)
|