Reverted changset r282 from Default branch (because it's for

1.2-dev-branch only).
This commit is contained in:
Emanuel Schuetze 2012-03-28 15:17:29 +02:00
parent 3472563ea1
commit a06d20a8d8
3 changed files with 30 additions and 7 deletions

View File

@ -2,7 +2,25 @@
{% block title %}{{ block.super }} - {%trans "Item" %}{% endblock %} {% block title %}{{ block.super }} - {%trans "Item" %}{% endblock %}
{% block content %} {% block content %}
<h1>{%trans "Edit item" %}</h1> {% if item %}
<h1>{%trans "Edit item" %}</h1>
{% else %}
<h1>{%trans "New item" %}</h1>
<p>{%trans "Choose item type:" %}</p>
<p>
<a href="{% url item_new 'ItemText' %}"
{% ifequal request.path '/agenda/new/ItemText/' %}style='font-size:15px; font-weight:bold;'{% endifequal %}
>{%trans "Item of Text" %}</a> |
<a href="{% url item_new 'ItemApplication' %}"
{% ifequal request.path '/agenda/new/ItemApplication/' %}style='font-size:15px; font-weight:bold;'{% endifequal %}
>{%trans "Item of Application" %}</a> |
<a href="{% url item_new 'ItemAssignment' %}"
{% ifequal request.path '/agenda/new/ItemAssignment/' %}style='font-size:15px; font-weight:bold;'{% endifequal %}
>{%trans "Item of Election" %}</a>
</p>
{% endif %}
<form action="" method="post">{% csrf_token %} <form action="" method="post">{% csrf_token %}
{{ form.as_p }} {{ form.as_p }}
<button class="button" type="submit"> <button class="button" type="submit">

View File

@ -128,13 +128,13 @@ def set_closed(request, item_id, closed=True):
@permission_required('agenda.can_manage_agenda') @permission_required('agenda.can_manage_agenda')
@template('agenda/edit.html') @template('agenda/edit.html')
def edit(request, item_id=None): def edit(request, item_id=None, form='ItemText', default=None):
""" """
Show a form to edit an existing Item, or create a new one. Show a form to edit an existing Item, or create a new one.
""" """
if item_id is not None: if item_id is not None:
try: try:
item = Item.objects.get(pk=item_id) item = Item.objects.get(id=item_id).cast()
except Item.DoesNotExist: except Item.DoesNotExist:
messages.error(request, _('Item ID %d does not exist.') % int(item_id)) messages.error(request, _('Item ID %d does not exist.') % int(item_id))
return redirect(reverse('item_overview')) return redirect(reverse('item_overview'))
@ -142,14 +142,21 @@ def edit(request, item_id=None):
item = None item = None
if request.method == 'POST': if request.method == 'POST':
form = ItemFormText(request.POST, instance=item) if item_id is None:
form = MODELFORM[form](request.POST)
else:
form = item.edit_form(request.POST)
if form.is_valid(): if form.is_valid():
item = form.save() item = form.save()
if item_id is None: if item_id is None:
messages.success(request, _('New item was successfully created.')) messages.success(request, _('New item was successfully created.'))
if "application" in request.POST:
item.application.writelog(_('Agenda item created'), request.user)
else: else:
messages.success(request, _('Item was successfully modified.')) messages.success(request, _('Item was successfully modified.'))
if "application" in request.POST:
item.application.writelog(_('Agenda item modified'), request.user)
if not 'apply' in request.POST: if not 'apply' in request.POST:
return redirect(reverse('item_overview')) return redirect(reverse('item_overview'))
if item_id is None: if item_id is None:
@ -157,7 +164,7 @@ def edit(request, item_id=None):
else: else:
messages.error(request, _('Please check the form for errors.')) messages.error(request, _('Please check the form for errors.'))
else: else:
form = ItemFormText(instance=item) form = ItemFormText()
return { 'form': form, return { 'form': form,
'item': item } 'item': item }

View File

@ -7,8 +7,6 @@ def get_element_from_eid(eid):
model, id = eid.split() model, id = eid.split()
except ValueError: except ValueError:
return None # We need a elementError hier return None # We need a elementError hier
except AttributeError:
return None
return ELEMENT[model].objects.get(pk=id) return ELEMENT[model].objects.get(pk=id)