Project

General

Profile

0001-fields-always-use-ckeditor-for-comment-fields-27988.patch

Frédéric Péters, 14 Nov 2018 01:51 PM

Download (3.45 KB)

View differences:

Subject: [PATCH] fields: ~always use ckeditor for comment fields (#27988)

 tests/test_admin_pages.py | 11 ++++++++++-
 wcs/fields.py             | 17 +++++++++--------
 2 files changed, 19 insertions(+), 9 deletions(-)
tests/test_admin_pages.py
1338 1338
        label='a comment field\n\na second line')]
1339 1339
    formdef.store()
1340 1340
    resp = app.get('/backoffice/forms/1/fields/1/')
1341
    assert not 'WysiwygTextWidget' in resp.body
1341
    assert 'WysiwygTextWidget' in resp.body
1342
    resp = resp.form.submit('submit')
1343
    assert FormDef.get(formdef.id).fields[0].label == '<p>a comment field</p>\n<p>a second line</p>'
1342 1344

  
1343 1345
    # starting with a <
1344 1346
    formdef.fields = [fields.CommentField(id='1', type='comment',
......
1347 1349
    resp = app.get('/backoffice/forms/1/fields/1/')
1348 1350
    assert 'WysiwygTextWidget' in resp.body
1349 1351

  
1352
    # legacy, ezt syntax in a non-html field will be presented as a textarea
1353
    formdef.fields = [fields.CommentField(id='1', type='comment',
1354
        label='[if-any toto]hello world[end]')]
1355
    formdef.store()
1356
    resp = app.get('/backoffice/forms/1/fields/1/')
1357
    assert 'WysiwygTextWidget' not in resp.body
1358

  
1350 1359
def test_form_edit_map_field(pub):
1351 1360
    create_superuser(pub)
1352 1361
    create_role()
wcs/fields.py
604 604
        tag_attributes = 'data-field-id="%s" class="comment-field %s"' % (
605 605
                self.id, self.extra_css_class or '')
606 606

  
607
        if '\n\n' in self.label:
608
            label = '<p>' + re.sub('\n\n+', '</p>\n<p>', self.label) + '</p>'
609
        else:
610
            label = self.label
607
        label = self.get_html_content()
611 608

  
612 609
        import wcs.workflows
613 610
        label = wcs.workflows.template_on_html_string(label)
......
626 623
    def add_to_view_form(self, *args):
627 624
        pass
628 625

  
626
    def get_html_content(self):
627
        if self.label and '\n\n' in self.label and self.label[0] != '<':
628
            return '<p>' + re.sub('\n\n+', '</p>\n<p>', self.label) + '</p>'
629
        return self.label
630

  
629 631
    def fill_admin_form(self, form):
630
        if self.label and (not self.label.startswith('<') and (
631
                '\n\n' in self.label or '[end]' in self.label)):
632
        if self.label and (self.label[0] != '<' and '[end]' in self.label):
632 633
            form.add(TextWidget, 'label', title=_('Label'), value=self.label,
633 634
                    required=True, cols=70, rows=3, render_br=False)
634 635
        else:
635
            form.add(WysiwygTextWidget, 'label', title=_('Label'), value=self.label,
636
                    required=True)
636
            form.add(WysiwygTextWidget, 'label', title=_('Label'),
637
                    value=self.get_html_content(), required=True)
637 638
        form.add(StringWidget, 'extra_css_class', title = _('Extra classes for CSS styling'),
638 639
                value=self.extra_css_class, size=30, advanced=(not self.extra_css_class))
639 640
        form.add(ConditionWidget, 'condition', title=_('Display Condition'), value=self.condition,
640
-