wcs: add card_id in get param for forms of category links (#58850) #122
|
@ -479,8 +479,28 @@ class CategoriesFilteringMixin:
|
|||
return url
|
||||
|
||||
|
||||
class CardIdMixin:
|
||||
def get_card_slug_from_sub_slug(self):
|
||||
if self.page.sub_slug:
|
||||
result = get_wcs_matching_card_model(self.page.sub_slug)
|
||||
if result:
|
||||
return result[0].split(':')[1]
|
||||
|
||||
def get_card_context_key(self):
|
||||
card_slug = self.get_card_slug_from_sub_slug()
|
||||
if card_slug:
|
||||
return '%s_id' % card_slug.replace('-', '_')
|
||||
|
||||
def get_card_id_from_context(self, context):
|
||||
card_key = self.get_card_context_key()
|
||||
if card_key:
|
||||
return context.get(card_key)
|
||||
|
||||
|
||||
@register_cell_class
|
||||
class WcsCurrentFormsCell(CategoriesAndWcsSiteValidityMixin, CategoriesFilteringMixin, WcsUserDataBaseCell):
|
||||
class WcsCurrentFormsCell(
|
||||
CategoriesAndWcsSiteValidityMixin, CategoriesFilteringMixin, CardIdMixin, WcsUserDataBaseCell
|
||||
):
|
||||
variable_name = 'user_forms'
|
||||
loading_message = _('Loading forms...')
|
||||
|
||||
|
@ -522,13 +542,10 @@ class WcsCurrentFormsCell(CategoriesAndWcsSiteValidityMixin, CategoriesFiltering
|
|||
if self.include_drafts:
|
||||
url += '&include-drafts=on'
|
||||
if self.filter_by_card:
|
||||
if self.page.sub_slug:
|
||||
result = get_wcs_matching_card_model(self.page.sub_slug)
|
||||
if result:
|
||||
card_slug = result[0].split(':')[1]
|
||||
card_id = context.get('%s_id' % card_slug)
|
||||
if card_id:
|
||||
url += '&related=carddef:%s:%s' % (card_slug, card_id)
|
||||
card_slug = self.get_card_slug_from_sub_slug()
|
||||
card_id = self.get_card_id_from_context(context)
|
||||
if card_slug and card_id:
|
||||
url += '&related=carddef:%s:%s' % (card_slug, card_id)
|
||||
url += '&limit=%s&sort=desc' % settings.WCS_USER_FORMS_LIMIT
|
||||
return url
|
||||
|
||||
|
@ -617,7 +634,7 @@ class WcsCurrentDraftsCell(CategoriesAndWcsSiteValidityMixin, CategoriesFilterin
|
|||
|
||||
|
||||
@register_cell_class
|
||||
class WcsFormsOfCategoryCell(WcsCommonCategoryCell, WcsBlurpMixin):
|
||||
class WcsFormsOfCategoryCell(WcsCommonCategoryCell, WcsBlurpMixin, CardIdMixin):
|
||||
ordering = models.CharField(
|
||||
_('Order'),
|
||||
max_length=20,
|
||||
|
@ -726,6 +743,11 @@ class WcsFormsOfCategoryCell(WcsCommonCategoryCell, WcsBlurpMixin):
|
|||
extra_context['more_forms'] = extra_context['forms'][self.limit :]
|
||||
extra_context['forms'] = extra_context['forms'][: self.limit]
|
||||
|
||||
card_key = self.get_card_context_key()
|
||||
card_id = self.get_card_id_from_context(context)
|
||||
if card_key and card_id:
|
||||
extra_context['card_id_param'] = '%s=%s' % (card_key, card_id)
|
||||
|
||||
return extra_context
|
||||
|
||||
def render_for_search(self):
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
|
||||
{% block form-link-pre %}{% endblock %}
|
||||
<a href="{{ form_url }}{% if not request_is_a_bot %}tryauth?cancelurl={{ absolute_uri|urlencode|iriencode }}{% endif %}"
|
||||
<a href="{{ form_url }}{% if not request_is_a_bot %}tryauth?cancelurl={{ absolute_uri|urlencode|iriencode }}{% if card_id_param %}&{{ card_id_param }}{% endif %}{% endif %}"
|
||||
{% if 'required-authentication' in form.css_classes %}
|
||||
title="{{ form_title }} - {% trans "authentication required" %}"
|
||||
{% endif %}
|
||||
|
|
|
@ -922,6 +922,7 @@ def test_forms_of_category_cell_render(mock_send, context):
|
|||
assert 'keyword-bar' in result
|
||||
assert '<p>a form description</p>' in result
|
||||
assert '<p>category 9 description</p>' not in result
|
||||
assert '?cancelurl=&' not in result
|
||||
|
||||
cell.ordering = 'popularity'
|
||||
cell.save()
|
||||
|
@ -968,6 +969,25 @@ def test_forms_of_category_cell_render(mock_send, context):
|
|||
assert '<h2>' in result
|
||||
context.pop('combo_display_even_empty_categories')
|
||||
|
||||
page.sub_slug = 'unknown'
|
||||
page.save()
|
||||
result = cell.render(context)
|
||||
assert '?cancelurl=&' not in result
|
||||
page.sub_slug = 'card_model_1_id'
|
||||
page.save()
|
||||
result = cell.render(context)
|
||||
assert '?cancelurl=&' not in result
|
||||
context['card_model_1_id'] = '42'
|
||||
result = cell.render(context)
|
||||
assert '?cancelurl=&card_model_1_id=42"' in result
|
||||
context.pop('card_id_param')
|
||||
page.sub_slug = 'card-e_id'
|
||||
|
||||
page.save()
|
||||
cell.refresh_from_db()
|
||||
context['card_e_id'] = '35'
|
||||
result = cell.render(context)
|
||||
assert '?cancelurl=&card_e_id=35"' in result
|
||||
|
||||
|
||||
@mock.patch('requests.Session.send', side_effect=mocked_requests_send)
|
||||
def test_forms_of_category_cancelurl(mock_send, app):
|
||||
|
|
|
@ -46,7 +46,7 @@ def test_card_cell_setup(mock_send, app, admin_user):
|
|||
('default:card_b:a-custom-view', 'test : Card B - foo bar'),
|
||||
('default:card_c', 'test : Card C'),
|
||||
('default:card_d', 'test : Card D'),
|
||||
('default:card_e', 'test : Card E'),
|
||||
('default:card-e', 'test : Card E'),
|
||||
('other:card_model_1', 'test2 : Card Model 1'),
|
||||
('other:card_model_1:foo', 'test2 : Card Model 1 - bar'),
|
||||
('other:card_model_2', 'test2 : Card Model 2'),
|
||||
|
@ -56,7 +56,7 @@ def test_card_cell_setup(mock_send, app, admin_user):
|
|||
('other:card_b:a-custom-view', 'test2 : Card B - foo bar'),
|
||||
('other:card_c', 'test2 : Card C'),
|
||||
('other:card_d', 'test2 : Card D'),
|
||||
('other:card_e', 'test2 : Card E'),
|
||||
('other:card-e', 'test2 : Card E'),
|
||||
]
|
||||
|
||||
form_display = WcsCardCellDisplayForm(instance=cell)
|
||||
|
@ -3695,7 +3695,7 @@ def test_page_edit_linked_card(mock_send, app, admin_user):
|
|||
'default:card_b',
|
||||
'default:card_c',
|
||||
'default:card_d',
|
||||
'default:card_e',
|
||||
'default:card-e',
|
||||
'other:card_model_1',
|
||||
'other:card_model_2',
|
||||
'other:card_model_3',
|
||||
|
@ -3703,7 +3703,7 @@ def test_page_edit_linked_card(mock_send, app, admin_user):
|
|||
'other:card_b',
|
||||
'other:card_c',
|
||||
'other:card_d',
|
||||
'other:card_e',
|
||||
'other:card-e',
|
||||
]
|
||||
resp.form['carddef_reference'] = 'default:card_model_3'
|
||||
resp = resp.form.submit().follow()
|
||||
|
|
|
@ -98,7 +98,7 @@ WCS_CARDDEFS_DATA = [
|
|||
{'title': 'Card B', 'slug': 'card_b', 'custom_views': [{'id': 'a-custom-view', 'text': 'foo bar'}]},
|
||||
{'title': 'Card C', 'slug': 'card_c'},
|
||||
{'title': 'Card D', 'slug': 'card_d'},
|
||||
{'title': 'Card E', 'slug': 'card_e'},
|
||||
{'title': 'Card E', 'slug': 'card-e'},
|
||||
]
|
||||
|
||||
WCS_CARDS_DATA = {
|
||||
|
|
Loading…
Reference in New Issue
avec un test pour le cas "slug avec tirets"