--- a/src/pyams_content/component/paragraph/html.py Tue Feb 06 11:15:55 2018 +0100
+++ b/src/pyams_content/component/paragraph/html.py Tue Feb 06 11:16:23 2018 +0100
@@ -22,14 +22,14 @@
from pyams_content.component.illustration.interfaces import IIllustrationTarget
from pyams_content.component.links.interfaces import ILinkContainerTarget, IInternalLink, IExternalLink, IMailtoLink
from pyams_content.component.paragraph.interfaces import IParagraphFactory
-from pyams_content.component.paragraph.interfaces.html import IHTMLParagraph
+from pyams_content.component.paragraph.interfaces.html import IRawParagraph, IHTMLParagraph
from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE
from pyams_i18n.interfaces import II18n, II18nManager, INegotiator
from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectModifiedEvent
# import packages
from pyams_content.component.links import InternalLink, ExternalLink, MailtoLink
-from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker
+from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker, BaseParagraphFactory
from pyams_utils.adapter import adapter_config
from pyams_utils.registry import utility_config, get_utility
from pyams_utils.request import check_request
@@ -46,6 +46,54 @@
#
+# Raw HTML paragraph
+#
+
+@implementer(IRawParagraph)
+class RawParagraph(BaseParagraph):
+ """Raw HTML paragraph"""
+
+ icon_class = 'fa-code'
+ icon_hint = _("Raw HTML ")
+
+ body = FieldProperty(IRawParagraph['body'])
+
+
+@utility_config(name='raw', provides=IParagraphFactory)
+class RawParagraphFactory(BaseParagraphFactory):
+ """Raw paragraph factory"""
+
+ name = _("Raw HTML paragraph")
+ content_type = RawParagraph
+ custom_menu = True
+
+
+@adapter_config(context=IRawParagraph, provides=IContentChecker)
+class RawParagraphContentChecker(BaseParagraphContentChecker):
+ """Raw HTML paragraph content checker"""
+
+ def inner_check(self, request):
+ output = []
+ translate = request.localizer.translate
+ manager = get_parent(self.context, II18nManager)
+ if manager is not None:
+ langs = manager.get_languages()
+ else:
+ negotiator = get_utility(INegotiator)
+ langs = (negotiator.server_language, )
+ i18n = II18n(self.context)
+ for lang in langs:
+ value = i18n.get_attribute('body', lang, request)
+ if not value:
+ field_title = translate(IRawParagraph['body'].title)
+ if len(langs) == 1:
+ output.append(translate(MISSING_VALUE).format(field=field_title))
+ else:
+ output.append(translate(MISSING_LANG_VALUE).format(field=field_title, lang=lang))
+ return output
+
+
+#
# HTML paragraph
#
@@ -54,16 +102,16 @@
"""HTML paragraph"""
icon_class = 'fa-html5'
- icon_hint = _("HTML paragraph")
+ icon_hint = _("Rich text")
body = FieldProperty(IHTMLParagraph['body'])
@utility_config(name='HTML', provides=IParagraphFactory)
-class HTMLParagraphFactory(object):
+class HTMLParagraphFactory(BaseParagraphFactory):
"""HTML paragraph factory"""
- name = _("HTML paragraph")
+ name = _("Rich text paragraph")
content_type = HTMLParagraph