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-01-17 14:25:05 +01:00
|
|
|
from openslides.utils.models import AbsoluteUrlMixin
|
2015-02-18 01:45:39 +01:00
|
|
|
from openslides.utils.projector import ProjectorElement
|
2015-01-17 14:25:05 +01:00
|
|
|
from openslides.utils.rest_api import RESTModelMixin
|
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
|
|
|
|
def projector_elements(self):
|
|
|
|
"""
|
|
|
|
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:
|
|
|
|
name = config_entry.get('name')
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
class CustomSlide(RESTModelMixin, AbsoluteUrlMixin, models.Model):
|
|
|
|
"""
|
|
|
|
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-01-17 14:25:05 +01:00
|
|
|
class Tag(RESTModelMixin, AbsoluteUrlMixin, 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
|