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 | ||
---|---|---|
929 | 929 |
cell_resp = app.get(ajax_cell_url + '?ctx=' + extra_ctx) |
930 | 930 |
assert ( |
931 | 931 |
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/'
|
|
932 |
== 'http://127.0.0.1:8999/a-second-form-title/tryauth?cancelurl=http%3A//testserver/test_forms_of_category_cell_render/'
|
|
933 | 933 |
) |
934 | 934 | |
935 | 935 | |
936 |
- |