#158: Added success notification for ItemCreate/ItemUpdate View.

This commit is contained in:
Emanuel Schuetze 2012-04-27 21:36:12 +02:00
parent 710882c28a
commit 822264ef7b
2 changed files with 19 additions and 1 deletions

View File

@ -5,7 +5,11 @@
{% block title %}{{ block.super }} - {%trans "Item" %}{% endblock %}
{% block content %}
<h1>{%trans "Edit item" %}</h1>
{% if item %}
<h1>{%trans "Edit item" %}</h1>
{% else %}
<h1>{%trans "New item" %}</h1>
{% endif %}
<form action="" method="post">{% csrf_token %}
{{ form.as_p }}
<p>

View File

@ -105,6 +105,13 @@ class ItemUpdate(UpdateView):
context_object_name = 'item'
form_class = ItemForm
success_url = 'item_overview'
apply_url = 'item_edit'
def get_success_url(self):
messages.success(self.request, _("Item <b>%s</b> was successfully modified.") % self.request.POST['title'])
if 'apply' in self.request.POST:
return ''
return reverse(super(UpdateView, self).get_success_url())
class ItemCreate(CreateView):
@ -114,6 +121,13 @@ class ItemCreate(CreateView):
context_object_name = 'item'
form_class = ItemForm
success_url = 'item_overview'
apply_url = 'item_edit'
def get_success_url(self):
messages.success(self.request, _("Item <b>%s</b> was successfully created.") % self.request.POST['title'])
if 'apply' in self.request.POST:
return reverse(self.get_apply_url(), args=[self.object.id])
return reverse(super(CreateView, self).get_success_url())
class ItemDelete(DeleteView):