wcs: add ?cancelurl query parameter to form links (#60114)

This commit is contained in:
Frédéric Péters 2021-12-28 10:11:04 +01:00
parent 2ee49ebd45
commit c122f8892e
2 changed files with 11 additions and 3 deletions

View File

@ -18,6 +18,7 @@
import collections
import copy
import logging
import urllib.parse
from django.conf import settings
from django.contrib.postgres.fields import JSONField
@ -124,10 +125,13 @@ class WcsFormCell(CellBase):
populate_cache()
def get_cell_extra_context(self, context):
request = context.get('request')
context = super().get_cell_extra_context(context)
context['slug'] = self.formdef_reference.split(':')[-1]
context['title'] = self.cached_title
context['url'] = self.cached_url + 'tryauth'
if request:
context['url'] += '?cancelurl=%s' % urllib.parse.quote(request.build_absolute_uri())
if self.cached_json:
context['description'] = mark_safe(self.cached_json.get('description', ''))
context['css_classes'] = get_formdef_css_classes(self.cached_json)

View File

@ -2770,14 +2770,18 @@ def test_list_of_links_with_form_render(app):
page=page,
placeholder=cell.link_placeholder,
cached_title='A title',
cached_url='http://example.com',
cached_url='http://example.com/',
cached_json={'keywords': ['bar']},
order=0,
)
resp = app.get('/test_list_of_links_with_form_render/')
assert 'A title' in resp
assert 'keyword-bar' in resp
assert PyQuery(resp.text).find('.links-list a').text() == 'A title'
assert PyQuery(resp.text).find('.links-list li').attr('class') == 'keyword-bar'
assert (
PyQuery(resp.text).find('.links-list a').attr('href')
== 'http://example.com/tryauth?cancelurl=http%3A//testserver/test_list_of_links_with_form_render/'
)
def test_view_page_with_wcs_cells_num_queries(app, admin_user):