Projet

Général

Profil

0001-backoffice-include-field-type-link-for-blocks-on-fie.patch

Frédéric Péters, 19 juin 2022 14:56

Télécharger (3,85 ko)

Voir les différences:

Subject: [PATCH] backoffice: include field type (& link for blocks) on field
 edit page (#65827)

 tests/admin_pages/test_block.py      |  5 +++++
 tests/admin_pages/test_form.py       |  2 ++
 wcs/admin/fields.py                  | 14 ++++++++++++--
 wcs/qommon/static/css/dc2/admin.scss | 11 +++++++++++
 4 files changed, 30 insertions(+), 2 deletions(-)
tests/admin_pages/test_block.py
290 290
    resp = resp.forms[0].submit().follow()
291 291
    assert 'a block field' in resp.text
292 292
    resp = resp.click('Edit', href='1/')
293
    assert resp.pyquery('.field-edit--title').text() == 'a block field'
294
    assert resp.pyquery('.field-edit--subtitle').text() == 'Block of fields - foobar'
295
    assert resp.pyquery('.field-edit--subtitle a').attr.href.endswith(
296
        '/backoffice/forms/blocks/%s/' % block.id
297
    )
293 298
    assert resp.form['max_items'].value == '1'
294 299

  
295 300

  
tests/admin_pages/test_form.py
1830 1830

  
1831 1831
    resp = resp.click('Edit', href='1/')
1832 1832
    assert '/backoffice/forms/1/fields/#itemId_1' in resp
1833
    assert resp.pyquery('.field-edit--title').text() == '1st field'
1834
    assert resp.pyquery('.field-edit--subtitle').text() == 'Text (line)'
1833 1835
    assert resp.forms[0]['label'].value == '1st field'
1834 1836
    resp.forms[0]['label'] = 'changed field'
1835 1837
    resp.forms[0]['required'] = False
wcs/admin/fields.py
23 23

  
24 24
from wcs import fields
25 25
from wcs.admin import utils
26
from wcs.fields import get_field_options
26
from wcs.fields import BlockField, get_field_options
27 27
from wcs.formdef import FormDef
28 28
from wcs.qommon import _, errors, get_cfg, misc
29 29
from wcs.qommon.admin.menu import command_icon
......
89 89
        if redo or not form.get_submit() == 'submit':
90 90
            self.html_top(self.objectdef.name)
91 91
            r = TemplateIO(html=True)
92
            r += htmltext('<h2>%s</h2>') % misc.ellipsize(self.field.unhtmled_label, 80)
92
            r += htmltext('<h2 class="field-edit--title">%s</h2>') % misc.ellipsize(
93
                self.field.unhtmled_label, 80
94
            )
95
            if isinstance(self.field, BlockField):
96
                r += htmltext('<h3 class="field-edit--subtitle">%s - <a href="%s">%s</a></h3>') % (
97
                    _('Block of fields'),
98
                    self.field.block.get_admin_url(),
99
                    self.field.block.name,
100
                )
101
            else:
102
                r += htmltext('<h3 class="field-edit--subtitle">%s</h3>') % self.field.description
93 103
            for widget in form.widgets:
94 104
                if hasattr(widget, 'get_widget'):
95 105
                    add_element_widget = widget.get_widget('add_element')
wcs/qommon/static/css/dc2/admin.scss
2455 2455
	padding-left: 10px;
2456 2456
	padding-right: 10px;
2457 2457
}
2458

  
2459
div#main-content > h2.field-edit--title {
2460
	margin-bottom: 0;
2461
}
2462

  
2463
div#main-content > h3.field-edit--subtitle {
2464
	margin-top: 0;
2465
	font-size: 100%;
2466
	opacity: 0.8;
2467
	font-weight: normal;
2468
}
2458
-