From 5f6c96b3e888d7d1accf6287dcf1497a9dc59389 Mon Sep 17 00:00:00 2001
From: Oskar Hahn
Date: Fri, 3 Feb 2012 23:12:28 +0100
Subject: [PATCH] assignment and application can be beamt without a
item-element
---
openslides/agenda/admin.py | 3 +-
openslides/agenda/api.py | 22 +-----
openslides/agenda/forms.py | 32 +-------
openslides/agenda/models.py | 65 ++++++----------
.../agenda/templates/agenda/base_agenda.html | 2 +-
.../templates/beamer/AgendaSummary.html} | 0
.../templates/beamer/AgendaText.html} | 0
openslides/agenda/urls.py | 7 +-
openslides/agenda/views.py | 43 ++++-------
openslides/application/models.py | 34 ++++++---
.../templates/application/view.html | 17 +----
.../templates/beamer/Application.html} | 18 ++---
openslides/application/views.py | 4 +-
openslides/assignment/models.py | 18 ++++-
.../assignment/templates/assignment/view.html | 13 +---
.../templates/beamer/Assignment.html} | 22 +++---
openslides/assignment/views.py | 4 +-
openslides/beamer/api.py | 32 ++++++++
openslides/beamer/models.py | 39 +++++++++-
.../beamer/templates/beamer/ItemPoll.html | 19 -----
openslides/beamer/views.py | 75 ++++++++++---------
21 files changed, 223 insertions(+), 246 deletions(-)
rename openslides/{beamer/templates/beamer/overview.html => agenda/templates/beamer/AgendaSummary.html} (100%)
rename openslides/{beamer/templates/beamer/ItemText.html => agenda/templates/beamer/AgendaText.html} (100%)
rename openslides/{beamer/templates/beamer/ItemApplication.html => application/templates/beamer/Application.html} (77%)
rename openslides/{beamer/templates/beamer/ItemAssignment.html => assignment/templates/beamer/Assignment.html} (82%)
delete mode 100644 openslides/beamer/templates/beamer/ItemPoll.html
diff --git a/openslides/agenda/admin.py b/openslides/agenda/admin.py
index 52fa6ef0b..bfab6d8f6 100644
--- a/openslides/agenda/admin.py
+++ b/openslides/agenda/admin.py
@@ -12,7 +12,6 @@
from django.contrib import admin
-from openslides.agenda.models import Item, ItemText
+from openslides.agenda.models import Item
admin.site.register(Item)
-admin.site.register(ItemText)
diff --git a/openslides/agenda/api.py b/openslides/agenda/api.py
index 3c0b86ba0..d07c306af 100644
--- a/openslides/agenda/api.py
+++ b/openslides/agenda/api.py
@@ -15,23 +15,7 @@ from django.contrib import messages
from django.core.context_processors import csrf
from openslides.system.api import config_get
-
-
-def get_active_item(only_id=False):
- """
- Returns the active Item. If no item is active, or it can not find an Item,
- it raise Item.DoesNotExist
-
- if only_id is True, returns only the id of this item. Returns None if not Item
- is active. Does not Raise Item.DoesNotExist
- """
- from agenda.models import Item
- id = config_get("presentation", None)
- if only_id:
- if id is None:
- return None
- return int(id)
- return Item.objects.get(pk=id)
+from beamer.api import get_active_element
def is_summary():
@@ -40,7 +24,7 @@ def is_summary():
"""
from agenda.models import Item
try:
- get_active_item()
+ get_active_element()
except Item.DoesNotExist:
return True
if config_get('summary', False):
@@ -70,4 +54,4 @@ def del_confirm_form_for_items(request, object, name=None):
if object.children:
gen_confirm_form_for_items(request, _('Do you really want to delete %s?') % name, object.get_absolute_url('delete'), False)
else:
- gen_confirm_form_for_items(request, _('Do you really want to delete %s?') % name, object.get_absolute_url('delete'), True)
\ No newline at end of file
+ gen_confirm_form_for_items(request, _('Do you really want to delete %s?') % name, object.get_absolute_url('delete'), True)
diff --git a/openslides/agenda/forms.py b/openslides/agenda/forms.py
index 69f761e75..fdd5b9c2d 100644
--- a/openslides/agenda/forms.py
+++ b/openslides/agenda/forms.py
@@ -13,8 +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, ItemApplication, \
- ItemAssignment
+from openslides.agenda.models import Item, ItemText
class ItemFormText(ModelForm):
error_css_class = 'error'
@@ -26,28 +25,6 @@ class ItemFormText(ModelForm):
exclude = ('closed', 'weight')
-class ItemFormApplication(ModelForm):
- error_css_class = 'error'
- required_css_class = 'required'
- items = Item.objects.all().filter(parent=None).order_by('weight')
- parent = ModelChoiceField(queryset=items, label=_("Parent item"), required=False)
-
- class Meta:
- model = ItemApplication
- exclude = ('closed', 'weight')
-
-
-class ItemFormAssignment(ModelForm):
- error_css_class = 'error'
- required_css_class = 'required'
- items = Item.objects.all().filter(parent=None).order_by('weight')
- parent = ModelChoiceField(queryset=items, label=_("Parent item"), required=False)
-
- class Meta:
- model = ItemAssignment
- exclude = ('closed', 'weight')
-
-
def genweightchoices():
l = []
for i in range(-50, 51):
@@ -61,10 +38,3 @@ class ElementOrderForm(Form):
label="")
self = IntegerField(widget=HiddenInput(attrs={'class': 'menu-mlid'}))
parent = IntegerField(widget=HiddenInput(attrs={'class': 'menu-plid'}))
-
-
-MODELFORM = {
- 'ItemText': ItemFormText,
- 'ItemApplication': ItemFormApplication,
- 'ItemAssignment': ItemFormAssignment,
-}
diff --git a/openslides/agenda/models.py b/openslides/agenda/models.py
index 40bebf658..f0228ef53 100644
--- a/openslides/agenda/models.py
+++ b/openslides/agenda/models.py
@@ -18,40 +18,45 @@ except ImportError:
from django.db import models
from django.utils.translation import ugettext as _
-from model_utils.models import InheritanceCastModel
-
-from openslides.agenda.api import get_active_item
-from openslides.system.api import config_set
-from openslides.application.models import Application
-from openslides.poll.models import Poll
-from openslides.assignment.models import Assignment
+from beamer.models import Element
+from beamer.api import element_register
+from system.api import config_set
+from application.models import Application
+from poll.models import Poll
+from assignment.models import Assignment
-class Item(InheritanceCastModel):
+class Item(models.Model, Element):
"""
- The BasisItem.
- Has all the attributes all Items need.
+ An Agenda Item
"""
title = models.CharField(max_length=100, verbose_name=_("Title"))
+ text = models.TextField(null=True, blank=True, verbose_name=_("Text"))
+ transcript = models.TextField(null=True, blank=True, verbose_name=_("Transcript"))
closed = models.BooleanField(default=False, verbose_name=_("Closed"))
weight = models.IntegerField(default=0, verbose_name=_("Weight"))
parent = models.ForeignKey('self', blank=True, null=True)
hidden = models.BooleanField(default=False,
verbose_name=_("Hidden (visible for agenda manager only)"))
+ prefix = 'item'
- @property
- def active(self):
+
+ def beamer(self):
"""
- Return True, if the the item is the active one.
+ Return a map with all Data for the Beamer
"""
- return True if get_active_item(only_id=True) == self.id else False
+ return {
+ 'item': self,
+ 'title': self.title,
+ 'template': 'beamer/AgendaText.html',
+ }
@property
def active_parent(self):
"""
Return True if the item has a activ parent
"""
- if get_active_item(only_id=True) in \
+ if get_active_element(only_id=True) in \
[parent.id for parent in self.parents]:
return True
return False
@@ -60,7 +65,7 @@ class Item(InheritanceCastModel):
"""
Appoint this item as the active one.
"""
- config_set("presentation", self.id)
+ Element.set_active(self)
if summary:
config_set("summary", True)
else:
@@ -182,32 +187,8 @@ class Item(InheritanceCastModel):
)
-class ItemText(Item):
- """
- An Item with a TextField.
- """
- text = models.TextField(null=True, blank=True, verbose_name=_("Text"))
-
- class Meta:
- pass
+ItemText = Item # ItemText is Depricated
-class ItemApplication(Item):
- """
- An Item which is connected to an application.
- """
- application = models.ForeignKey(Application, verbose_name=_("Application"))
-
-class ItemAssignment(Item):
- """
- An Item which is connected to an assignment.
- """
- assignment = models.ForeignKey(Assignment, verbose_name=_("Election"))
-
-
-class ItemPoll(Item):
- """
- An Item which is connected to a poll
- """
- poll = models.ForeignKey(Poll, verbose_name=_("Poll"))
+element_register(Item.prefix, Item)
diff --git a/openslides/agenda/templates/agenda/base_agenda.html b/openslides/agenda/templates/agenda/base_agenda.html
index 8b4f73db0..331f98d6f 100644
--- a/openslides/agenda/templates/agenda/base_agenda.html
+++ b/openslides/agenda/templates/agenda/base_agenda.html
@@ -8,7 +8,7 @@
- {%trans "All items" %}
{% if perms.agenda.can_manage_agenda %}
- - {%trans "New item" %}
+ - {%trans "New item" %}
{% endif %}
{% if perms.agenda.can_see_projector %}
- {%trans 'Projector view' %}
diff --git a/openslides/beamer/templates/beamer/overview.html b/openslides/agenda/templates/beamer/AgendaSummary.html
similarity index 100%
rename from openslides/beamer/templates/beamer/overview.html
rename to openslides/agenda/templates/beamer/AgendaSummary.html
diff --git a/openslides/beamer/templates/beamer/ItemText.html b/openslides/agenda/templates/beamer/AgendaText.html
similarity index 100%
rename from openslides/beamer/templates/beamer/ItemText.html
rename to openslides/agenda/templates/beamer/AgendaText.html
diff --git a/openslides/agenda/urls.py b/openslides/agenda/urls.py
index e890540db..c8cc08ea2 100644
--- a/openslides/agenda/urls.py
+++ b/openslides/agenda/urls.py
@@ -40,14 +40,9 @@ urlpatterns = patterns('agenda.views',
url(r'^agenda/new/$', 'edit',
name='item_new_default'),
- url(r'^agenda/new/(?P
{% endif %}
- {% if "createitem" in actions %}
-
-
- {%trans 'New agenda item' %}
-
- {% endif %}
-
- {% if "activateitem" in actions %}
-
-
- {%trans 'Show agenda item' %}
-
- {% endif %}
+
+
+ {%trans 'Beam Application' %}
+
{% if "acc" in actions or "rej" in actions %}
{% trans "Result after vote" %}:
diff --git a/openslides/beamer/templates/beamer/ItemApplication.html b/openslides/application/templates/beamer/Application.html
similarity index 77%
rename from openslides/beamer/templates/beamer/ItemApplication.html
rename to openslides/application/templates/beamer/Application.html
index 8bbde4567..cad4db3e1 100644
--- a/openslides/beamer/templates/beamer/ItemApplication.html
+++ b/openslides/application/templates/beamer/Application.html
@@ -6,19 +6,19 @@
- {% trans "Application No." %} {{ item.application.number }}
+ {% trans "Application No." %} {{ application.number }}
{{ item.title }}
-
{{ item.application.public_version.text|linebreaks }}
- {% if item.application.public_version.reason %}
+ {{ application.public_version.text|linebreaks }}
+ {% if application.public_version.reason %}
{% trans "Reason" %}:
- {{ item.application.public_version.reason|linebreaks }}
+ {{ application.public_version.reason|linebreaks }}
{% endif %}
{% endblock %}
diff --git a/openslides/application/views.py b/openslides/application/views.py
index 3c1f3f266..c0f98b0a6 100644
--- a/openslides/application/views.py
+++ b/openslides/application/views.py
@@ -332,8 +332,8 @@ def unsupport(request, application_id):
@permission_required('application.can_manage_application')
def set_active(request, application_id):
- item = Item.objects.get(itemapplication__application__id=application_id)
- item.set_active(False)
+ application = Application.objects.get(pk=application_id)
+ application.set_active()
return redirect(reverse('application_view', args=[application_id]))
diff --git a/openslides/assignment/models.py b/openslides/assignment/models.py
index 899ca9af9..337a6bb0b 100644
--- a/openslides/assignment/models.py
+++ b/openslides/assignment/models.py
@@ -15,8 +15,12 @@ from django.utils.translation import ugettext as _
from participant.models import Profile
+from beamer.models import Element
+from beamer.api import element_register
-class Assignment(models.Model):
+
+class Assignment(models.Model, Element):
+ prefix = 'assignment'
STATUS = (
('sea', _('Searching for candidates')),
('vot', _('Voting')),
@@ -113,6 +117,16 @@ class Assignment(models.Model):
poll.add_option(candidate)
return poll
+ def beamer(self):
+ """
+ return the beamer dict
+ """
+ data = super(Assignment, self).beamer()
+ data['assignment'] = self
+ data['title'] = self.name
+ data['template'] = 'beamer/Assignment.html'
+ return data
+
@models.permalink
def get_absolute_url(self, link='view'):
if link == 'view':
@@ -130,3 +144,5 @@ class Assignment(models.Model):
('can_nominate_self', "Can nominate themselves"),
('can_manage_assignment', "Can manage assignment"),
)
+
+element_register(Assignment.prefix, Assignment)
diff --git a/openslides/assignment/templates/assignment/view.html b/openslides/assignment/templates/assignment/view.html
index 49f590f98..2a5d56754 100644
--- a/openslides/assignment/templates/assignment/view.html
+++ b/openslides/assignment/templates/assignment/view.html
@@ -36,21 +36,14 @@
- {% if not assignment.itemassignment_set.all %}
-
-
-
- {%trans 'New agenda item' %}
-
-
- {% else %}
+
- {%trans 'Show agenda item' %}
+ {%trans 'Beam assignment' %}
- {% endif %}
+
{% endif %}
diff --git a/openslides/beamer/templates/beamer/ItemAssignment.html b/openslides/assignment/templates/beamer/Assignment.html
similarity index 82%
rename from openslides/beamer/templates/beamer/ItemAssignment.html
rename to openslides/assignment/templates/beamer/Assignment.html
index 6304d71f3..b0a6c38eb 100644
--- a/openslides/beamer/templates/beamer/ItemAssignment.html
+++ b/openslides/assignment/templates/beamer/Assignment.html
@@ -5,31 +5,31 @@
{% endblock %}
{% block content %}
- {% trans "Election" %}: {{ item.assignment }}
+ {% trans "Election" %}: {{ assignment }}
- {% if item.assignment.status != "fin" %}
+ {% if assignment.status != "fin" %}
{% endif %}
- {% if not item.assignment.profile.exists %}
+ {% if not assignment.profile.exists %}
-
{{ item.assignment.description|linebreaks }}
+ {{ assignment.description|linebreaks }}
{% endif %}
- {% if item.assignment.profile.exists and item.assignment.status != "fin" %}
+ {% if assignment.profile.exists and assignment.status != "fin" %}
{% trans "Candidates" %}
- {% for profile in item.assignment.profile.all|dictsort:"user.first_name" %}
+ {% for profile in assignment.profile.all|dictsort:"user.first_name" %}
- {{ profile }}
{% empty %}
-
@@ -46,7 +46,7 @@
{% trans "Candidates" %} |
- {% for poll in item.assignment.poll_set.all %}
+ {% for poll in assignment.poll_set.all %}
{% if poll.published %}
{{forloop.counter}}. {% trans "ballot" %} |
{% endif %}
@@ -78,7 +78,7 @@
{% empty %}
- {% trans "No ballots available." %} |
+ {% trans "No ballots available." %} |
{% endfor %}
diff --git a/openslides/assignment/views.py b/openslides/assignment/views.py
index 9c06ac1b4..70e7394e7 100644
--- a/openslides/assignment/views.py
+++ b/openslides/assignment/views.py
@@ -187,8 +187,8 @@ def delother(request, assignment_id, profile_id):
@permission_required('assignment.can_manage_application')
def set_active(request, assignment_id):
- item = Item.objects.get(itemassignment__assignment__id=assignment_id)
- item.set_active(False)
+ assignment = Assignment.objects.get(pk=assignment_id)
+ assignment.set_active()
return redirect(reverse('assignment_view', args=[assignment_id]))
@permission_required('assignment.can_manage_assignment')
diff --git a/openslides/beamer/api.py b/openslides/beamer/api.py
index 39f57d320..ae7f03374 100644
--- a/openslides/beamer/api.py
+++ b/openslides/beamer/api.py
@@ -1,3 +1,35 @@
+from system.api import config_set, config_get
+from beamer.models import ELEMENT
+
+
+def get_element_from_eid(eid):
+ try:
+ model, id = eid.split()
+ except ValueError:
+ return None # We need a elementError hier
+ return ELEMENT[model].objects.get(pk=id)
+
+
+def get_active_element(only_eid=False):
+ """
+ Returns the active element. If no element is active, or it can not find an Item,
+ it raise Element.DoesNotExist
+
+ if only_id is True, returns only the id of this item. Returns None if not Item
+ is active. Does not Raise Item.DoesNotExist
+ """
+ from beamer.models import Element
+ eid = config_get("presentation", None)
+
+ if only_eid:
+ return eid
+ return get_element_from_eid(eid)
+
+
+def element_register(prefix, model):
+ ELEMENT[prefix] = model
+
+
def assignment_votes(item):
votes = []
if item.type == "ItemAssignment":
diff --git a/openslides/beamer/models.py b/openslides/beamer/models.py
index 71a836239..8e81c967e 100644
--- a/openslides/beamer/models.py
+++ b/openslides/beamer/models.py
@@ -1,3 +1,40 @@
from django.db import models
-# Create your models here.
+from system.api import config_set, config_get
+
+ELEMENT = {}
+
+class Element(object):
+
+ def beamer(self):
+ """
+ Return a map with all Data for the Beamer
+ """
+ return {
+ 'element': self,
+ 'title': 'dummy-title',
+ }
+
+ @property
+ def eid(self):
+ """
+ Return the eid from this element
+ """
+ for key, value in ELEMENT.iteritems():
+ if type(self) == value:
+ return "%s %d" % (key, self.id)
+ return None
+
+ @property
+ def active(self):
+ """
+ Return True, if the the element is the active one.
+ """
+ from beamer.api import get_active_element
+ return True if get_active_element(only_eid=True) == self.eid else False
+
+ def set_active(self):
+ """
+ Appoint this item as the active one.
+ """
+ config_set("presentation", "%s %d" % (self.prefix, self.id))
diff --git a/openslides/beamer/templates/beamer/ItemPoll.html b/openslides/beamer/templates/beamer/ItemPoll.html
deleted file mode 100644
index fe26c9197..000000000
--- a/openslides/beamer/templates/beamer/ItemPoll.html
+++ /dev/null
@@ -1,19 +0,0 @@
-{% extends "beamer.html" %}
-{% block title %}{{ block.super }} - {{ item.title }}{% endblock %}
-{% block content %}
- {%trans "Poll about" %}:
- {{ item.title }}
-
-
- {% for option in item.poll.get_options %}
-
- {{ option }} |
- {{ option.voteyes }} |
- {% if item.poll.optiondecision %}
- {{ option.voteno }} |
- {{ option.voteundesided }} |
- {% endif %}
-
- {% endfor %}
-
-{% endblock %}
diff --git a/openslides/beamer/views.py b/openslides/beamer/views.py
index c1dfa9c73..269e738f7 100644
--- a/openslides/beamer/views.py
+++ b/openslides/beamer/views.py
@@ -24,11 +24,11 @@ from utils.template import render_block_to_string
from system.api import config_set, config_get
-from agenda.api import get_active_item, is_summary, children_list, \
+from agenda.api import is_summary, children_list, \
del_confirm_form_for_items
from agenda.models import Item
-from beamer.api import assignment_votes, assignment_polls
+from beamer.api import get_active_element, assignment_votes, assignment_polls
@permission_required('agenda.can_see_projector')
@@ -36,46 +36,51 @@ def beamer(request):
"""
Shows the active Slide.
"""
- data = {'ajax': 'on'}
- template = ''
try:
- item = get_active_item()
- votes = assignment_votes(item)
- polls = assignment_polls(item)
- if is_summary():
- items = item.children.filter(hidden=False)
- data['items'] = items
- data['title'] = item.title
- template = 'beamer/overview.html'
+ element = get_active_element()
+ except Item.DoesNotExist: #TODO: It has to be an Element.DoesNotExist
+ element = None
+
+
+ if element is None:
+ data = {}
+ else:
+ data = element.beamer()
+
+ data['ajax'] = 'on'
+
+ if element is None or (type(element) == Item and is_summary()):
+
+ if element is None:
+ items = Item.objects.filter(parent=None) \
+ .filter(hidden=False).order_by('weight')
+ data['title'] = _("Agenda")
else:
- data['item'] = item.cast()
- data['title'] = item.title
- data['votes'] = votes
- data['polls'] = polls
- template = 'beamer/%s.html' % (item.type)
- except Item.DoesNotExist:
- items = Item.objects.filter(parent=None).filter(hidden=False) \
- .order_by('weight')
+ items = element.children.filter(hidden=False)
+ data['title'] = element.title
data['items'] = items
- data['title'] = _("Agenda")
- template = 'beamer/overview.html'
+ data['template'] = 'beamer/AgendaSummary.html'
+
if request.is_ajax():
- content = render_block_to_string(template, 'content', data)
- jsondata = {'content': content,
- 'title': data['title'],
- 'time': datetime.now().strftime('%H:%M'),
- 'bigger': config_get('bigger'),
- 'up': config_get('up'),
- 'countdown_visible': config_get('countdown_visible'),
- 'countdown_time': config_get('agenda_countdown_time'),
- 'countdown_control': config_get('countdown_control'),
- }
+ content = render_block_to_string(data['template'], 'content', data)
+ jsondata = {
+ 'content': content,
+ 'title': data['title'],
+ 'time': datetime.now().strftime('%H:%M'),
+ 'bigger': config_get('bigger'),
+ 'up': config_get('up'),
+ 'countdown_visible': config_get('countdown_visible'),
+ 'countdown_time': config_get('agenda_countdown_time'),
+ 'countdown_control': config_get('countdown_control'),
+ }
return ajax_request(jsondata)
else:
- return render_to_response(template,
- data,
- context_instance=RequestContext(request))
+ return render_to_response(
+ data['template'],
+ data,
+ context_instance=RequestContext(request)
+ )
@permission_required('agenda.can_manage_agenda')