From 575da78f3a2b8d0ca3f36f5da97a81ba09c814b7 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Fri, 14 Jun 2013 09:00:37 +0200 Subject: [PATCH] Editview for releated agenda items. Releated Agenda Items need there own edit view to edit some agenda specifc values. Also added a new filter 'trans' to translate variables. Fixes #710 --- openslides/agenda/forms.py | 13 +++++++++++-- openslides/agenda/models.py | 10 ++-------- openslides/agenda/templates/agenda/edit.html | 10 ++++++++++ openslides/agenda/views.py | 9 +++++++-- openslides/utils/templatetags/tags.py | 6 ++++++ 5 files changed, 36 insertions(+), 12 deletions(-) diff --git a/openslides/agenda/forms.py b/openslides/agenda/forms.py index 783398765..00a48281e 100644 --- a/openslides/agenda/forms.py +++ b/openslides/agenda/forms.py @@ -21,7 +21,7 @@ from openslides.utils.person.forms import PersonFormField from .models import Item, Speaker -class ItemForm(forms.ModelForm, CssClassMixin): +class ItemForm(CssClassMixin, forms.ModelForm): """ Form to create of update an item. """ @@ -40,7 +40,16 @@ class ItemForm(forms.ModelForm, CssClassMixin): exclude = ('closed', 'weight', 'related_sid') -class ItemOrderForm(forms.Form, CssClassMixin): +class RelatedItemForm(ItemForm): + """ + Form to update an related item. + """ + class Meta: + model = Item + exclude = ('closed', 'type', 'weight', 'related_sid', 'title', 'text') + + +class ItemOrderForm(CssClassMixin, forms.Form): """ Form to change the order of the items. """ diff --git a/openslides/agenda/models.py b/openslides/agenda/models.py index 711d58639..8d347f381 100644 --- a/openslides/agenda/models.py +++ b/openslides/agenda/models.py @@ -114,19 +114,13 @@ class Item(MPTTModel, SlideMixin): def get_absolute_url(self, link='detail'): """ - Return the URL to this item. By default it is the link to its - view or the view of a related object. + Return the URL to this item. - The link can be: - * detail or view - * update or edit - * delete + The link can be detail, update or delete. """ if link == 'detail' or link == 'view': return reverse('item_view', args=[str(self.id)]) if link == 'update' or link == 'edit': - if self.related_sid: - return self.get_related_slide().get_absolute_url(link) return reverse('item_edit', args=[str(self.id)]) if link == 'delete': return reverse('item_delete', args=[str(self.id)]) diff --git a/openslides/agenda/templates/agenda/edit.html b/openslides/agenda/templates/agenda/edit.html index 9d5a8065b..081caaed5 100644 --- a/openslides/agenda/templates/agenda/edit.html +++ b/openslides/agenda/templates/agenda/edit.html @@ -1,6 +1,7 @@ {% extends "base.html" %} {% load i18n %} +{% load tags %} {% block title %} {% if item %} @@ -22,6 +23,15 @@ {% trans "Back to overview" %} +

+ {% if item.related_sid %} + + {% blocktrans with type=item.get_related_type|trans name=item.get_related_slide %} + Edit {{ type }} {{ name }} + {% endblocktrans %} + + {% endif %} +

{% csrf_token %} {% include "form.html" %}

diff --git a/openslides/agenda/views.py b/openslides/agenda/views.py index e839aaa47..cebeebbc7 100644 --- a/openslides/agenda/views.py +++ b/openslides/agenda/views.py @@ -32,7 +32,7 @@ from openslides.utils.utils import html_strong from openslides.projector.api import get_active_slide, get_slide_from_sid from openslides.projector.projector import Widget, SLIDE from .models import Item, Speaker -from .forms import ItemOrderForm, ItemForm, AppendSpeakerForm +from .forms import ItemOrderForm, ItemForm, AppendSpeakerForm, RelatedItemForm class Overview(TemplateView): @@ -187,9 +187,14 @@ class ItemUpdate(UpdateView): template_name = 'agenda/edit.html' model = Item context_object_name = 'item' - form_class = ItemForm success_url_name = 'item_overview' + def get_form_class(self): + if self.object.related_sid is None: + return ItemForm + else: + return RelatedItemForm + class ItemCreate(CreateView): """ diff --git a/openslides/utils/templatetags/tags.py b/openslides/utils/templatetags/tags.py index cb814067a..8592696ef 100644 --- a/openslides/utils/templatetags/tags.py +++ b/openslides/utils/templatetags/tags.py @@ -11,6 +11,7 @@ """ from django import template +from django.utils.translation import ugettext as _ from openslides.config.api import config @@ -27,6 +28,11 @@ def get_config(key): return config[key] +@register.filter +def trans(value): + return _(value) + + @register.simple_tag def model_url(object, link='view'): # TODO: Rename to object_url