misc: add site options to control rich text usage (#86222)
gitea/wcs/pipeline/head Build queued...
Details
gitea/wcs/pipeline/head Build queued...
Details
This commit is contained in:
parent
c6780665cd
commit
61fcfee1f5
|
@ -1,3 +1,5 @@
|
|||
import os
|
||||
|
||||
import pytest
|
||||
from quixote import cleanup
|
||||
|
||||
|
@ -62,3 +64,48 @@ def test_display_message_rich_text(pub):
|
|||
workflow.store()
|
||||
resp = app.get(display_message.get_admin_url())
|
||||
assert resp.pyquery('textarea[data-config]') # ckeditor
|
||||
|
||||
pub.site_options.set('options', 'rich-text-wf-displaymsg', 'auto-ckeditor-textarea')
|
||||
with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd:
|
||||
pub.site_options.write(fd)
|
||||
display_message.message = '<table><tr><td>hello world</td></tr></table>'
|
||||
workflow.store()
|
||||
resp = app.get(display_message.get_admin_url())
|
||||
assert resp.pyquery('textarea[data-config]') # ckeditor
|
||||
|
||||
display_message.message = '<ul>{% for item in lists %}<li>{{ item }}</li>{% endfor %}</ul>'
|
||||
workflow.store()
|
||||
resp = app.get(display_message.get_admin_url())
|
||||
assert resp.pyquery('textarea:not([data-config]):not([data-godo-schema])') # plain textarea
|
||||
|
||||
pub.site_options.set('options', 'rich-text-wf-displaymsg', 'auto-textarea')
|
||||
with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd:
|
||||
pub.site_options.write(fd)
|
||||
resp = app.get(display_message.get_admin_url())
|
||||
assert resp.pyquery('textarea:not([data-config]):not([data-godo-schema])') # plain textarea
|
||||
|
||||
pub.site_options.set('options', 'rich-text-wf-displaymsg', 'auto-ckeditor')
|
||||
with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd:
|
||||
pub.site_options.write(fd)
|
||||
resp = app.get(display_message.get_admin_url())
|
||||
assert resp.pyquery('textarea[data-config]') # ckeditor
|
||||
|
||||
display_message.message = '<p>simple</p>'
|
||||
workflow.store()
|
||||
pub.site_options.set('options', 'rich-text-wf-displaymsg', 'ckeditor')
|
||||
with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd:
|
||||
pub.site_options.write(fd)
|
||||
resp = app.get(display_message.get_admin_url())
|
||||
assert resp.pyquery('textarea[data-config]') # ckeditor
|
||||
|
||||
pub.site_options.set('options', 'rich-text-wf-displaymsg', 'godo')
|
||||
with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd:
|
||||
pub.site_options.write(fd)
|
||||
resp = app.get(display_message.get_admin_url())
|
||||
assert resp.pyquery('textarea[data-godo-schema]') # godo
|
||||
|
||||
pub.site_options.set('options', 'rich-text-wf-displaymsg', 'textarea')
|
||||
with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd:
|
||||
pub.site_options.write(fd)
|
||||
resp = app.get(display_message.get_admin_url())
|
||||
assert resp.pyquery('textarea:not([data-config]):not([data-godo-schema])') # plain textarea
|
||||
|
|
|
@ -3972,9 +3972,29 @@ class DjangoConditionWidget(StringWidget):
|
|||
self.set_error(str(e))
|
||||
|
||||
|
||||
def get_rich_text_widget_class(content):
|
||||
# use godo.js if all tags in existing content are supported
|
||||
def get_rich_text_widget_class(content, usage):
|
||||
# get widget for rich text content, with different fallback modes, to avoid godo.js
|
||||
# if all tags in existing content are not supported.
|
||||
behaviour = get_publisher().get_site_option(f'rich-text-{usage}')
|
||||
|
||||
tags = set(re.findall(r'<([a-z]+)[\s>]', content or ''))
|
||||
if tags.issubset(set(RichTextWidget.ALL_TAGS)):
|
||||
return RichTextWidget
|
||||
return WysiwygTextWidget
|
||||
has_godo_unsupported_tags = not (tags.issubset(set(RichTextWidget.ALL_TAGS)))
|
||||
is_django_template = Template.is_template_string(content or '', ezt_support=False)
|
||||
|
||||
if behaviour == 'godo':
|
||||
widget = RichTextWidget
|
||||
elif behaviour == 'ckeditor':
|
||||
widget = WysiwygTextWidget
|
||||
elif behaviour == 'textarea':
|
||||
widget = TextWidget
|
||||
elif behaviour == 'auto-ckeditor' and (has_godo_unsupported_tags or is_django_template):
|
||||
widget = WysiwygTextWidget
|
||||
elif behaviour == 'auto-ckeditor-textarea' and is_django_template:
|
||||
widget = TextWidget
|
||||
elif behaviour == 'auto-ckeditor-textarea' and has_godo_unsupported_tags:
|
||||
widget = WysiwygTextWidget
|
||||
elif behaviour == 'auto-textarea' and (has_godo_unsupported_tags or is_django_template):
|
||||
widget = TextWidget
|
||||
else:
|
||||
widget = RichTextWidget
|
||||
return widget
|
||||
|
|
|
@ -446,6 +446,7 @@ class QommonPublisher(Publisher):
|
|||
'relatable-hosts': '',
|
||||
'sync-map-and-address-fields': 'true',
|
||||
'unused-files-behaviour': 'remove',
|
||||
'rich-text-wf-displaymsg': 'auto-ckeditor',
|
||||
},
|
||||
}
|
||||
if self.site_options is None:
|
||||
|
|
|
@ -112,7 +112,7 @@ class DisplayMessageWorkflowStatusItem(WorkflowStatusItem):
|
|||
in_global_action = isinstance(self.parent, WorkflowGlobalAction)
|
||||
if 'message' in parameters:
|
||||
form.add(
|
||||
get_rich_text_widget_class(self.message),
|
||||
get_rich_text_widget_class(self.message, usage='wf-displaymsg'),
|
||||
'%smessage' % prefix,
|
||||
title=_('Message'),
|
||||
value=self.message,
|
||||
|
|
Loading…
Reference in New Issue