From c678d0cfedf0fbe1d3a4274d851ddc7dd676c213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20Irl=C3=A4nder?= Date: Mon, 18 Sep 2017 14:27:14 +0200 Subject: [PATCH 1/3] Also render backurl if the application is in readmode. Further maintain a previous set backurl and use this from the session in favour of the current_route_path. --- ringo/lib/renderer/form.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ringo/lib/renderer/form.py b/ringo/lib/renderer/form.py index 3219c435..f809f8f3 100644 --- a/ringo/lib/renderer/form.py +++ b/ringo/lib/renderer/form.py @@ -71,8 +71,9 @@ def get_link_url(item, request, actionname=None, backurl=False): return None query = {} - if not readmode and backurl: - query['backurl'] = request.current_route_path() + if backurl: + clazz = request.context.__model__ + query['backurl'] = request.session.get('%s.backurl' % clazz) or request.current_route_path() return request.route_path(route_name, id=item.id, _query=query) return None From f64b1fa3718b7bc8d04176dbe30723ddc4fc7911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20Irl=C3=A4nder?= Date: Mon, 18 Sep 2017 14:28:57 +0200 Subject: [PATCH 2/3] Keep value of backurl in case it has been set. --- ringo/lib/helpers/misc.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ringo/lib/helpers/misc.py b/ringo/lib/helpers/misc.py index 01fe2a72..aacbff97 100644 --- a/ringo/lib/helpers/misc.py +++ b/ringo/lib/helpers/misc.py @@ -343,7 +343,13 @@ def get_action_url(request, item, action): """ route_name = get_action_routename(item, action) if isinstance(item, object): - return request.route_path(route_name, id=item.id) + # If backurl is set + clazz = request.context.__model__ + backurl = request.session.get('%s.backurl' % clazz) + query = {} + if backurl: + query['backurl'] = backurl + return request.route_path(route_name, id=item.id, _query=query) # TODO: Is this code ever reached. See testcase (ti) <2014-02-25 23:17> return request.route_path(route_name) From 7d6464ea2c9a0646ee6528b542d045d79db4573f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20Irl=C3=A4nder?= Date: Mon, 18 Sep 2017 14:45:56 +0200 Subject: [PATCH 3/3] Explicit check if the context has a __model__ This is not true in test scenario where the request.context is only a Mock. --- ringo/lib/helpers/misc.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ringo/lib/helpers/misc.py b/ringo/lib/helpers/misc.py index aacbff97..876db0a8 100644 --- a/ringo/lib/helpers/misc.py +++ b/ringo/lib/helpers/misc.py @@ -344,8 +344,11 @@ def get_action_url(request, item, action): route_name = get_action_routename(item, action) if isinstance(item, object): # If backurl is set - clazz = request.context.__model__ - backurl = request.session.get('%s.backurl' % clazz) + if hasattr(request.context, "__model__"): + clazz = request.context.__model__ + backurl = request.session.get('%s.backurl' % clazz) + else: + backurl = None query = {} if backurl: query['backurl'] = backurl