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 @@