OpenSlides/openslides/projector/api.py

82 lines
2.6 KiB
Python
Raw Normal View History

from system.api import config_set, config_get
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-06 22:22:16 +01:00
sid = config_get("presentation", None)
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):
config_set("presentation", sid)
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
2012-02-09 02:29:38 +01:00
## def assignment_votes(item):
## votes = []
## if item.type == "ItemAssignment":
## assignment = item.cast().assignment
## publish_winner_results_only = config_get("assignment_publish_winner_results_only")
## # list of votes
## votes = []
## for candidate in assignment.candidates:
## tmplist = [[candidate, assignment.is_elected(candidate)], []]
## for poll in assignment.poll_set.all():
## if poll.published:
## if candidate in poll.options_values:
## # check config option 'publish_winner_results_only'
## if not publish_winner_results_only \
## or publish_winner_results_only and assignment.is_elected(candidate):
## option = Option.objects.filter(poll=poll).filter(user=candidate)[0]
## if poll.optiondecision:
## tmplist[1].append([option.yes, option.no, option.undesided])
## else:
## tmplist[1].append(option.yes)
## else:
## tmplist[1].append("")
## else:
## tmplist[1].append("-")
## votes.append(tmplist)
## return votes
##
##
## def assignment_polls(item):
## polls = []
## if item.type == "ItemAssignment":
## for poll in item.cast().assignment.poll_set.filter(assignment=item.cast().assignment):
## polls.append(poll)
## return polls