Skip to content

Commit

Permalink
Set markup schema to html/text as default for RichText fields (#1755)
Browse files Browse the repository at this point in the history
* Set markup schema to `html/text` as default for RichText fields

* Safe retrieval of markup registry
  • Loading branch information
xispa committed Jan 30, 2021
1 parent dc77e98 commit b663ffc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
2.0.0 (unreleased)
------------------

- #1755 Set markup schema to `html/text` as default for RichText fields
- #1754 Fix KeyError in calculation validator
- #1753 Fixed indexing of partitions and missing metadata generation
- #1751 Fix typos and naming in import template
Expand Down
19 changes: 19 additions & 0 deletions src/senaite/core/setuphandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@
from bika.lims.setuphandlers import setup_core_catalogs
from bika.lims.setuphandlers import setup_form_controller_actions
from bika.lims.setuphandlers import setup_groups
from plone.registry.interfaces import IRegistry
from Products.CMFPlone.utils import get_installer
from senaite.core import logger
from senaite.core.config import PROFILE_ID
from zope.component import getUtility
from zope.interface import implementer

try:
from Products.CMFPlone.interfaces import IMarkupSchema
from Products.CMFPlone.interfaces import INonInstallable
except ImportError:
from zope.interface import Interface
IMarkupSchema = None

class INonInstallable(Interface):
pass
Expand Down Expand Up @@ -117,6 +121,9 @@ def install(context):
setup_form_controller_actions(portal)
setup_form_controller_more_action(portal)

# Setup markup default and allowed schemas
setup_markup_schema(portal)

logger.info("SENAITE CORE install handler [DONE]")


Expand Down Expand Up @@ -201,3 +208,15 @@ def post_install(portal_setup):
_run_import_step(portal, "skins", profile=profile_id)

logger.info("SENAITE CORE post install handler [DONE]")


def setup_markup_schema(portal):
"""Sets the default and allowed markup schemas for RichText widgets
"""
if not IMarkupSchema:
return

registry = getUtility(IRegistry, context=portal)
settings = registry.forInterface(IMarkupSchema, prefix='plone')
settings.default_type = u"text/html"
settings.allowed_types = ("text/html", )
4 changes: 4 additions & 0 deletions src/senaite/core/upgrade/v02_00_000.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from senaite.core import logger
from senaite.core.config import PROJECTNAME as product
from senaite.core.setuphandlers import _run_import_step
from senaite.core.setuphandlers import setup_markup_schema
from senaite.core.upgrade import upgradestep
from senaite.core.upgrade.utils import UpgradeUtils
from senaite.core.upgrade.utils import catalog_object
Expand Down Expand Up @@ -246,6 +247,9 @@ def upgrade(tool):
# Resolve attachment image URLs in results interpretations by UID
migrate_resultsinterpretations_inline_images(portal)

# Setup markup default and allowed schemas
setup_markup_schema(portal)

logger.info("{0} upgraded to version {1}".format(product, version))
return True

Expand Down

0 comments on commit b663ffc

Please sign in to comment.