fields: refine long text field display mode labels (#57283) #100
|
@ -2045,8 +2045,8 @@ def test_form_edit_text_field(pub):
|
|||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/forms/1/fields/1/')
|
||||
assert resp.form['display_mode'].options == [
|
||||
('Plain Text (paragraphs)', True, None),
|
||||
('Preformatted Text', False, None),
|
||||
('Plain Text (with automatic paragraphs on blank lines)', True, None),
|
||||
('Plain Text (with linebreaks as typed)', False, None),
|
||||
]
|
||||
|
||||
pub.site_options.set('options', 'enable-richtext-field', 'true')
|
||||
|
@ -2054,9 +2054,9 @@ def test_form_edit_text_field(pub):
|
|||
pub.site_options.write(fd)
|
||||
resp = app.get('/backoffice/forms/1/fields/1/')
|
||||
assert resp.form['display_mode'].options == [
|
||||
('Plain Text (paragraphs)', True, None),
|
||||
('Preformatted Text', False, None),
|
||||
('Rich Text', False, None),
|
||||
('Plain Text (with automatic paragraphs on blank lines)', True, None),
|
||||
('Plain Text (with linebreaks as typed)', False, None),
|
||||
]
|
||||
|
||||
|
||||
|
|
|
@ -101,11 +101,11 @@ def test_string():
|
|||
assert fields.StringField().get_csv_value(url) == [url]
|
||||
|
||||
|
||||
def test_text():
|
||||
def test_text(pub):
|
||||
assert fields.TextField().get_view_short_value('foo' * 15) == ('foo' * 10)[:27] + '(…)'
|
||||
assert fields.TextField().get_view_value('foo') == '<p>foo</p>'
|
||||
assert fields.TextField().get_view_value('foo\n\nfoo') == '<p>foo\n</p><p>\nfoo</p>'
|
||||
assert fields.TextField(display_mode='pre').get_view_value('foo') == '<pre>foo</pre>'
|
||||
assert fields.TextField(display_mode='pre').get_view_value('foo') == '<p class="plain-text-pre">foo</p>'
|
||||
assert (
|
||||
fields.TextField(display_mode='rich').get_view_short_value('<p>foo</p>' * 15)
|
||||
== ('foo' * 10)[:27] + '(…)'
|
||||
|
|
|
@ -1419,14 +1419,15 @@ class TextField(WidgetField):
|
|||
form.add(HiddenWidget, 'cols', value=None)
|
||||
form.add(StringWidget, 'rows', title=_('Number of rows'), value=self.rows)
|
||||
form.add(StringWidget, 'maxlength', title=_('Maximum number of characters'), value=self.maxlength)
|
||||
display_options = [
|
||||
('plain', _('Plain Text (paragraphs)')),
|
||||
('pre', _('Preformatted Text')),
|
||||
]
|
||||
display_options = []
|
||||
if get_publisher().get_site_option('enable-richtext-field'):
|
||||
display_options += [
|
||||
('rich', _('Rich Text')),
|
||||
]
|
||||
display_options += [
|
||||
('plain', _('Plain Text (with automatic paragraphs on blank lines)')),
|
||||
('pre', _('Plain Text (with linebreaks as typed)')),
|
||||
]
|
||||
form.add(
|
||||
RadiobuttonsWidget,
|
||||
'display_mode',
|
||||
|
@ -1434,7 +1435,6 @@ class TextField(WidgetField):
|
|||
value=self.display_mode,
|
||||
default_value='plain',
|
||||
options=display_options,
|
||||
extra_css_class='widget-inline-radio no-bottom-margin',
|
||||
advanced=True,
|
||||
)
|
||||
|
||||
|
@ -1446,7 +1446,7 @@ class TextField(WidgetField):
|
|||
|
||||
def get_view_value(self, value, **kwargs):
|
||||
if self.display_mode == 'pre':
|
||||
return htmltext('<pre>') + value + htmltext('</pre>')
|
||||
return htmltext('<p class="plain-text-pre">') + value + htmltext('</p>')
|
||||
elif self.display_mode == 'rich':
|
||||
return htmltext(strip_some_tags(value, RichTextWidget.ALL_TAGS))
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue