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 openslides.system.api import config_get
from projector.api import get_active_element
from projector.api import get_active_slide
def is_summary():
@ -24,7 +24,7 @@ def is_summary():
"""
from agenda.models import Item
try:
get_active_element()
get_active_slide()
except Item.DoesNotExist:
return True
if config_get('summary', False):

View File

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

View File

@ -18,15 +18,15 @@ except ImportError:
from django.db import models
from django.utils.translation import ugettext as _
from projector.models import Element
from projector.api import element_register
from projector.models import Slide
from projector.api import register_slidemodel
from system.api import config_set
from application.models import Application
from poll.models import Poll
from assignment.models import Assignment
class Item(models.Model, Element):
class Item(models.Model, Slide):
"""
An Agenda Item
"""
@ -56,8 +56,8 @@ class Item(models.Model, Element):
"""
Return True if the item has a activ parent
"""
if get_active_element(only_id=True) in \
[parent.id for parent in self.parents]:
if get_active_slide(only_sid=True) in \
[parent.id for parent in self.parents]:
return True
return False
@ -65,7 +65,7 @@ class Item(models.Model, Element):
"""
Appoint this item as the active one.
"""
Element.set_active(self)
Slide.set_active(self)
if summary:
config_set("summary", True)
else:
@ -105,7 +105,7 @@ class Item(models.Model, Element):
"""
Return the WeightForm for this item.
"""
from agenda.forms import ElementOrderForm
from agenda.forms import ItemOrderForm
try:
parent = self.parent.id
except AttributeError:
@ -115,7 +115,7 @@ class Item(models.Model, Element):
'self': self.id,
'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):
"""
@ -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.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.api import is_summary, children_list, \
del_confirm_form_for_items
from agenda.forms import ElementOrderForm, ItemFormText
from agenda.forms import ItemOrderForm, ItemFormText
from application.models import Application
from assignment.models import Assignment
from poll.models import Poll
@ -53,7 +53,7 @@ def overview(request):
"""
if request.method == 'POST':
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():
try:
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_hidden = children_list(Item.objects.filter(parent=None).exclude(hidden=False).order_by('weight'))
try:
overview = is_summary() and not get_active_element()
overview = is_summary() and not get_active_slide()
except Item.DoesNotExist:
overview = True
return {

View File

@ -17,15 +17,15 @@ from django.db.models import Max
from django.contrib.auth.models import User
from django.utils.translation import ugettext as _
from projector.api import element_register
from projector.models import Element
from projector.api import register_slidemodel
from projector.models import Slide
from participant.models import Profile
from system.api import config_get
from utils.utils import _propper_unicode
class Application(models.Model, Element):
class Application(models.Model, Slide):
prefix = "application"
STATUS = (
('pub', _('Published')),
@ -483,4 +483,4 @@ class AVersion(models.Model):
.filter(id__lte=self.id).count()
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 projector.models import Element
from projector.api import element_register
from projector.models import Slide
from projector.api import register_slidemodel
class Assignment(models.Model, Element):
class Assignment(models.Model, Slide):
prefix = 'assignment'
STATUS = (
('sea', _('Searching for candidates')),
@ -145,4 +145,4 @@ class Assignment(models.Model, Element):
('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 projector.models import ELEMENT
from projector.models import SLIDE
def get_element_from_eid(eid):
def get_slide_from_sid(sid):
try:
model, id = eid.split()
model, id = sid.split()
except ValueError:
return None # We need a elementError hier
return None # We need a slideError hier
except AttributeError:
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,
it raise Element.DoesNotExist
Returns the active slide. If no slide is active, or it can not find an Item,
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
"""
from projector.models import Element
eid = config_get("presentation", None)
sid = config_get("presentation", None)
if only_eid:
return eid
return get_element_from_eid(eid)
if only_sid:
return sid
return get_slide_from_sid(sid)
def element_register(prefix, model):
ELEMENT[prefix] = model
def register_slidemodel(model):
SLIDE[model.prefix] = model
def assignment_votes(item):

View File

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

View File

@ -28,7 +28,7 @@ from agenda.api import is_summary, children_list, \
del_confirm_form_for_items
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')
@ -37,27 +37,27 @@ def active_slide(request):
Shows the active Slide.
"""
try:
element = get_active_element()
except Item.DoesNotExist: #TODO: It has to be an Element.DoesNotExist
element = None
slide = get_active_slide()
except Item.DoesNotExist: #TODO: It has to be an Slide.DoesNotExist
slide = None
if element is None:
if slide is None:
data = {}
else:
data = element.slide()
data = slide.slide()
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) \
.filter(hidden=False).order_by('weight')
data['title'] = _("Agenda")
else:
items = element.children.filter(hidden=False)
data['title'] = element.title
items = slide.children.filter(hidden=False)
data['title'] = slide.title
data['items'] = items
data['template'] = 'projector/AgendaSummary.html'