2015-09-07 16:46:04 +02:00
|
|
|
from django.conf import settings
|
2015-10-24 19:02:43 +02:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2016-05-29 08:29:14 +02:00
|
|
|
from django.contrib.sessions.models import Session as DjangoSession
|
2014-01-28 08:32:26 +01:00
|
|
|
from django.db import models
|
2015-02-18 01:45:39 +01:00
|
|
|
from jsonfield import JSONField
|
2014-01-28 08:32:26 +01:00
|
|
|
|
2016-01-09 10:18:51 +01:00
|
|
|
from openslides.mediafiles.models import Mediafile
|
2015-06-29 12:08:15 +02:00
|
|
|
from openslides.utils.models import RESTModelMixin
|
2015-02-18 01:45:39 +01:00
|
|
|
from openslides.utils.projector import ProjectorElement
|
2014-01-28 08:32:26 +01:00
|
|
|
|
2016-02-11 22:58:32 +01:00
|
|
|
from .access_permissions import (
|
|
|
|
ChatMessageAccessPermissions,
|
|
|
|
ConfigAccessPermissions,
|
|
|
|
CustomSlideAccessPermissions,
|
|
|
|
ProjectorAccessPermissions,
|
|
|
|
TagAccessPermissions,
|
|
|
|
)
|
2015-02-18 01:45:39 +01:00
|
|
|
from .exceptions import ProjectorException
|
2014-10-11 14:34:49 +02:00
|
|
|
|
2014-01-28 08:32:26 +01:00
|
|
|
|
2015-02-18 01:45:39 +01:00
|
|
|
class Projector(RESTModelMixin, models.Model):
|
2014-01-28 08:32:26 +01:00
|
|
|
"""
|
2015-02-18 01:45:39 +01:00
|
|
|
Model for all projectors. At the moment we support only one projector,
|
|
|
|
the default projector (pk=1).
|
|
|
|
|
2015-09-06 13:28:25 +02:00
|
|
|
The config field contains a dictionary which uses UUIDs as keys. Every
|
|
|
|
element must have at least the property "name". The property "stable"
|
|
|
|
is to set whether this element should disappear on prune or clear
|
|
|
|
requests.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
{
|
|
|
|
"881d875cf01741718ca926279ac9c99c": {
|
|
|
|
"name": "core/customslide",
|
2015-09-14 23:16:31 +02:00
|
|
|
"id": 1
|
|
|
|
},
|
2015-09-06 13:28:25 +02:00
|
|
|
"191c0878cdc04abfbd64f3177a21891a": {
|
|
|
|
"name": "core/countdown",
|
|
|
|
"stable": true,
|
2015-09-14 23:16:31 +02:00
|
|
|
"status": "stop",
|
2015-09-06 13:28:25 +02:00
|
|
|
"countdown_time": 20,
|
2015-09-14 23:16:31 +02:00
|
|
|
"visable": true,
|
|
|
|
"default": 42
|
|
|
|
},
|
2015-09-06 13:28:25 +02:00
|
|
|
"db670aa8d3ed4aabb348e752c75aeaaf": {
|
|
|
|
"name": "core/clock",
|
2015-09-14 23:16:31 +02:00
|
|
|
"stable": true
|
|
|
|
}
|
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
|
|
|
"""
|
2016-02-11 22:58:32 +01:00
|
|
|
access_permissions = ProjectorAccessPermissions()
|
|
|
|
|
2015-02-18 01:45:39 +01:00
|
|
|
config = JSONField()
|
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)
|
|
|
|
|
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
|
|
|
"""
|
2015-12-10 00:20:59 +01:00
|
|
|
default_permissions = ()
|
2014-01-28 08:32:26 +01:00
|
|
|
permissions = (
|
2016-01-27 13:41:19 +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
|
|
|
|
|
|
|
@property
|
2015-06-17 09:45:00 +02:00
|
|
|
def elements(self):
|
2015-02-18 01:45:39 +01:00
|
|
|
"""
|
2016-02-27 20:25:06 +01:00
|
|
|
Retrieve all projector elements given in the config field. For
|
|
|
|
every element the method check_and_update_data() is called and its
|
2015-09-06 13:28:25 +02:00
|
|
|
result is also used.
|
2015-02-18 01:45:39 +01:00
|
|
|
"""
|
2015-09-06 13:28:25 +02:00
|
|
|
# Get all elements from all apps.
|
2015-02-18 01:45:39 +01:00
|
|
|
elements = {}
|
|
|
|
for element in ProjectorElement.get_all():
|
|
|
|
elements[element.name] = element
|
2015-09-06 13:28:25 +02:00
|
|
|
|
|
|
|
# Parse result
|
|
|
|
result = {}
|
|
|
|
for key, value in self.config.items():
|
2015-09-08 14:14:11 +02:00
|
|
|
# Use a copy here not to change the origin value in the config field.
|
|
|
|
result[key] = value.copy()
|
2015-09-05 23:32:10 +02:00
|
|
|
result[key]['uuid'] = key
|
2015-09-06 13:28:25 +02:00
|
|
|
element = elements.get(value['name'])
|
2015-02-18 01:45:39 +01:00
|
|
|
if element is None:
|
2016-01-09 13:32:56 +01:00
|
|
|
result[key]['error'] = 'Projector element does not exist.'
|
2015-02-18 01:45:39 +01:00
|
|
|
else:
|
|
|
|
try:
|
2016-02-27 20:25:06 +01:00
|
|
|
result[key].update(element.check_and_update_data(
|
2015-02-18 01:45:39 +01:00
|
|
|
projector_object=self,
|
2015-09-06 13:28:25 +02:00
|
|
|
config_entry=value))
|
2015-02-18 01:45:39 +01:00
|
|
|
except ProjectorException as e:
|
2015-09-06 13:28:25 +02:00
|
|
|
result[key]['error'] = str(e)
|
|
|
|
return result
|
2015-02-18 01:45:39 +01:00
|
|
|
|
2015-06-12 21:08:57 +02:00
|
|
|
@classmethod
|
|
|
|
def get_all_requirements(cls):
|
|
|
|
"""
|
|
|
|
Generator which returns all ProjectorRequirement instances of all
|
|
|
|
active projector elements.
|
|
|
|
"""
|
2015-09-06 13:28:25 +02:00
|
|
|
# Get all elements from all apps.
|
2015-06-12 21:08:57 +02:00
|
|
|
elements = {}
|
|
|
|
for element in ProjectorElement.get_all():
|
|
|
|
elements[element.name] = element
|
2015-09-06 13:28:25 +02:00
|
|
|
|
|
|
|
# Generator
|
2015-06-12 21:08:57 +02:00
|
|
|
for projector in cls.objects.all():
|
2015-09-06 13:28:25 +02:00
|
|
|
for key, value in projector.config.items():
|
|
|
|
element = elements.get(value['name'])
|
2015-06-12 21:08:57 +02:00
|
|
|
if element is not None:
|
2015-09-06 13:28:25 +02:00
|
|
|
for requirement in element.get_requirements(value):
|
2015-06-12 21:08:57 +02:00
|
|
|
yield requirement
|
|
|
|
|
2015-02-18 01:45:39 +01:00
|
|
|
|
2015-06-16 10:37:23 +02:00
|
|
|
class CustomSlide(RESTModelMixin, models.Model):
|
2015-02-18 01:45:39 +01:00
|
|
|
"""
|
|
|
|
Model for slides with custom content.
|
|
|
|
"""
|
2016-02-11 22:58:32 +01:00
|
|
|
access_permissions = CustomSlideAccessPermissions()
|
|
|
|
|
2015-02-18 01:45:39 +01:00
|
|
|
title = models.CharField(
|
|
|
|
max_length=256)
|
|
|
|
text = models.TextField(
|
|
|
|
blank=True)
|
|
|
|
weight = models.IntegerField(
|
|
|
|
default=0)
|
2016-01-09 10:18:51 +01:00
|
|
|
attachments = models.ManyToManyField(
|
|
|
|
Mediafile,
|
|
|
|
blank=True)
|
2015-02-18 01:45:39 +01:00
|
|
|
|
|
|
|
class Meta:
|
2015-12-10 00:20:59 +01:00
|
|
|
default_permissions = ()
|
2015-02-18 01:45:39 +01:00
|
|
|
ordering = ('weight', 'title', )
|
2014-01-28 08:32:26 +01:00
|
|
|
|
2014-08-16 09:25:18 +02:00
|
|
|
def __str__(self):
|
2014-01-28 08:32:26 +01:00
|
|
|
return self.title
|
|
|
|
|
2015-10-24 19:02:43 +02:00
|
|
|
@property
|
|
|
|
def agenda_item(self):
|
|
|
|
"""
|
|
|
|
Returns the related agenda item.
|
|
|
|
"""
|
|
|
|
# TODO: Move the agenda app in the core app to fix circular dependencies
|
|
|
|
from openslides.agenda.models import Item
|
|
|
|
content_type = ContentType.objects.get_for_model(self)
|
|
|
|
return Item.objects.get(object_id=self.pk, content_type=content_type)
|
|
|
|
|
|
|
|
@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
|
|
|
|
|
2016-01-25 21:22:22 +01:00
|
|
|
def get_agenda_list_view_title(self):
|
|
|
|
return self.title
|
|
|
|
|
2016-01-03 15:33:51 +01:00
|
|
|
def get_search_index_string(self):
|
|
|
|
"""
|
|
|
|
Returns a string that can be indexed for the search.
|
|
|
|
"""
|
|
|
|
return " ".join((
|
|
|
|
self.title,
|
|
|
|
self.text))
|
|
|
|
|
2014-12-26 13:45:13 +01:00
|
|
|
|
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
|
|
|
"""
|
2016-02-11 22:58:32 +01:00
|
|
|
access_permissions = TagAccessPermissions()
|
|
|
|
|
2015-02-18 01:45:39 +01:00
|
|
|
name = models.CharField(
|
|
|
|
max_length=255,
|
|
|
|
unique=True)
|
2014-12-26 13:45:13 +01:00
|
|
|
|
|
|
|
class Meta:
|
2015-02-18 01:45:39 +01:00
|
|
|
ordering = ('name',)
|
2015-12-10 00:20:59 +01:00
|
|
|
default_permissions = ()
|
2014-12-26 13:45:13 +01:00
|
|
|
permissions = (
|
2016-01-27 13:41:19 +01:00
|
|
|
('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.
|
|
|
|
"""
|
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 = (
|
2016-01-27 13:41:19 +01:00
|
|
|
('can_manage_config', 'Can manage configuration'),)
|
2015-09-07 16:46:04 +02:00
|
|
|
|
2016-02-11 22:58:32 +01:00
|
|
|
@classmethod
|
|
|
|
def get_collection_string(cls):
|
|
|
|
return 'core/config'
|
|
|
|
|
|
|
|
def get_rest_pk(self):
|
2016-01-09 19:36:41 +01:00
|
|
|
"""
|
2016-02-11 22:58:32 +01:00
|
|
|
Returns the primary key used in the REST API.
|
2016-01-09 19:36:41 +01:00
|
|
|
"""
|
2016-02-11 22:58:32 +01:00
|
|
|
return self.key
|
2016-01-09 19:36:41 +01:00
|
|
|
|
2015-09-07 16:46:04 +02:00
|
|
|
|
|
|
|
class ChatMessage(RESTModelMixin, models.Model):
|
|
|
|
"""
|
|
|
|
Model for chat messages.
|
|
|
|
|
|
|
|
At the moment we only have one global chat room for managers.
|
|
|
|
"""
|
2016-02-11 22:58:32 +01:00
|
|
|
access_permissions = ChatMessageAccessPermissions()
|
|
|
|
|
2016-01-09 13:32:56 +01:00
|
|
|
message = models.TextField()
|
2015-09-07 16:46:04 +02:00
|
|
|
|
|
|
|
timestamp = models.DateTimeField(auto_now_add=True)
|
|
|
|
|
|
|
|
user = models.ForeignKey(
|
|
|
|
settings.AUTH_USER_MODEL,
|
2016-01-09 13:32:56 +01:00
|
|
|
on_delete=models.CASCADE)
|
2015-09-07 16:46:04 +02:00
|
|
|
|
|
|
|
class Meta:
|
2015-12-10 00:20:59 +01:00
|
|
|
default_permissions = ()
|
2015-09-07 16:46:04 +02:00
|
|
|
permissions = (
|
2016-01-27 13:41:19 +01:00
|
|
|
('can_use_chat', 'Can use the chat'),)
|
2015-09-07 16:46:04 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return 'Message {}'.format(self.timestamp)
|
2016-05-29 08:29:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Session(DjangoSession):
|
|
|
|
"""
|
|
|
|
Model like the Django db session, which saves the user as ForeignKey instead
|
|
|
|
of an encoded value.
|
|
|
|
"""
|
|
|
|
user = models.ForeignKey(
|
|
|
|
settings.AUTH_USER_MODEL,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
null=True)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get_session_store_class(cls):
|
|
|
|
from .session_backend import SessionStore
|
|
|
|
return SessionStore
|