From c6a40f4dcb9bde0e2771322a6f7c70d349e51afb Mon Sep 17 00:00:00 2001
From: Emanuel Schuetze
Date: Wed, 28 Mar 2012 15:17:50 +0200
Subject: [PATCH] Reverted changset r281 from Default branch (because it's for
1.2-dev-branch only).
---
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 +-
openslides/agenda/urls.py | 7 +-
openslides/agenda/views.py | 43 +++++++----
openslides/application/models.py | 34 +++------
.../templates/application/view.html | 17 ++++-
openslides/application/views.py | 4 +-
openslides/assignment/models.py | 18 +----
.../assignment/templates/assignment/view.html | 13 +++-
openslides/assignment/views.py | 4 +-
openslides/beamer/api.py | 32 --------
openslides/beamer/models.py | 39 +---------
.../templates/beamer/ItemApplication.html} | 18 ++---
.../templates/beamer/ItemAssignment.html} | 22 +++---
.../beamer/templates/beamer/ItemPoll.html | 19 +++++
.../templates/beamer/ItemText.html} | 0
.../templates/beamer/overview.html} | 0
openslides/beamer/views.py | 75 +++++++++----------
21 files changed, 246 insertions(+), 223 deletions(-)
rename openslides/{application/templates/beamer/Application.html => beamer/templates/beamer/ItemApplication.html} (77%)
rename openslides/{assignment/templates/beamer/Assignment.html => beamer/templates/beamer/ItemAssignment.html} (82%)
create mode 100644 openslides/beamer/templates/beamer/ItemPoll.html
rename openslides/{agenda/templates/beamer/AgendaText.html => beamer/templates/beamer/ItemText.html} (100%)
rename openslides/{agenda/templates/beamer/AgendaSummary.html => beamer/templates/beamer/overview.html} (100%)
diff --git a/openslides/agenda/admin.py b/openslides/agenda/admin.py
index bfab6d8f6..52fa6ef0b 100644
--- a/openslides/agenda/admin.py
+++ b/openslides/agenda/admin.py
@@ -12,6 +12,7 @@
from django.contrib import admin
-from openslides.agenda.models import Item
+from openslides.agenda.models import Item, ItemText
admin.site.register(Item)
+admin.site.register(ItemText)
diff --git a/openslides/agenda/api.py b/openslides/agenda/api.py
index d07c306af..3c0b86ba0 100644
--- a/openslides/agenda/api.py
+++ b/openslides/agenda/api.py
@@ -15,7 +15,23 @@ from django.contrib import messages
from django.core.context_processors import csrf
from openslides.system.api import config_get
-from beamer.api import get_active_element
+
+
+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)
def is_summary():
@@ -24,7 +40,7 @@ def is_summary():
"""
from agenda.models import Item
try:
- get_active_element()
+ get_active_item()
except Item.DoesNotExist:
return True
if config_get('summary', False):
@@ -54,4 +70,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)
+ 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
diff --git a/openslides/agenda/forms.py b/openslides/agenda/forms.py
index fdd5b9c2d..69f761e75 100644
--- a/openslides/agenda/forms.py
+++ b/openslides/agenda/forms.py
@@ -13,7 +13,8 @@
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, ItemText, ItemApplication, \
+ ItemAssignment
class ItemFormText(ModelForm):
error_css_class = 'error'
@@ -25,6 +26,28 @@ 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):
@@ -38,3 +61,10 @@ 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 f0228ef53..40bebf658 100644
--- a/openslides/agenda/models.py
+++ b/openslides/agenda/models.py
@@ -18,45 +18,40 @@ except ImportError:
from django.db import models
from django.utils.translation import ugettext as _
-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
+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
-class Item(models.Model, Element):
+class Item(InheritanceCastModel):
"""
- An Agenda Item
+ The BasisItem.
+ Has all the attributes all Items need.
"""
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'
-
- def beamer(self):
+ @property
+ def active(self):
"""
- Return a map with all Data for the Beamer
+ Return True, if the the item is the active one.
"""
- return {
- 'item': self,
- 'title': self.title,
- 'template': 'beamer/AgendaText.html',
- }
+ return True if get_active_item(only_id=True) == self.id else False
@property
def active_parent(self):
"""
Return True if the item has a activ parent
"""
- if get_active_element(only_id=True) in \
+ if get_active_item(only_id=True) in \
[parent.id for parent in self.parents]:
return True
return False
@@ -65,7 +60,7 @@ class Item(models.Model, Element):
"""
Appoint this item as the active one.
"""
- Element.set_active(self)
+ config_set("presentation", self.id)
if summary:
config_set("summary", True)
else:
@@ -187,8 +182,32 @@ class Item(models.Model, Element):
)
-ItemText = Item # ItemText is Depricated
+class ItemText(Item):
+ """
+ An Item with a TextField.
+ """
+ text = models.TextField(null=True, blank=True, verbose_name=_("Text"))
+
+ class Meta:
+ pass
+class ItemApplication(Item):
+ """
+ An Item which is connected to an application.
+ """
+ application = models.ForeignKey(Application, verbose_name=_("Application"))
-element_register(Item.prefix, Item)
+
+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"))
diff --git a/openslides/agenda/templates/agenda/base_agenda.html b/openslides/agenda/templates/agenda/base_agenda.html
index 331f98d6f..8b4f73db0 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/agenda/urls.py b/openslides/agenda/urls.py
index c8cc08ea2..e890540db 100644
--- a/openslides/agenda/urls.py
+++ b/openslides/agenda/urls.py
@@ -40,9 +40,14 @@ urlpatterns = patterns('agenda.views',
url(r'^agenda/new/$', 'edit',
name='item_new_default'),
- url(r'^agenda/new$', 'edit',
+ url(r'^agenda/new/(?P
{% endif %}
-
-
- {%trans 'Beam Application' %}
-
+ {% if "createitem" in actions %}
+
+
+ {%trans 'New agenda item' %}
+
+ {% endif %}
+
+ {% if "activateitem" in actions %}
+
+
+ {%trans 'Show agenda item' %}
+
+ {% endif %}
{% if "acc" in actions or "rej" in actions %}
{% trans "Result after vote" %}:
diff --git a/openslides/application/views.py b/openslides/application/views.py
index c0f98b0a6..3c1f3f266 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):
- application = Application.objects.get(pk=application_id)
- application.set_active()
+ item = Item.objects.get(itemapplication__application__id=application_id)
+ item.set_active(False)
return redirect(reverse('application_view', args=[application_id]))
diff --git a/openslides/assignment/models.py b/openslides/assignment/models.py
index 337a6bb0b..899ca9af9 100644
--- a/openslides/assignment/models.py
+++ b/openslides/assignment/models.py
@@ -15,12 +15,8 @@ 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, Element):
- prefix = 'assignment'
+class Assignment(models.Model):
STATUS = (
('sea', _('Searching for candidates')),
('vot', _('Voting')),
@@ -117,16 +113,6 @@ class Assignment(models.Model, Element):
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':
@@ -144,5 +130,3 @@ class Assignment(models.Model, Element):
('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 2a5d56754..49f590f98 100644
--- a/openslides/assignment/templates/assignment/view.html
+++ b/openslides/assignment/templates/assignment/view.html
@@ -36,14 +36,21 @@
-
+ {% if not assignment.itemassignment_set.all %}
+
+
+
+ {%trans 'New agenda item' %}
+
+
+ {% else %}
- {%trans 'Beam assignment' %}
+ {%trans 'Show agenda item' %}
-
+ {% endif %}
{% endif %}
diff --git a/openslides/assignment/views.py b/openslides/assignment/views.py
index 70e7394e7..9c06ac1b4 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):
- assignment = Assignment.objects.get(pk=assignment_id)
- assignment.set_active()
+ item = Item.objects.get(itemassignment__assignment__id=assignment_id)
+ item.set_active(False)
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 ae7f03374..39f57d320 100644
--- a/openslides/beamer/api.py
+++ b/openslides/beamer/api.py
@@ -1,35 +1,3 @@
-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 8e81c967e..71a836239 100644
--- a/openslides/beamer/models.py
+++ b/openslides/beamer/models.py
@@ -1,40 +1,3 @@
from django.db import models
-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))
+# Create your models here.
diff --git a/openslides/application/templates/beamer/Application.html b/openslides/beamer/templates/beamer/ItemApplication.html
similarity index 77%
rename from openslides/application/templates/beamer/Application.html
rename to openslides/beamer/templates/beamer/ItemApplication.html
index cad4db3e1..8bbde4567 100644
--- a/openslides/application/templates/beamer/Application.html
+++ b/openslides/beamer/templates/beamer/ItemApplication.html
@@ -6,19 +6,19 @@
- {% trans "Application No." %} {{ application.number }}
+ {% trans "Application No." %} {{ item.application.number }}
{{ item.title }}
-
{{ application.public_version.text|linebreaks }}
- {% if application.public_version.reason %}
+ {{ item.application.public_version.text|linebreaks }}
+ {% if item.application.public_version.reason %}
{% trans "Reason" %}:
- {{ application.public_version.reason|linebreaks }}
+ {{ item.application.public_version.reason|linebreaks }}
{% endif %}
{% endblock %}
diff --git a/openslides/assignment/templates/beamer/Assignment.html b/openslides/beamer/templates/beamer/ItemAssignment.html
similarity index 82%
rename from openslides/assignment/templates/beamer/Assignment.html
rename to openslides/beamer/templates/beamer/ItemAssignment.html
index b0a6c38eb..6304d71f3 100644
--- a/openslides/assignment/templates/beamer/Assignment.html
+++ b/openslides/beamer/templates/beamer/ItemAssignment.html
@@ -5,31 +5,31 @@
{% endblock %}
{% block content %}
- {% trans "Election" %}: {{ assignment }}
+ {% trans "Election" %}: {{ item.assignment }}
- {% if assignment.status != "fin" %}
+ {% if item.assignment.status != "fin" %}
{% endif %}
- {% if not assignment.profile.exists %}
+ {% if not item.assignment.profile.exists %}
-
{{ assignment.description|linebreaks }}
+ {{ item.assignment.description|linebreaks }}
{% endif %}
- {% if assignment.profile.exists and assignment.status != "fin" %}
+ {% if item.assignment.profile.exists and item.assignment.status != "fin" %}
{% trans "Candidates" %}
- {% for profile in assignment.profile.all|dictsort:"user.first_name" %}
+ {% for profile in item.assignment.profile.all|dictsort:"user.first_name" %}
- {{ profile }}
{% empty %}
-
@@ -46,7 +46,7 @@
{% trans "Candidates" %} |
- {% for poll in assignment.poll_set.all %}
+ {% for poll in item.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/beamer/templates/beamer/ItemPoll.html b/openslides/beamer/templates/beamer/ItemPoll.html
new file mode 100644
index 000000000..fe26c9197
--- /dev/null
+++ b/openslides/beamer/templates/beamer/ItemPoll.html
@@ -0,0 +1,19 @@
+{% 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/agenda/templates/beamer/AgendaText.html b/openslides/beamer/templates/beamer/ItemText.html
similarity index 100%
rename from openslides/agenda/templates/beamer/AgendaText.html
rename to openslides/beamer/templates/beamer/ItemText.html
diff --git a/openslides/agenda/templates/beamer/AgendaSummary.html b/openslides/beamer/templates/beamer/overview.html
similarity index 100%
rename from openslides/agenda/templates/beamer/AgendaSummary.html
rename to openslides/beamer/templates/beamer/overview.html
diff --git a/openslides/beamer/views.py b/openslides/beamer/views.py
index 269e738f7..c1dfa9c73 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 is_summary, children_list, \
+from agenda.api import get_active_item, is_summary, children_list, \
del_confirm_form_for_items
from agenda.models import Item
-from beamer.api import get_active_element, assignment_votes, assignment_polls
+from beamer.api import assignment_votes, assignment_polls
@permission_required('agenda.can_see_projector')
@@ -36,51 +36,46 @@ def beamer(request):
"""
Shows the active Slide.
"""
+ data = {'ajax': 'on'}
+ template = ''
try:
- 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")
+ 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'
else:
- items = element.children.filter(hidden=False)
- data['title'] = element.title
+ 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')
data['items'] = items
- data['template'] = 'beamer/AgendaSummary.html'
-
+ data['title'] = _("Agenda")
+ template = 'beamer/overview.html'
if request.is_ajax():
- 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'),
- }
+ 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'),
+ }
return ajax_request(jsondata)
else:
- return render_to_response(
- data['template'],
- data,
- context_instance=RequestContext(request)
- )
+ return render_to_response(template,
+ data,
+ context_instance=RequestContext(request))
@permission_required('agenda.can_manage_agenda')