beamer setting page

This commit is contained in:
Oskar Hahn 2012-03-03 09:11:56 +01:00
parent a2230c9077
commit 654b101dac
10 changed files with 104 additions and 28 deletions

View File

@ -22,13 +22,13 @@ from mptt.models import MPTTModel, TreeForeignKey
from system import config from system import config
from projector.models import Slide from projector.models import SlideMixin
from projector.api import register_slidemodel from projector.api import register_slidemodel
from agenda.api import is_summary from agenda.api import is_summary
class Item(MPTTModel, Slide): class Item(MPTTModel, SlideMixin):
""" """
An Agenda Item An Agenda Item
@ -55,7 +55,7 @@ class Item(MPTTModel, Slide):
} }
if is_summary(): if is_summary():
data['items'] = self.children.filter(hidden=False) data['items'] = self.children.all()
data['template'] = 'projector/AgendaSummary.html' data['template'] = 'projector/AgendaSummary.html'
return data return data
@ -63,7 +63,7 @@ class Item(MPTTModel, Slide):
""" """
Appoint this item as the active one. Appoint this item as the active one.
""" """
Slide.set_active(self) super(Item, self).set_active()
if summary: if summary:
config["agenda_summary"] = True config["agenda_summary"] = True
else: else:
@ -135,7 +135,7 @@ class Item(MPTTModel, Slide):
register_slidemodel(Item) register_slidemodel(Item)
# TODO: put this in anouther file # TODO: put this in another file
from projector.api import register_slidefunc from projector.api import register_slidefunc
from agenda.slides import agenda_show from agenda.slides import agenda_show

View File

@ -36,7 +36,7 @@ class View(TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(View, self).get_context_data(**kwargs) context = super(View, self).get_context_data(**kwargs)
context.update({ context.update({
'item': Item.objects.get(pk=kwargs['item_id']), 'item': Item.objects.get(pk=kwargs['pk']),
'ajax': 'off', 'ajax': 'off',
}) })
return context return context

View File

@ -18,7 +18,7 @@ from django.contrib.auth.models import User
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from projector.api import register_slidemodel from projector.api import register_slidemodel
from projector.models import Slide from projector.models import SlideMixin
from participant.models import Profile from participant.models import Profile
from system import config from system import config
@ -27,7 +27,7 @@ from poll import ChoicePoll
from poll.models import BaseOption, BasePoll, CountVotesCast, CountInvalid, Vote from poll.models import BaseOption, BasePoll, CountVotesCast, CountInvalid, Vote
class Application(models.Model, Slide): class Application(models.Model, SlideMixin):
prefix = "application" prefix = "application"
STATUS = ( STATUS = (
('pub', _('Published')), ('pub', _('Published')),

View File

@ -15,12 +15,12 @@ from django.utils.translation import ugettext as _
from participant.models import Profile from participant.models import Profile
from projector.models import Slide from projector.models import SlideMixin
from projector.api import register_slidemodel from projector.api import register_slidemodel
from poll.models import BasePoll, CountInvalid, CountVotesCast, BaseOption from poll.models import BasePoll, CountInvalid, CountVotesCast, BaseOption
class Assignment(models.Model, Slide): class Assignment(models.Model, SlideMixin):
prefix = 'assignment' prefix = 'assignment'
STATUS = ( STATUS = (
('sea', _('Searching for candidates')), ('sea', _('Searching for candidates')),

View File

@ -14,7 +14,7 @@ from django.db import models
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from projector.api import register_slidemodel from projector.api import register_slidemodel
from projector.models import Slide from projector.models import SlideMixin
class BaseOption(models.Model): class BaseOption(models.Model):
@ -67,7 +67,7 @@ class CountInvalid(models.Model):
abstract = True abstract = True
class BasePoll(models.Model, Slide): class BasePoll(models.Model, SlideMixin):
#TODO: It would be nice if this class wouldn't be a subclass from models.Model. But it is needet aslong #TODO: It would be nice if this class wouldn't be a subclass from models.Model. But it is needet aslong
# BaseOption has a foreignKey on BasePoll # BaseOption has a foreignKey on BasePoll
prefix = 'BasePoll' prefix = 'BasePoll'

View File

@ -1,16 +1,16 @@
from system import config from system import config
from projector.models import SLIDE from projector.models import SLIDE, Slide
def get_slide_from_sid(sid): def get_slide_from_sid(sid):
data = sid.split() data = sid.split('-')
if len(data) == 2: if len(data) == 2:
model = data[0] model = data[0]
id = data[1] id = data[1]
return SLIDE[model].objects.get(pk=id).slide() return SLIDE[model].model.objects.get(pk=id).slide()
if len(data) == 1: if len(data) == 1:
try: try:
return SLIDE[data[0]]() return SLIDE[data[0]].func()
except KeyError: except KeyError:
return None return None
return None return None
@ -35,11 +35,25 @@ def set_active_slide(sid):
config["presentation"] = sid config["presentation"] = sid
def register_slidemodel(model): def register_slidemodel(model, category=None):
SLIDE[model.prefix] = model #TODO: Warn if there already is a slide with this prefix
SLIDE[model.prefix] = Slide(
model_slide=True,
model=model,
category=category,
key=model.prefix,
)
def register_slidefunc(name, func): def register_slidefunc(key, func, category=None):
if ' ' in name: #TODO: Warn if there already is a slide with this prefix
raise NameError('There can be no space in name') SLIDE[key] = Slide(
SLIDE[name] = func model_slide=False,
func=func,
category=category,
key=key,
)
#def get_possible_slides():

View File

@ -4,7 +4,7 @@ from system import config
SLIDE = {} SLIDE = {}
class Slide(object): class SlideMixin(object):
def slide(self): def slide(self):
""" """
@ -22,8 +22,8 @@ class Slide(object):
Return the sid from this Slide Return the sid from this Slide
""" """
for key, value in SLIDE.iteritems(): for key, value in SLIDE.iteritems():
if type(self) == value: if type(self) == value.model:
return "%s %d" % (key, self.id) return "%s-%d" % (key, self.id)
return None return None
@property @property
@ -38,4 +38,23 @@ class Slide(object):
""" """
Appoint this item as the active one. Appoint this item as the active one.
""" """
config["presentation"] = "%s %d" % (self.prefix, self.id) config["presentation"] = "%s-%d" % (self.prefix, self.id)
class Slide(object):
def __init__(self, model_slide=False, func=None, model=None, category=None, key=None):
"""
model_slide: Boolean if the value is a Model.
func: The function to call. Only if modelslide is False.
model: The model. Only if modelslide is True.
category: The category to show this Slide.
key: the key in the slide object to find myself.
"""
self.model_slide = model_slide
self.func = func
self.model = model
self.category = category
self.key = key
def get_items(self):
return self.model.objects.all()

View File

@ -12,10 +12,22 @@
from django.conf.urls.defaults import * from django.conf.urls.defaults import *
from projector.views import SettingView, ActivateView
urlpatterns = patterns('projector.views', urlpatterns = patterns('projector.views',
url(r'^$', 'active_slide', url(r'^$', 'active_slide',
name='projector_show'), name='projector_show'),
url(r'^settings$',
SettingView.as_view(),
name='projector_settings',
),
url(r'^activate/(?P<sid>[^/]*)/$',
ActivateView.as_view(),
name='projector_activate_slide',
),
url(r'^bigger/$', 'projector_edit', {'direction': 'bigger'}, url(r'^bigger/$', 'projector_edit', {'direction': 'bigger'},
name='projector_bigger'), name='projector_bigger'),

View File

@ -18,13 +18,38 @@ from django.contrib import messages
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from utils.views import TemplateView, RedirectView
from utils.utils import template, permission_required, \ from utils.utils import template, permission_required, \
del_confirm_form, ajax_request del_confirm_form, ajax_request
from utils.template import render_block_to_string from utils.template import render_block_to_string
from system import config from system import config
from projector.api import get_active_slide from projector.api import get_active_slide, set_active_slide
from projector.models import SLIDE
class SettingView(TemplateView):
template_name = 'projector/settings.html'
def get_context_data(self, **kwargs):
context = super(SettingView, self).get_context_data(**kwargs)
context.update({
'slides': SLIDE.values(),
})
return context
class ActivateView(RedirectView):
url = 'projector_settings'
allow_ajax = True
def pre_redirect(self, request, *args, **kwargs):
set_active_slide(kwargs['sid'])
def get_ajax_context(self, **kwargs):
context = super(ActivateView, self).get_ajax_context()
return context
@permission_required('agenda.can_see_projector') @permission_required('agenda.can_see_projector')
@ -35,6 +60,9 @@ def active_slide(request):
try: try:
data = get_active_slide() data = get_active_slide()
except AttributeError: #TODO: It has to be an Slide.DoesNotExist except AttributeError: #TODO: It has to be an Slide.DoesNotExist
data = None
if data is None:
data = { data = {
'title': config['event_name'], 'title': config['event_name'],
'template': 'projector/default.html', 'template': 'projector/default.html',

View File

@ -22,7 +22,7 @@
<ul> <ul>
{% if user.is_authenticated %} {% if user.is_authenticated %}
<li>|<a href="{% url user_logout %}">{%trans "Logout" %}</a></li> <li>|<a href="{% url user_logout %}">{%trans "Logout" %}</a></li>
<li>|<a href="{% url user_settings %}">{%trans "Settings" %}</a></li> <li>|<a href="{% url user_settings %}">{%trans "Usersettings" %}</a></li>
<li>{%trans "Welcome" %}, <strong>{{ user.username }}</strong></li> <li>{%trans "Welcome" %}, <strong>{{ user.username }}</strong></li>
{% else %} {% else %}
<li><a href="{% url user_login %}">{%trans "Login" %}</a></li> <li><a href="{% url user_login %}">{%trans "Login" %}</a></li>
@ -33,6 +33,9 @@
<div id="mainmenu"> <div id="mainmenu">
{% block mainmenu %} {% block mainmenu %}
<ul> <ul>
<li class="{% active request '/projector' %}">
<a href="{% url projector_settings %}" title="">{%trans "Projector" %}</a>
</li>
{% if perms.agenda.can_see_agenda or perms.agenda.can_manage_agenda %} {% if perms.agenda.can_see_agenda or perms.agenda.can_manage_agenda %}
<li class="{% active request '/agenda' %} <li class="{% active request '/agenda' %}
{% if request.path == '/'%}selected{% endif %}"> {% if request.path == '/'%}selected{% endif %}">