OpenSlides/openslides/projector/api.py

46 lines
1.0 KiB
Python
Raw Normal View History

2012-02-15 12:04:11 +01:00
from system import config
2012-02-06 22:22:16 +01:00
from projector.models import SLIDE
2012-02-06 22:22:16 +01:00
def get_slide_from_sid(sid):
2012-02-09 01:46:58 +01:00
data = sid.split()
if len(data) == 2:
model = data[0]
id = data[1]
return SLIDE[model].objects.get(pk=id).slide()
if len(data) == 1:
try:
return SLIDE[data[0]]()
except KeyError:
return None
return None
2012-02-06 22:22:16 +01:00
def get_active_slide(only_sid=False):
"""
2012-02-06 22:22:16 +01:00
Returns the active slide. If no slide is active, or it can not find an Item,
it raise an error
2012-02-06 22:22:16 +01:00
if only_sid is True, returns only the id of this item. Returns None if not Item
is active. Does not Raise Item.DoesNotExist
"""
2012-02-15 12:04:11 +01:00
sid = config["presentation"]
2012-02-06 22:22:16 +01:00
if only_sid:
return sid
return get_slide_from_sid(sid)
2012-02-09 02:29:38 +01:00
def set_active_slide(sid):
2012-02-15 12:04:11 +01:00
config["presentation"] = sid
2012-02-09 02:29:38 +01:00
2012-02-06 22:22:16 +01:00
def register_slidemodel(model):
SLIDE[model.prefix] = model
2012-02-09 01:46:58 +01:00
def register_slidefunc(name, func):
if ' ' in name:
raise NameError('There can be no space in name')
SLIDE[name] = func