2014-01-28 08:32:26 +01:00
|
|
|
from django.db import models
|
2015-02-18 01:45:39 +01:00
|
|
|
from django.utils.translation import ugettext as _
|
2014-01-28 08:32:26 +01:00
|
|
|
from django.utils.translation import ugettext_lazy, ugettext_noop
|
2015-02-18 01:45:39 +01:00
|
|
|
from jsonfield import JSONField
|
2014-01-28 08:32:26 +01:00
|
|
|
|
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
|
|
|
|
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).
|
|
|
|
|
|
|
|
If the config field is empty or invalid the projector shows a default
|
|
|
|
slide. To activate a slide and extra projector elements, save valid
|
|
|
|
JSON to the config field.
|
2014-01-28 08:32:26 +01:00
|
|
|
|
2015-02-18 01:45:39 +01:00
|
|
|
Example: [{"name": "core/customslide", "id": 2},
|
|
|
|
{"name": "core/countdown", "countdown_time": 20, "status": "stop"},
|
|
|
|
{"name": "core/clock", "stable": true}]
|
|
|
|
|
|
|
|
This can be done using the REST API with POST requests on e. g. the URL
|
|
|
|
/rest/core/projector/1/activate_projector_elements/. The data have to be
|
|
|
|
a list of dictionaries. Every dictionary must have at least the
|
|
|
|
property "name". The property "stable" is to set whether this element
|
|
|
|
should disappear on prune or clear requests.
|
|
|
|
"""
|
|
|
|
config = JSONField()
|
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
|
|
|
"""
|
|
|
|
permissions = (
|
|
|
|
('can_see_projector', ugettext_noop('Can see the projector')),
|
2015-02-18 01:45:39 +01:00
|
|
|
('can_manage_projector', ugettext_noop('Can manage the projector')),
|
2014-01-28 08:32:26 +01:00
|
|
|
('can_see_dashboard', ugettext_noop('Can see the dashboard')),
|
2015-02-18 01:45:39 +01:00
|
|
|
('can_use_chat', ugettext_noop('Can use the chat')))
|
|
|
|
|
|
|
|
@property
|
2015-06-17 09:45:00 +02:00
|
|
|
def elements(self):
|
2015-02-18 01:45:39 +01:00
|
|
|
"""
|
|
|
|
A generator to retrieve all projector elements given in the config
|
|
|
|
field. For every element the method get_data() is called and its
|
|
|
|
result returned.
|
|
|
|
"""
|
|
|
|
elements = {}
|
|
|
|
for element in ProjectorElement.get_all():
|
|
|
|
elements[element.name] = element
|
|
|
|
for config_entry in self.config:
|
2015-06-12 21:08:57 +02:00
|
|
|
name = config_entry['name']
|
2015-02-18 01:45:39 +01:00
|
|
|
element = elements.get(name)
|
|
|
|
data = {'name': name}
|
|
|
|
if element is None:
|
|
|
|
data['error'] = _('Projector element does not exist.')
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
data.update(element.get_data(
|
|
|
|
projector_object=self,
|
|
|
|
config_entry=config_entry))
|
|
|
|
except ProjectorException as e:
|
|
|
|
data['error'] = str(e)
|
|
|
|
yield data
|
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
elements = {}
|
|
|
|
for element in ProjectorElement.get_all():
|
|
|
|
elements[element.name] = element
|
|
|
|
for projector in cls.objects.all():
|
|
|
|
for config_entry in projector.config:
|
|
|
|
element = elements.get(config_entry['name'])
|
|
|
|
if element is not None:
|
|
|
|
for requirement in element.get_requirements(config_entry):
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
title = models.CharField(
|
|
|
|
verbose_name=ugettext_lazy('Title'),
|
|
|
|
max_length=256)
|
|
|
|
text = models.TextField(
|
|
|
|
verbose_name=ugettext_lazy('Text'),
|
|
|
|
blank=True)
|
|
|
|
weight = models.IntegerField(
|
|
|
|
verbose_name=ugettext_lazy('Weight'),
|
|
|
|
default=0)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
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
|
|
|
|
|
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
|
|
|
"""
|
2015-02-18 01:45:39 +01:00
|
|
|
name = models.CharField(
|
|
|
|
verbose_name=ugettext_lazy('Tag'),
|
|
|
|
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',)
|
2014-12-26 13:45:13 +01:00
|
|
|
permissions = (
|
|
|
|
('can_manage_tags', ugettext_noop('Can manage tags')), )
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
class ConfigStore(models.Model):
|
|
|
|
"""
|
|
|
|
A model class to store all config variables in the database.
|
|
|
|
"""
|
|
|
|
|
|
|
|
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:
|
|
|
|
permissions = (('can_manage_config', ugettext_noop('Can manage configuration')),)
|