#1744: go back after chunk edit,
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Thu, 13 Oct 2011 11:41:06 +0000 (13:41 +0200)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Thu, 13 Oct 2011 11:41:06 +0000 (13:41 +0200)
#1758: don't open new tab for book edit

apps/catalogue/templates/catalogue/book_list/book.html
apps/catalogue/templates/catalogue/chunk_edit.html
apps/catalogue/views.py

index a45a357..00f2f1c 100755 (executable)
@@ -3,7 +3,7 @@
 {% if book.single %}
     {% with book.0 as chunk %}
     <tr>
-        <td><a target="_blank" href="{% url catalogue_book book.slug %}" title='{% trans "Book settings" %}'>[B]</a></td>
+        <td><a href="{% url catalogue_book book.slug %}" title='{% trans "Book settings" %}'>[B]</a></td>
         <td><a href="{% url catalogue_chunk_edit book.slug chunk.slug %}" title='{% trans "Chunk settings" %}'>[c]</a></td>
         <td><a target="_blank"
                     href="{% url wiki_editor book.slug %}">
@@ -22,7 +22,7 @@
     {% endwith %}
 {% else %}
     <tr>
-        <td><a target="_blank" href="{% url catalogue_book book.slug %}" title='{% trans "Book settings" %}'>[B]</a></td>
+        <td><a href="{% url catalogue_book book.slug %}" title='{% trans "Book settings" %}'>[B]</a></td>
         <td></td>
         <td>{{ book.title }}</td>
         <td></td><td></td>
index 3fffa96..94fe12b 100755 (executable)
@@ -2,7 +2,7 @@
 {% load i18n %}
 
 {% block leftcolumn %}
-       <form enctype="multipart/form-data" method="POST" action="">
+       <form enctype="multipart/form-data" method="POST" action="{% if go_next %}?next={{ go_next }}{% endif %}">
     {% csrf_token %}
        {{ form.as_p }}
 
index df7c2bf..cac1bd2 100644 (file)
@@ -2,6 +2,8 @@ from datetime import datetime
 import logging
 import os
 from StringIO import StringIO
+from urllib import unquote
+from urlparse import urlsplit, urlunsplit
 
 from django.contrib import auth
 from django.contrib.auth.models import User
@@ -11,6 +13,7 @@ from django.db.models import Count, Q
 from django import http
 from django.http import Http404
 from django.shortcuts import get_object_or_404, render
+from django.utils.encoding import iri_to_uri
 from django.utils.http import urlquote_plus
 from django.utils.translation import ugettext_lazy as _
 from django.views.decorators.http import require_POST
@@ -359,12 +362,23 @@ def chunk_edit(request, slug, chunk):
         form = forms.ChunkForm(request.POST, instance=doc)
         if form.is_valid():
             form.save()
-            return http.HttpResponseRedirect(doc.book.get_absolute_url())
+            go_next = request.GET.get('next', None)
+            if go_next:
+                go_next = urlquote_plus(unquote(iri_to_uri(go_next)), safe='/?=&')
+            else:
+                go_next = doc.book.get_absolute_url()
+            return http.HttpResponseRedirect(go_next)
     else:
         form = forms.ChunkForm(instance=doc)
+
+    parts = urlsplit(request.META['HTTP_REFERER'])
+    parts = ['', ''] + list(parts[2:])
+    go_next = urlquote_plus(urlunsplit(parts))
+
     return direct_to_template(request, "catalogue/chunk_edit.html", extra_context={
         "chunk": doc,
         "form": form,
+        "go_next": go_next,
     })