0001-backoffice-add-inspector-view-for-blocks-65545.patch
tests/admin_pages/test_block.py | ||
---|---|---|
441 | 441 |
assert 'This block of fields contains 30 fields.' in resp.text |
442 | 442 |
assert '<div id="new-field"><h3>New Field</h3>' not in resp.text |
443 | 443 |
assert '>Duplicate<' not in resp.text |
444 | ||
445 | ||
446 |
def test_block_inspect(pub): |
|
447 |
create_superuser(pub) |
|
448 |
BlockDef.wipe() |
|
449 |
block = BlockDef() |
|
450 |
block.name = 'foobar' |
|
451 |
block.fields = [ |
|
452 |
fields.StringField(id='123', required=True, label='Test', type='string'), |
|
453 |
fields.StringField(id='124', required=True, label='Test2', type='string'), |
|
454 |
] |
|
455 |
block.store() |
|
456 | ||
457 |
app = login(get_app(pub)) |
|
458 |
resp = app.get('/backoffice/forms/blocks/%s/' % block.id) |
|
459 |
resp = resp.click('Inspector') |
|
460 |
assert resp.pyquery('#inspect-fields .inspect-field').length == 2 |
tests/admin_pages/test_form.py | ||
---|---|---|
10 | 10 |
from webtest import Upload |
11 | 11 | |
12 | 12 |
from wcs import fields |
13 |
from wcs.blocks import BlockDef |
|
13 | 14 |
from wcs.carddef import CardDef |
14 | 15 |
from wcs.categories import Category, DataSourceCategory, WorkflowCategory |
15 | 16 |
from wcs.data_sources import NamedDataSource |
... | ... | |
3476 | 3477 |
] |
3477 | 3478 |
workflow.store() |
3478 | 3479 | |
3480 |
BlockDef.wipe() |
|
3481 |
block = BlockDef() |
|
3482 |
block.name = 'foobar' |
|
3483 |
block.fields = [ |
|
3484 |
fields.StringField(id='123', required=True, label='Test', type='string'), |
|
3485 |
fields.StringField(id='234', required=True, label='Test2', type='string'), |
|
3486 |
] |
|
3487 |
block.store() |
|
3488 | ||
3479 | 3489 |
FormDef.wipe() |
3480 | 3490 |
formdef = FormDef() |
3481 | 3491 |
formdef.name = 'form title' |
... | ... | |
3520 | 3530 |
fields.FileField( |
3521 | 3531 |
id='12', label='file', automatic_image_resize=True, display_locations=['validation'] |
3522 | 3532 |
), |
3533 |
fields.BlockField(id='13', label='Block field', type='block:foobar'), |
|
3523 | 3534 |
] |
3524 | 3535 |
formdef.workflow_options = {'test': 'plop'} |
3525 | 3536 |
formdef.store() |
... | ... | |
3566 | 3577 |
resp.pyquery('[data-field-id="12"] .parameter-display_locations').text() |
3567 | 3578 |
== 'Display Locations: Validation Page' |
3568 | 3579 |
) |
3580 |
assert resp.pyquery('[data-field-id="13"] h4 .inspect-field-type a').attr.href.endswith( |
|
3581 |
block.get_admin_url() + 'inspect' |
|
3582 |
) |
wcs/admin/blocks.py | ||
---|---|---|
44 | 44 |
'delete', |
45 | 45 |
'export', |
46 | 46 |
'settings', |
47 |
'inspect', |
|
47 | 48 |
('history', 'snapshots_dir'), |
48 | 49 |
] |
49 | 50 |
field_def_page_class = BlockFieldDefPage |
... | ... | |
103 | 104 |
if get_publisher().snapshot_class: |
104 | 105 |
r += htmltext('<li><a rel="popup" href="history/save">%s</a></li>') % _('Save snapshot') |
105 | 106 |
r += htmltext('<li><a href="history/">%s</a></li>') % _('History') |
107 |
r += htmltext('<li><a href="inspect">%s</a></li>') % _('Inspector') |
|
106 | 108 |
r += htmltext('<li><a href="settings" rel="popup">%s</a></li>') % _('Settings') |
107 | 109 |
r += htmltext('</ul>') |
108 | 110 |
r += super().get_new_field_form(page_id=page_id) |
... | ... | |
206 | 208 |
r += form.render() |
207 | 209 |
return r.getvalue() |
208 | 210 | |
211 |
def inspect(self): |
|
212 |
self.html_top(self.objectdef.name) |
|
213 |
get_response().breadcrumb.append(('inspect', _('Inspector'))) |
|
214 |
context = {'blockdef': self.objectdef, 'view': self} |
|
215 |
return template.QommonTemplateResponse( |
|
216 |
templates=['wcs/backoffice/block-inspect.html'], context=context |
|
217 |
) |
|
218 | ||
209 | 219 | |
210 | 220 |
class BlocksDirectory(Directory): |
211 | 221 |
_q_exports = ['', 'new', 'categories', ('import', 'p_import')] |
wcs/templates/wcs/backoffice/block-inspect.html | ||
---|---|---|
1 |
{% extends "wcs/backoffice/base.html" %} |
|
2 |
{% load i18n %} |
|
3 | ||
4 |
{% block appbar %}{% endblock %} |
|
5 | ||
6 |
{% block content %} |
|
7 | ||
8 |
<div class="pk-tabs inspect-tabs inspect-form-tabs"> |
|
9 |
<div class="pk-tabs--tab-list" role="tablist"> |
|
10 |
<button role="tab" aria-selected="true" aria-controls="inspect-infos" id="tab-infos" tabindex="0">{% trans "Information" %}</button> |
|
11 |
<button role="tab" aria-selected="false" aria-controls="inspect-fields" id="tab-fields" tabindex="-1">{% trans "Fields" %}</button> |
|
12 |
</div> |
|
13 |
<div class="pk-tabs--container"> |
|
14 | ||
15 |
<div id="inspect-infos" role="tabpanel" tabindex="0" aria-labelledby="tab-info"> |
|
16 |
<ul> |
|
17 |
<li><span class="parameter">{% trans "Title" %}{% trans ":" %}</span> {{ blockdef.name|default:"-" }}</li> |
|
18 |
<li><span class="parameter">{% trans "Category" %}{% trans ":" %}</span> {% if blockdef.category %}<a href="{{ blockdef.category.get_admin_url }}">{{ blockdef.category.name }}</a>{% else %}-{% endif %}</li> |
|
19 |
<li><span class="parameter">{% trans "Digest Template" %}{% trans ":" %}</span> {{ blockdef.digest_template|default:"-" }}</li> |
|
20 |
</ul> |
|
21 |
</div> |
|
22 | ||
23 |
<div id="inspect-fields" role="tabpanel" tabindex="0" aria-labelledby="tab-fields" hidden> |
|
24 |
{% for field in blockdef.fields %} |
|
25 |
{% include "wcs/backoffice/includes/inspect-field.html" %} |
|
26 |
{% endfor %} |
|
27 |
</div> |
|
28 |
</div> |
|
29 | ||
30 |
</div> |
|
31 |
{% endblock %} |
wcs/templates/wcs/backoffice/formdef-inspect.html | ||
---|---|---|
78 | 78 |
{% blocktrans count fields_count=formdef.fields|count %}{{ fields_count }} field{% plural %}{{ fields_count }} fields.{% endblocktrans %} |
79 | 79 |
</p></div> |
80 | 80 |
{% for field in formdef.fields %} |
81 |
<div class="inspect-field inspect-field--{{ field.key }} {% if forloop.first %}inspect-field--first{% endif %}" data-field-id="{{ field.id }}"> |
|
82 |
<h4><a href="fields/{{ field.id }}/">{{ field.ellipsized_label }}</a> <span class="inspect-field-type">- {{ field.get_type_label }}</span></h4> |
|
83 |
{{ field.get_parameters_view|safe }} |
|
84 |
</div> |
|
81 |
{% include "wcs/backoffice/includes/inspect-field.html" %} |
|
85 | 82 |
{% endfor %} |
86 | 83 |
</div> |
87 | 84 |
</div> |
wcs/templates/wcs/backoffice/includes/inspect-field.html | ||
---|---|---|
1 |
<div class="inspect-field inspect-field--{{ field.key }} {% if forloop.first %}inspect-field--first{% endif %}" |
|
2 |
data-field-id="{{ field.id }}"> |
|
3 |
<h4><a href="{{ path|default:"fields/" }}{{ field.id }}/">{{ field.ellipsized_label }}</a> |
|
4 |
<span class="inspect-field-type">- |
|
5 |
{% if field.key == 'block' %}<a href="{{ field.block.get_admin_url }}inspect">{% endif %} |
|
6 |
{{ field.get_type_label }} |
|
7 |
{% if field.key == 'block' %}</a>{% endif %} |
|
8 |
</span> |
|
9 |
</h4> |
|
10 |
{{ field.get_parameters_view|safe }} |
|
11 |
</div> |
wcs/templates/wcs/backoffice/workflow-inspect.html | ||
---|---|---|
34 | 34 | |
35 | 35 |
<div id="inspect-variables" role="tabpanel" tabindex="0" aria-labelledby="tab-variables" hidden> |
36 | 36 |
{% for field in workflow.variables_formdef.fields %} |
37 |
<div class="inspect-field inspect-field--{{ field.key }} {% if forloop.first %}inspect-field--first{% endif %}" data-field-id="{{ field.id }}"> |
|
38 |
<h4><a href="variables/fields/{{ field.id }}/">{{ field.ellipsized_label }}</a> <span class="inspect-field-type">- {{ field.get_type_label }}</span></h4> |
|
39 |
{{ field.get_parameters_view|safe }} |
|
40 |
</div> |
|
37 |
{% include "wcs/backoffice/includes/inspect-field.html" with path="variables/fields/" %} |
|
41 | 38 |
{% endfor %} |
42 | 39 |
</div> |
43 | 40 | |
44 | 41 |
<div id="inspect-fields" role="tabpanel" tabindex="0" aria-labelledby="tab-fields" hidden> |
45 | 42 |
{% for field in workflow.backoffice_fields_formdef.fields %} |
46 |
<div class="inspect-field inspect-field--{{ field.key }} {% if forloop.first %}inspect-field--first{% endif %}" data-field-id="{{ field.id }}"> |
|
47 |
<h4><a href="backoffice-fields/fields/{{ field.id }}/">{{ field.ellipsized_label }}</a> <span class="inspect-field-type">- {{ field.get_type_label }}</span></h4> |
|
48 |
{{ field.get_parameters_view|safe }} |
|
49 |
</div> |
|
43 |
{% include "wcs/backoffice/includes/inspect-field.html" with path="backoffice-fields/fields/" %} |
|
50 | 44 |
{% endfor %} |
51 | 45 |
</div> |
52 | 46 | |
53 |
- |