fields: ~always use ckeditor for comment fields (#27988)

This commit is contained in:
Frédéric Péters 2018-11-14 13:50:50 +01:00
parent 3ccd6f4cc9
commit e986bf93d8
2 changed files with 19 additions and 9 deletions

View File

@ -1344,7 +1344,9 @@ def test_form_edit_comment_field(pub):
label='a comment field\n\na second line')]
formdef.store()
resp = app.get('/backoffice/forms/1/fields/1/')
assert not 'WysiwygTextWidget' in resp.body
assert 'WysiwygTextWidget' in resp.body
resp = resp.form.submit('submit')
assert FormDef.get(formdef.id).fields[0].label == '<p>a comment field</p>\n<p>a second line</p>'
# starting with a <
formdef.fields = [fields.CommentField(id='1', type='comment',
@ -1353,6 +1355,13 @@ def test_form_edit_comment_field(pub):
resp = app.get('/backoffice/forms/1/fields/1/')
assert 'WysiwygTextWidget' in resp.body
# legacy, ezt syntax in a non-html field will be presented as a textarea
formdef.fields = [fields.CommentField(id='1', type='comment',
label='[if-any toto]hello world[end]')]
formdef.store()
resp = app.get('/backoffice/forms/1/fields/1/')
assert 'WysiwygTextWidget' not in resp.body
def test_form_edit_map_field(pub):
create_superuser(pub)
create_role()

View File

@ -611,10 +611,7 @@ class CommentField(Field):
tag_attributes = 'data-field-id="%s" class="comment-field %s"' % (
self.id, self.extra_css_class or '')
if '\n\n' in self.label:
label = '<p>' + re.sub('\n\n+', '</p>\n<p>', self.label) + '</p>'
else:
label = self.label
label = self.get_html_content()
import wcs.workflows
label = wcs.workflows.template_on_html_string(label)
@ -633,14 +630,18 @@ class CommentField(Field):
def add_to_view_form(self, *args):
pass
def get_html_content(self):
if self.label and '\n\n' in self.label and self.label[0] != '<':
return '<p>' + re.sub('\n\n+', '</p>\n<p>', self.label) + '</p>'
return self.label
def fill_admin_form(self, form):
if self.label and (not self.label.startswith('<') and (
'\n\n' in self.label or '[end]' in self.label)):
if self.label and (self.label[0] != '<' and '[end]' in self.label):
form.add(TextWidget, 'label', title=_('Label'), value=self.label,
required=True, cols=70, rows=3, render_br=False)
else:
form.add(WysiwygTextWidget, 'label', title=_('Label'), value=self.label,
required=True)
form.add(WysiwygTextWidget, 'label', title=_('Label'),
value=self.get_html_content(), required=True)
form.add(StringWidget, 'extra_css_class', title = _('Extra classes for CSS styling'),
value=self.extra_css_class, size=30, advanced=(not self.extra_css_class))
form.add(ConditionWidget, 'condition', title=_('Display Condition'), value=self.condition,