Merge pull request #735 from ostcar/Issue-710

Editview for releated agenda items.
This commit is contained in:
Oskar Hahn 2013-06-15 15:55:32 -07:00
commit 69f7e22320
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 from .models import Item, Speaker
class ItemForm(forms.ModelForm, CssClassMixin): class ItemForm(CssClassMixin, forms.ModelForm):
""" """
Form to create of update an item. Form to create of update an item.
""" """
@ -40,7 +40,16 @@ class ItemForm(forms.ModelForm, CssClassMixin):
exclude = ('closed', 'weight', 'related_sid') 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. 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'): def get_absolute_url(self, link='detail'):
""" """
Return the URL to this item. By default it is the link to its Return the URL to this item.
view or the view of a related object.
The link can be: The link can be detail, update or delete.
* detail or view
* update or edit
* delete
""" """
if link == 'detail' or link == 'view': if link == 'detail' or link == 'view':
return reverse('item_view', args=[str(self.id)]) return reverse('item_view', args=[str(self.id)])
if link == 'update' or link == 'edit': 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)]) return reverse('item_edit', args=[str(self.id)])
if link == 'delete': if link == 'delete':
return reverse('item_delete', args=[str(self.id)]) return reverse('item_delete', args=[str(self.id)])

View File

@ -1,6 +1,7 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load i18n %} {% load i18n %}
{% load tags %}
{% block title %} {% block title %}
{% if item %} {% 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> <a href="{% url 'item_overview' %}" class="btn btn-mini"><i class="icon-chevron-left"></i> {% trans "Back to overview" %}</a>
</small> </small>
</h1> </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 %} <form action="" method="post">{% csrf_token %}
{% include "form.html" %} {% include "form.html" %}
<p> <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.api import get_active_slide, get_slide_from_sid
from openslides.projector.projector import Widget, SLIDE from openslides.projector.projector import Widget, SLIDE
from .models import Item, Speaker from .models import Item, Speaker
from .forms import ItemOrderForm, ItemForm, AppendSpeakerForm from .forms import ItemOrderForm, ItemForm, AppendSpeakerForm, RelatedItemForm
class Overview(TemplateView): class Overview(TemplateView):
@ -187,9 +187,14 @@ class ItemUpdate(UpdateView):
template_name = 'agenda/edit.html' template_name = 'agenda/edit.html'
model = Item model = Item
context_object_name = 'item' context_object_name = 'item'
form_class = ItemForm
success_url_name = 'item_overview' 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): class ItemCreate(CreateView):
""" """

View File

@ -11,6 +11,7 @@
""" """
from django import template from django import template
from django.utils.translation import ugettext as _
from openslides.config.api import config from openslides.config.api import config
@ -27,6 +28,11 @@ def get_config(key):
return config[key] return config[key]
@register.filter
def trans(value):
return _(value)
@register.simple_tag @register.simple_tag
def model_url(object, link='view'): def model_url(object, link='view'):
# TODO: Rename to object_url # TODO: Rename to object_url