0001-wcs-uniformize-forms-links-rendering-65846.patch
combo/apps/wcs/models.py | ||
---|---|---|
18 | 18 |
import collections |
19 | 19 |
import copy |
20 | 20 |
import logging |
21 |
import urllib.parse |
|
22 | 21 | |
23 | 22 |
from django.conf import settings |
24 | 23 |
from django.contrib.postgres.fields import JSONField |
... | ... | |
138 | 137 |
populate_cache() |
139 | 138 | |
140 | 139 |
def get_cell_extra_context(self, context): |
141 |
request = context.get('request')
|
|
142 |
context = super().get_cell_extra_context(context)
|
|
143 |
context['slug'] = self.formdef_reference.split(':')[-1]
|
|
144 |
context['title'] = self.cached_title
|
|
145 |
context['url'] = self.cached_url
|
|
146 |
if not is_a_bot(request):
|
|
147 |
context['url'] += 'tryauth?cancelurl=%s' % urllib.parse.quote(request.build_absolute_uri()) |
|
140 |
extra_context = super().get_cell_extra_context(context)
|
|
141 |
extra_context['slug'] = self.formdef_reference.split(':')[-1]
|
|
142 |
extra_context['title'] = self.cached_title
|
|
143 |
extra_context['url'] = self.cached_url
|
|
144 |
extra_context['request_is_a_bot'] = is_a_bot(context.get('request'))
|
|
145 |
extra_context['is_form'] = True
|
|
146 | ||
148 | 147 |
if self.cached_json: |
149 |
context['description'] = mark_safe(self.cached_json.get('description', '')) |
|
150 |
context['css_classes'] = get_formdef_css_classes(self.cached_json) |
|
148 |
extra_context['description'] = mark_safe(self.cached_json.get('description', ''))
|
|
149 |
extra_context['css_classes'] = get_formdef_css_classes(self.cached_json)
|
|
151 | 150 |
for attribute in self.cached_json: |
152 | 151 |
if attribute not in context: |
153 |
context[attribute] = self.cached_json.get(attribute) |
|
154 |
return context |
|
152 |
extra_context[attribute] = self.cached_json.get(attribute)
|
|
153 |
return extra_context
|
|
155 | 154 | |
156 | 155 |
def get_additional_label(self): |
157 | 156 |
if not self.cached_title: |
combo/apps/wcs/templates/combo/wcs/form.html | ||
---|---|---|
1 | 1 |
{% block cell-content %} |
2 |
<div class="wcs-form-{{slug}}"><a href="{{ url }}">{{ title }}</a> |
|
3 |
{% if description %} |
|
4 |
<div class="description"> |
|
5 |
{{ description }} |
|
6 |
</div> |
|
7 |
{% endif %} |
|
2 |
<div class="wcs-form-{{slug}}"> |
|
3 |
{% include "combo/wcs/form_link_fragment.html" %} |
|
8 | 4 |
</div> |
9 | 5 |
{% endblock %} |
combo/apps/wcs/templates/combo/wcs/form_link_fragment.html | ||
---|---|---|
1 |
{% firstof form.url url as form_url %} |
|
2 |
{% firstof form.title title as form_title %} |
|
3 |
{% autoescape off %} |
|
4 |
{% firstof form.description description as form_description %} |
|
5 |
{% endautoescape %} |
|
6 | ||
7 | ||
1 | 8 |
{% block form-link-pre %}{% endblock %} |
2 |
<a href="{{ form.url }}{% if not request_is_a_bot %}tryauth?cancelurl={{ uri|iriencode }}{% endif %}">{% block form-link-title %}{{ form.title }}{% endblock %}</a>
|
|
3 |
{% if form.description %}
|
|
4 |
<div class="description">{% block form-link-description %}{{ form.description|safe }}{% endblock %}</div>
|
|
9 |
<a href="{{ form_url }}{% if not request_is_a_bot %}tryauth?cancelurl={{ absolute_uri|urlencode|iriencode }}{% endif %}">{% block form-link-title %}{{ form_title }}{% endblock %}</a>
|
|
10 |
{% if form_description %}
|
|
11 |
<div class="description">{% block form-link-description %}{{ form_description|safe }}{% endblock %}</div>
|
|
5 | 12 |
{% endif %} |
6 | 13 |
{% block form-link-post %}{% endblock %} |
7 | 14 |
combo/apps/wcs/templates/combo/wcs/forms_of_category.html | ||
---|---|---|
15 | 15 |
{% block cell-top-content %}{% endblock cell-top-content %} |
16 | 16 |
<ul> |
17 | 17 |
{% for form in forms %} |
18 |
<li class="{{ form.css_classes|join:" " }}">{% include "combo/wcs/form_link_fragment.html" with form=form uri=absolute_uri %}</li>
|
|
18 |
<li class="{{ form.css_classes|join:" " }}">{% include "combo/wcs/form_link_fragment.html" %}</li> |
|
19 | 19 |
{% endfor %} |
20 | 20 |
{% if more_forms %} |
21 | 21 |
<li class="add-more-items"> |
... | ... | |
28 | 28 |
<ul style="display: none" class="more-items" id="more-items-{{ cell.get_reference }}" aria-labelledby="btn-wcs-more-items-{{ cell.get_reference }}"> |
29 | 29 |
{% for form in more_forms %} |
30 | 30 |
<li class="more-items--item {{ form.css_classes|join:" " }}"> |
31 |
{% include "combo/wcs/form_link_fragment.html" with form=form uri=absolute_uri %}
|
|
31 |
{% include "combo/wcs/form_link_fragment.html" %} |
|
32 | 32 |
</li> |
33 | 33 |
{% endfor %} |
34 | 34 |
{% endif %} |
combo/public/templates/combo/link-list-cell.html | ||
---|---|---|
9 | 9 |
{% block cell-top-content %}{% endblock cell-top-content %} |
10 | 10 |
<ul> |
11 | 11 |
{% for link in links %} |
12 |
<li class="{{ link.css_classes|default:""|join:" " }}{% if link.cell.extra_css_class %} {{ link.cell.extra_css_class }}{% endif %}"><a href="{{ link.url }}">{{ link.title }}</a></li> |
|
12 |
<li class="{{ link.css_classes|default:""|join:" " }}{% if link.cell.extra_css_class %} {{ link.cell.extra_css_class }}{% endif %}">{% if link.is_form %} |
|
13 |
{% include "combo/wcs/form_link_fragment.html" with form=link %} |
|
14 |
{% else %} |
|
15 |
<a href="{{ link.url }}">{{ link.title }}</a> |
|
16 |
{% endif %}</li> |
|
13 | 17 |
{% endfor %} |
14 | 18 |
{% if more_links %} |
15 | 19 |
<li class="add-more-items"> |
tests/wcs/test_all.py | ||
---|---|---|
75 | 75 |
# check content provided to search engine |
76 | 76 |
assert cell.render_for_search() == '' |
77 | 77 |
assert cell.get_external_links_data() == [ |
78 |
{'title': 'form title', 'url': 'http://127.0.0.1:8999/form-title/', 'text': 'foo bar'} |
|
78 |
{ |
|
79 |
'title': 'form title', |
|
80 |
'url': 'http://127.0.0.1:8999/form-title/', |
|
81 |
'text': '<p>a form description</p> foo bar', |
|
82 |
} |
|
79 | 83 |
] |
80 | 84 | |
81 | 85 |
# artificially change title |
... | ... | |
240 | 244 |
result = cell.render({'request': RequestFactory().get('/')}) |
241 | 245 |
assert 'http://127.0.0.1:8999/form-title/tryauth' in result |
242 | 246 |
assert 'form title' in result |
247 |
assert '<p>a form description</p>' in result |
|
243 | 248 | |
244 | 249 | |
245 | 250 |
@mock.patch('requests.Session.send', side_effect=mocked_requests_send) |
... | ... | |
868 | 873 |
assert 'http://127.0.0.1:8999/a-second-form-title/tryauth' in result |
869 | 874 |
assert 'keyword-foo' in result |
870 | 875 |
assert 'keyword-bar' in result |
876 |
assert '<p>a form description</p>' in result |
|
871 | 877 | |
872 | 878 |
cell.ordering = 'popularity' |
873 | 879 |
cell.save() |
... | ... | |
929 | 935 |
cell_resp = app.get(ajax_cell_url + '?ctx=' + extra_ctx) |
930 | 936 |
assert ( |
931 | 937 |
PyQuery(cell_resp.text).find('a').attr('href') |
932 |
== 'http://127.0.0.1:8999/a-second-form-title/tryauth?cancelurl=http://testserver/test_forms_of_category_cell_render/'
|
|
938 |
== 'http://127.0.0.1:8999/a-second-form-title/tryauth?cancelurl=http%3A//testserver/test_forms_of_category_cell_render/'
|
|
933 | 939 |
) |
934 | 940 | |
935 | 941 |
tests/wcs/utils.py | ||
---|---|---|
7 | 7 |
WCS_FORMDEFS_DATA = [ |
8 | 8 |
{'slug': 'a-private-form', 'title': 'a private form', 'url': '/a-private-form/'}, |
9 | 9 |
{'slug': 'a-second-form-title', 'title': 'a second form title', 'url': '/a-second-form-title/'}, |
10 |
{'slug': 'form-title', 'title': 'form title', 'url': '/form-title/', 'keywords': ['foo', 'bar']}, |
|
10 |
{ |
|
11 |
'slug': 'form-title', |
|
12 |
'title': 'form title', |
|
13 |
'url': '/form-title/', |
|
14 |
'keywords': ['foo', 'bar'], |
|
15 |
'description': '<p>a form description</p>', |
|
16 |
}, |
|
11 | 17 |
{'slug': 'third-form-title', 'title': 'Third form title', 'url': '/third-form-title/'}, |
12 | 18 |
] |
13 | 19 | |
... | ... | |
22 | 28 |
'url': '/form-title/', |
23 | 29 |
'keywords': ['foo', 'bar'], |
24 | 30 |
'count': 42, |
31 |
'description': '<p>a form description</p>', |
|
25 | 32 |
}, |
26 | 33 |
{ |
27 | 34 |
'slug': 'a-second-form-title', |
28 |
- |