From 8fa65f60d1a8e18e77acc6377c989c5e52b87208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sat, 8 Dec 2018 15:24:11 +0100 Subject: [PATCH] misc: add page absolute URI to cell rendering context (#28777 --- .../wcs/templates/combo/wcs/backoffice_submission.html | 2 +- combo/data/models.py | 1 + combo/public/views.py | 5 ++++- tests/test_public.py | 7 +++++-- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/combo/apps/wcs/templates/combo/wcs/backoffice_submission.html b/combo/apps/wcs/templates/combo/wcs/backoffice_submission.html index fc1b7dd1..83e431b7 100644 --- a/combo/apps/wcs/templates/combo/wcs/backoffice_submission.html +++ b/combo/apps/wcs/templates/combo/wcs/backoffice_submission.html @@ -9,7 +9,7 @@ {% for category_formdefs in categories_formdefs %}
  • {{ category_formdefs.grouper }}

  • {% for formdef in category_formdefs.list|dictsort:"title" %} -
  • {{formdef.title}}
  • +
  • {{formdef.title}}
  • {% endfor %} {% endfor %} diff --git a/combo/data/models.py b/combo/data/models.py index f63c4a1a..9dd42952 100644 --- a/combo/data/models.py +++ b/combo/data/models.py @@ -692,6 +692,7 @@ class CellBase(six.with_metaclass(CellMeta, models.Model)): 'site_base': request.build_absolute_uri('/')[:-1], 'synchronous': True, 'user': None, # compat + 'absolute_uri': request.build_absolute_uri, } if not self.is_relevant(context): return '' diff --git a/combo/public/views.py b/combo/public/views.py index 6fa07949..95f7d808 100644 --- a/combo/public/views.py +++ b/combo/public/views.py @@ -143,6 +143,7 @@ def render_cell(request, cell): 'cell': cell, 'synchronous': True, 'site_base': request.build_absolute_uri('/')[:-1], + 'absolute_uri': request.build_absolute_uri } if request.GET.get('ctx'): context.update(signing.loads(request.GET['ctx'])) @@ -356,7 +357,9 @@ def empty_site(request): def page(request): - request.extra_context_data = {} + request.extra_context_data = { + 'absolute_uri': request.build_absolute_uri() + } url = request.path_info parts = [x for x in request.path_info.strip('/').split('/') if x] if len(parts) == 1 and parts[0] == 'index': diff --git a/tests/test_public.py b/tests/test_public.py index 6fde354d..7ff3d4e0 100644 --- a/tests/test_public.py +++ b/tests/test_public.py @@ -727,7 +727,7 @@ def test_sub_slug(app, john_doe, jane_doe): cell.save() cell2 = JsonCell(page=page3, url='http://example.net', order=0, placeholder='content') - cell2.template_string = 'AA{{ blah }}BB' + cell2.template_string = 'AA{{ blah }}BB{{ absolute_uri }}CC' cell2.save() with mock.patch('combo.utils.requests.get') as requests_get: @@ -746,7 +746,10 @@ def test_sub_slug(app, john_doe, jane_doe): # check sub page resp = app.get('/users/whatever/plop/', status=404) resp = app.get('/users/whatever/blah/', status=200) - assert 'AAwhateverBB' in resp.text + cell_url = re.findall(r'data-ajax-cell-url="(.*)"', resp.text)[0] + extra_ctx = re.findall(r'data-extra-context="(.*)"', resp.text)[0] + resp = app.get(cell_url + '?ctx=' + extra_ctx) + assert resp.text == 'AAwhateverBBhttp://testserver/users/whatever/blah/CC' # custom behaviour for , it will add the user to context page2.sub_slug = '(?P[0-9]+)' -- 2.20.0.rc2