rename Element to Slide

This commit is contained in:
Oskar Hahn 2012-02-06 22:22:16 +01:00
parent 16c37661f7
commit 8c27c731f8
9 changed files with 60 additions and 61 deletions

View File

@ -15,7 +15,7 @@ from django.contrib import messages
from django.core.context_processors import csrf from django.core.context_processors import csrf
from openslides.system.api import config_get from openslides.system.api import config_get
from projector.api import get_active_element from projector.api import get_active_slide
def is_summary(): def is_summary():
@ -24,7 +24,7 @@ def is_summary():
""" """
from agenda.models import Item from agenda.models import Item
try: try:
get_active_element() get_active_slide()
except Item.DoesNotExist: except Item.DoesNotExist:
return True return True
if config_get('summary', False): if config_get('summary', False):

View File

@ -13,7 +13,7 @@
from django.forms import Form, ModelForm, IntegerField, ChoiceField, \ from django.forms import Form, ModelForm, IntegerField, ChoiceField, \
ModelChoiceField, HiddenInput, Select ModelChoiceField, HiddenInput, Select
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from openslides.agenda.models import Item, ItemText from openslides.agenda.models import Item
class ItemFormText(ModelForm): class ItemFormText(ModelForm):
error_css_class = 'error' error_css_class = 'error'
@ -21,7 +21,7 @@ class ItemFormText(ModelForm):
items = Item.objects.all().filter(parent=None).order_by('weight') items = Item.objects.all().filter(parent=None).order_by('weight')
parent = ModelChoiceField(queryset=items, label=_("Parent item"), required=False) parent = ModelChoiceField(queryset=items, label=_("Parent item"), required=False)
class Meta: class Meta:
model = ItemText model = Item
exclude = ('closed', 'weight') exclude = ('closed', 'weight')
@ -32,7 +32,7 @@ def genweightchoices():
return l return l
class ElementOrderForm(Form): class ItemOrderForm(Form):
weight = ChoiceField(choices=genweightchoices(), \ weight = ChoiceField(choices=genweightchoices(), \
widget=Select(attrs={'class': 'menu-weight'}), widget=Select(attrs={'class': 'menu-weight'}),
label="") label="")

View File

@ -18,15 +18,15 @@ except ImportError:
from django.db import models from django.db import models
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from projector.models import Element from projector.models import Slide
from projector.api import element_register from projector.api import register_slidemodel
from system.api import config_set from system.api import config_set
from application.models import Application from application.models import Application
from poll.models import Poll from poll.models import Poll
from assignment.models import Assignment from assignment.models import Assignment
class Item(models.Model, Element): class Item(models.Model, Slide):
""" """
An Agenda Item An Agenda Item
""" """
@ -56,7 +56,7 @@ class Item(models.Model, Element):
""" """
Return True if the item has a activ parent Return True if the item has a activ parent
""" """
if get_active_element(only_id=True) in \ if get_active_slide(only_sid=True) in \
[parent.id for parent in self.parents]: [parent.id for parent in self.parents]:
return True return True
return False return False
@ -65,7 +65,7 @@ class Item(models.Model, Element):
""" """
Appoint this item as the active one. Appoint this item as the active one.
""" """
Element.set_active(self) Slide.set_active(self)
if summary: if summary:
config_set("summary", True) config_set("summary", True)
else: else:
@ -105,7 +105,7 @@ class Item(models.Model, Element):
""" """
Return the WeightForm for this item. Return the WeightForm for this item.
""" """
from agenda.forms import ElementOrderForm from agenda.forms import ItemOrderForm
try: try:
parent = self.parent.id parent = self.parent.id
except AttributeError: except AttributeError:
@ -115,7 +115,7 @@ class Item(models.Model, Element):
'self': self.id, 'self': self.id,
'parent': parent, 'parent': parent,
} }
return ElementOrderForm(initial=initial, prefix="i%d" % self.id) return ItemOrderForm(initial=initial, prefix="i%d" % self.id)
def edit_form(self, post=None): def edit_form(self, post=None):
""" """
@ -191,4 +191,4 @@ ItemText = Item # ItemText is Depricated
element_register(Item.prefix, Item) register_slidemodel(Item)

View File

@ -17,11 +17,11 @@ from django.core.urlresolvers import reverse
from django.contrib import messages from django.contrib import messages
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from projector.api import get_active_element from projector.api import get_active_slide
from agenda.models import Item from agenda.models import Item
from agenda.api import is_summary, children_list, \ from agenda.api import is_summary, children_list, \
del_confirm_form_for_items del_confirm_form_for_items
from agenda.forms import ElementOrderForm, ItemFormText from agenda.forms import ItemOrderForm, ItemFormText
from application.models import Application from application.models import Application
from assignment.models import Assignment from assignment.models import Assignment
from poll.models import Poll from poll.models import Poll
@ -53,7 +53,7 @@ def overview(request):
""" """
if request.method == 'POST': if request.method == 'POST':
for item in Item.objects.all(): for item in Item.objects.all():
form = ElementOrderForm(request.POST, prefix="i%d" % item.id) form = ItemOrderForm(request.POST, prefix="i%d" % item.id)
if form.is_valid(): if form.is_valid():
try: try:
item.parent = Item.objects.get( \ item.parent = Item.objects.get( \
@ -66,7 +66,7 @@ def overview(request):
items = children_list(Item.objects.filter(parent=None).exclude(hidden=True).order_by('weight')) items = children_list(Item.objects.filter(parent=None).exclude(hidden=True).order_by('weight'))
items_hidden = children_list(Item.objects.filter(parent=None).exclude(hidden=False).order_by('weight')) items_hidden = children_list(Item.objects.filter(parent=None).exclude(hidden=False).order_by('weight'))
try: try:
overview = is_summary() and not get_active_element() overview = is_summary() and not get_active_slide()
except Item.DoesNotExist: except Item.DoesNotExist:
overview = True overview = True
return { return {

View File

@ -17,15 +17,15 @@ from django.db.models import Max
from django.contrib.auth.models import User 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 element_register from projector.api import register_slidemodel
from projector.models import Element from projector.models import Slide
from participant.models import Profile from participant.models import Profile
from system.api import config_get from system.api import config_get
from utils.utils import _propper_unicode from utils.utils import _propper_unicode
class Application(models.Model, Element): class Application(models.Model, Slide):
prefix = "application" prefix = "application"
STATUS = ( STATUS = (
('pub', _('Published')), ('pub', _('Published')),
@ -483,4 +483,4 @@ class AVersion(models.Model):
.filter(id__lte=self.id).count() .filter(id__lte=self.id).count()
return self._aid return self._aid
element_register(Application.prefix, Application) register_slidemodel(Application)

View File

@ -15,11 +15,11 @@ from django.utils.translation import ugettext as _
from participant.models import Profile from participant.models import Profile
from projector.models import Element from projector.models import Slide
from projector.api import element_register from projector.api import register_slidemodel
class Assignment(models.Model, Element): class Assignment(models.Model, Slide):
prefix = 'assignment' prefix = 'assignment'
STATUS = ( STATUS = (
('sea', _('Searching for candidates')), ('sea', _('Searching for candidates')),
@ -145,4 +145,4 @@ class Assignment(models.Model, Element):
('can_manage_assignment', "Can manage assignment"), ('can_manage_assignment', "Can manage assignment"),
) )
element_register(Assignment.prefix, Assignment) register_slidemodel(Assignment)

View File

@ -1,35 +1,34 @@
from system.api import config_set, config_get from system.api import config_set, config_get
from projector.models import ELEMENT from projector.models import SLIDE
def get_element_from_eid(eid): def get_slide_from_sid(sid):
try: try:
model, id = eid.split() model, id = sid.split()
except ValueError: except ValueError:
return None # We need a elementError hier return None # We need a slideError hier
except AttributeError: except AttributeError:
return None return None
return ELEMENT[model].objects.get(pk=id) return SLIDE[model].objects.get(pk=id)
def get_active_element(only_eid=False): def get_active_slide(only_sid=False):
""" """
Returns the active element. If no element is active, or it can not find an Item, Returns the active slide. If no slide is active, or it can not find an Item,
it raise Element.DoesNotExist it raise an error
if only_id is True, returns only the id of this item. Returns None if not Item if only_sid is True, returns only the id of this item. Returns None if not Item
is active. Does not Raise Item.DoesNotExist is active. Does not Raise Item.DoesNotExist
""" """
from projector.models import Element sid = config_get("presentation", None)
eid = config_get("presentation", None)
if only_eid: if only_sid:
return eid return sid
return get_element_from_eid(eid) return get_slide_from_sid(sid)
def element_register(prefix, model): def register_slidemodel(model):
ELEMENT[prefix] = model SLIDE[model.prefix] = model
def assignment_votes(item): def assignment_votes(item):

View File

@ -2,25 +2,25 @@ from django.db import models
from system.api import config_set, config_get from system.api import config_set, config_get
ELEMENT = {} SLIDE = {}
class Element(object): class Slide(object):
def slide(self): def slide(self):
""" """
Return a map with all Data for a Slide Return a map with all Data for a Slide
""" """
return { return {
'element': self, 'slide': self,
'title': 'dummy-title', 'title': 'dummy-title',
} }
@property @property
def eid(self): def sid(self):
""" """
Return the eid from this element Return the sid from this Slide
""" """
for key, value in ELEMENT.iteritems(): for key, value in SLIDE.iteritems():
if type(self) == value: if type(self) == value:
return "%s %d" % (key, self.id) return "%s %d" % (key, self.id)
return None return None
@ -28,10 +28,10 @@ class Element(object):
@property @property
def active(self): def active(self):
""" """
Return True, if the the element is the active one. Return True, if the the slide is the active one.
""" """
from projector.api import get_active_element from projector.api import get_active_slide
return True if get_active_element(only_eid=True) == self.eid else False return True if get_active_slide(only_sid=True) == self.sid else False
def set_active(self): def set_active(self):
""" """

View File

@ -28,7 +28,7 @@ from agenda.api import is_summary, children_list, \
del_confirm_form_for_items del_confirm_form_for_items
from agenda.models import Item from agenda.models import Item
from projector.api import get_active_element, assignment_votes, assignment_polls from projector.api import get_active_slide
@permission_required('agenda.can_see_projector') @permission_required('agenda.can_see_projector')
@ -37,27 +37,27 @@ def active_slide(request):
Shows the active Slide. Shows the active Slide.
""" """
try: try:
element = get_active_element() slide = get_active_slide()
except Item.DoesNotExist: #TODO: It has to be an Element.DoesNotExist except Item.DoesNotExist: #TODO: It has to be an Slide.DoesNotExist
element = None slide = None
if element is None: if slide is None:
data = {} data = {}
else: else:
data = element.slide() data = slide.slide()
data['ajax'] = 'on' data['ajax'] = 'on'
if element is None or (type(element) == Item and is_summary()): if slide is None or (type(slide) == Item and is_summary()):
if element is None: if slide is None:
items = Item.objects.filter(parent=None) \ items = Item.objects.filter(parent=None) \
.filter(hidden=False).order_by('weight') .filter(hidden=False).order_by('weight')
data['title'] = _("Agenda") data['title'] = _("Agenda")
else: else:
items = element.children.filter(hidden=False) items = slide.children.filter(hidden=False)
data['title'] = element.title data['title'] = slide.title
data['items'] = items data['items'] = items
data['template'] = 'projector/AgendaSummary.html' data['template'] = 'projector/AgendaSummary.html'