2013-08-04 12:59:11 +02:00
|
|
|
from django.core.urlresolvers import reverse
|
2012-04-16 16:35:30 +02:00
|
|
|
|
2013-08-04 12:59:11 +02:00
|
|
|
from openslides.utils.utils import int_or_none
|
2012-07-07 14:01:40 +02:00
|
|
|
|
2012-04-14 12:52:56 +02:00
|
|
|
|
2013-08-04 12:59:11 +02:00
|
|
|
class SlideMixin(object):
|
|
|
|
"""
|
|
|
|
A Mixin for a Django-Model, for making the model a slide.
|
|
|
|
"""
|
|
|
|
|
|
|
|
slide_callback_name = None
|
|
|
|
"""
|
|
|
|
Name of the callback to render the model as slide.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def get_absolute_url(self, link='projector'):
|
|
|
|
"""
|
2013-10-03 21:49:51 +02:00
|
|
|
Return the url to activate the slide, if link == 'projector'.
|
2013-08-04 12:59:11 +02:00
|
|
|
"""
|
|
|
|
if link in ('projector', 'projector_preview'):
|
2013-10-03 21:49:51 +02:00
|
|
|
url_name = {'projector': 'projector_activate_slide',
|
|
|
|
'projector_preview': 'projector_preview'}[link]
|
|
|
|
value = '%s?pk=%d' % (
|
2013-08-04 12:59:11 +02:00
|
|
|
reverse(url_name,
|
2013-10-03 21:49:51 +02:00
|
|
|
args=[self.slide_callback_name]),
|
2013-08-04 12:59:11 +02:00
|
|
|
self.pk)
|
2013-10-03 21:49:51 +02:00
|
|
|
else:
|
|
|
|
value = super(SlideMixin, self).get_absolute_url(link)
|
|
|
|
return value
|
2013-08-04 12:59:11 +02:00
|
|
|
|
|
|
|
def is_active_slide(self):
|
|
|
|
"""
|
|
|
|
Return True, if the the slide is the active slide.
|
|
|
|
"""
|
|
|
|
from openslides.projector.api import get_active_slide
|
|
|
|
active_slide = get_active_slide()
|
2013-09-25 10:01:01 +02:00
|
|
|
slide_pk = int_or_none(active_slide.get('pk', None))
|
2013-10-03 21:49:51 +02:00
|
|
|
return (active_slide['callback'] == self.slide_callback_name and
|
2013-09-25 10:01:01 +02:00
|
|
|
self.pk == slide_pk)
|
2013-08-04 12:59:11 +02:00
|
|
|
|
2013-10-03 21:49:51 +02:00
|
|
|
def get_slide_context(self, **context):
|
|
|
|
"""
|
|
|
|
Returns the context for the template which renders the slide.
|
|
|
|
"""
|
|
|
|
slide_name = self._meta.object_name.lower()
|
|
|
|
context.update({'slide': self,
|
|
|
|
slide_name: self})
|
|
|
|
return context
|