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
This commit is contained in:
Oskar Hahn 2013-06-14 09:00:37 +02:00
parent 746a8b371a
commit 575da78f3a
5 changed files with 36 additions and 12 deletions

View File

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

View File

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

View File

@ -1,6 +1,7 @@
{% extends "base.html" %}
{% load i18n %}
{% load tags %}
{% block title %}
{% if item %}
@ -22,6 +23,15 @@
<a href="{% url 'item_overview' %}" class="btn btn-mini"><i class="icon-chevron-left"></i> {% trans "Back to overview" %}</a>
</small>
</h1>
<p>
{% if item.related_sid %}
<a href="{% model_url item.get_related_slide 'update' %}" class="btn btn-small">
{% blocktrans with type=item.get_related_type|trans name=item.get_related_slide %}
Edit {{ type }} {{ name }}
{% endblocktrans %}
</a>
{% endif %}
</p>
<form action="" method="post">{% csrf_token %}
{% include "form.html" %}
<p>

View File

@ -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):
"""

View File

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