From e2efa3c922eb796cf57f22fa4e2780defd8b7a20 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Thu, 13 Oct 2011 13:41:06 +0200 Subject: [PATCH] #1744: go back after chunk edit, #1758: don't open new tab for book edit --- .../templates/catalogue/book_list/book.html | 4 ++-- .../templates/catalogue/chunk_edit.html | 2 +- apps/catalogue/views.py | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/apps/catalogue/templates/catalogue/book_list/book.html b/apps/catalogue/templates/catalogue/book_list/book.html index a45a3578..00f2f1c1 100755 --- a/apps/catalogue/templates/catalogue/book_list/book.html +++ b/apps/catalogue/templates/catalogue/book_list/book.html @@ -3,7 +3,7 @@ {% if book.single %} {% with book.0 as chunk %} - [B] + [B] [c] @@ -22,7 +22,7 @@ {% endwith %} {% else %} - [B] + [B] {{ book.title }} diff --git a/apps/catalogue/templates/catalogue/chunk_edit.html b/apps/catalogue/templates/catalogue/chunk_edit.html index 3fffa963..94fe12bc 100755 --- a/apps/catalogue/templates/catalogue/chunk_edit.html +++ b/apps/catalogue/templates/catalogue/chunk_edit.html @@ -2,7 +2,7 @@ {% load i18n %} {% block leftcolumn %} -
+ {% csrf_token %} {{ form.as_p }} diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index df7c2bf3..cac1bd2b 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -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, }) -- 2.20.1