2012-04-14 12:52:56 +02:00
|
|
|
from config.models import config
|
2012-03-12 18:22:18 +01:00
|
|
|
from projector import SLIDE, Slide
|
2012-02-03 23:12:28 +01:00
|
|
|
|
|
|
|
|
2012-02-06 22:22:16 +01:00
|
|
|
def get_slide_from_sid(sid):
|
2012-03-03 09:11:56 +01:00
|
|
|
data = sid.split('-')
|
2012-02-09 01:46:58 +01:00
|
|
|
if len(data) == 2:
|
|
|
|
model = data[0]
|
|
|
|
id = data[1]
|
2012-03-03 09:11:56 +01:00
|
|
|
return SLIDE[model].model.objects.get(pk=id).slide()
|
2012-02-09 01:46:58 +01:00
|
|
|
if len(data) == 1:
|
|
|
|
try:
|
2012-03-03 09:11:56 +01:00
|
|
|
return SLIDE[data[0]].func()
|
2012-02-09 01:46:58 +01:00
|
|
|
except KeyError:
|
|
|
|
return None
|
|
|
|
return None
|
2012-02-03 23:12:28 +01:00
|
|
|
|
|
|
|
|
2012-02-06 22:22:16 +01:00
|
|
|
def get_active_slide(only_sid=False):
|
2012-02-03 23:12:28 +01:00
|
|
|
"""
|
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-03 23:12:28 +01:00
|
|
|
|
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
|
2012-02-03 23:12:28 +01:00
|
|
|
is active. Does not Raise Item.DoesNotExist
|
|
|
|
"""
|
2012-02-15 12:04:11 +01:00
|
|
|
sid = config["presentation"]
|
2012-02-03 23:12:28 +01:00
|
|
|
|
2012-02-06 22:22:16 +01:00
|
|
|
if only_sid:
|
|
|
|
return sid
|
|
|
|
return get_slide_from_sid(sid)
|
2012-02-03 23:12:28 +01:00
|
|
|
|
|
|
|
|
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-04-14 11:18:47 +02:00
|
|
|
def register_slidemodel(model, model_name=None):
|
2012-03-03 09:11:56 +01:00
|
|
|
#TODO: Warn if there already is a slide with this prefix
|
2012-03-06 12:16:03 +01:00
|
|
|
if model_name is None:
|
|
|
|
model_name = model.prefix
|
2012-04-14 11:18:47 +02:00
|
|
|
|
|
|
|
category = model.__module__.split('.')[0]
|
2012-03-03 09:11:56 +01:00
|
|
|
SLIDE[model.prefix] = Slide(
|
|
|
|
model_slide=True,
|
|
|
|
model=model,
|
|
|
|
category=category,
|
|
|
|
key=model.prefix,
|
2012-03-03 11:16:10 +01:00
|
|
|
model_name=model_name,
|
2012-03-03 09:11:56 +01:00
|
|
|
)
|
2012-02-03 23:12:28 +01:00
|
|
|
|
|
|
|
|
2012-04-14 11:18:47 +02:00
|
|
|
def register_slidefunc(key, func):
|
2012-03-03 09:11:56 +01:00
|
|
|
#TODO: Warn if there already is a slide with this prefix
|
2012-04-14 11:18:47 +02:00
|
|
|
category = func.__module__.split('.')[0]
|
2012-03-03 09:11:56 +01:00
|
|
|
SLIDE[key] = Slide(
|
|
|
|
model_slide=False,
|
|
|
|
func=func,
|
|
|
|
category=category,
|
|
|
|
key=key,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
#def get_possible_slides():
|
|
|
|
|