Skip to content

Commit

Permalink
Code cleanup, add 'volto.blocks' behavior to Plone Site GS types info…
Browse files Browse the repository at this point in the history
…. Remove 'Collection' from types in GS. Remove 'plone.richtext' behavior from Plone Site, Document, News Item, Events.
  • Loading branch information
sneridagh committed Jan 17, 2022
1 parent 40ab807 commit ebfa43e
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 79 deletions.
11 changes: 11 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ Changelog
- Use by default Slate blocks for the default pages
[sneridagh]

- Code cleanup, remove some outdated and unused helpers in ``setuptools.py``
[sneridagh]

- Add ``volto.blocks`` behavior to Plone Site GS types info.
[sneridagh]

- Remove ``Collection`` from types in GS types info.
[sneridagh]

- Remove ``plone.richtext`` behavior from Plone Site, Document, News Item, Events
[sneridagh]

3.1.0a9 (2022-01-15)
--------------------
Expand Down
2 changes: 1 addition & 1 deletion src/plone/volto/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<version>1012</version>
<version>1013</version>
<dependencies>
<dependency>profile-collective.folderishtypes.dx:default</dependency>
<dependency>profile-plone.restapi:blocks</dependency>
Expand Down
1 change: 1 addition & 0 deletions src/plone/volto/profiles/default/types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<object name="Plone Site" />
<object meta_type="Dexterity FTI" name="LRF" />
<object meta_type="Dexterity FTI" name="Document" />
<object meta_type="Dexterity FTI" name="Collection" />
</object>
8 changes: 8 additions & 0 deletions src/plone/volto/profiles/default/types/Collection.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<object name="Collection" meta_type="Dexterity FTI" i18n:domain="plone"
xmlns:i18n="http://xml.zope.org/namespaces/i18n">

<!-- Collections in Volto are disabled by default -->
<property name="global_allow">False</property>

</object>
15 changes: 5 additions & 10 deletions src/plone/volto/profiles/default/types/Plone_Site.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
<?xml version="1.0"?>
<object name="Plone Site"
i18n:domain="plone" xmlns:i18n="http://xml.zope.org/namespaces/i18n">
<action
action_id="edit"
category="object"
condition_expr=""
i18n:attributes="title"
title="Edit"
url_expr="string:${object_url}/edit"
visible="True">
<permission value="Manage portal"/>
</action>

<property name="behaviors" purge="false">
<element value="volto.blocks" />
</property>

</object>
100 changes: 32 additions & 68 deletions src/plone/volto/setuphandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,14 @@
from plone import api
from plone.app.multilingual.browser.setup import SetupMultilingualSite
from plone.app.multilingual.setuphandlers import enable_translatable_behavior
from plone.app.portlets.utils import assignment_mapping_from_key
from plone.dexterity.interfaces import IDexterityFTI
from plone.portlets.constants import CONTEXT_CATEGORY
from plone.portlets.interfaces import IPortletAssignmentMapping
from plone.portlets.interfaces import IPortletManager
from plone.volto.default_homepage.default import default_home
from plone.volto.default_homepage.demo import demo_home_page
from plone.volto.default_homepage.lrf import default_lrf_home
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.interfaces import INonInstallable
from Products.CMFPlone.utils import get_installer
from zope.component import getMultiAdapter
from zope.component import getUtility
from zope.component import queryUtility
from zope.component.interfaces import IFactory
from zope.container.interfaces import INameChooser
from zope.interface import implementer

import json
Expand All @@ -36,6 +28,13 @@

logger = logging.getLogger("plone.volto")

NO_RICHTEXT_BEHAVIOR_CONTENT_TYPES = [
"Plone Site",
"Document",
"News Item",
"Event",
]


@implementer(INonInstallable)
class HiddenProfiles(object):
Expand All @@ -47,8 +46,11 @@ def getNonInstallableProfiles(self):
def post_install(context):
"""Post install script"""
# For Plone 6, make sure the blocks behavior is enabled in the root
if PLONE_6:
add_behavior("Plone Site", "volto.blocks")
add_behavior("Plone Site", "volto.blocks")

# Remove plone.richtext from content types with blocks enabled
for type_ in NO_RICHTEXT_BEHAVIOR_CONTENT_TYPES:
remove_behavior(type_, "plone.richtext")


def uninstall(context):
Expand Down Expand Up @@ -147,64 +149,26 @@ def add_catalog_indexes(context, wanted=None):

def add_behavior(portal_type, behavior):
fti = queryUtility(IDexterityFTI, name=portal_type)
new = [
currentbehavior
for currentbehavior in fti.behaviors
if currentbehavior != behavior
]
new.append(behavior)
fti.behaviors = tuple(new)


def setupNavigationPortlet(
context,
name="",
root=None,
includeTop=False,
currentFolderOnly=False,
bottomLevel=0,
topLevel=0,
):
"""
setupNavigationPortlet(portal['vereinigungen']['fachliche-vereinigungen']['sektion-materie-und-kosmos']['gravitation-und-relativitaetstheorie']) # noqa
"""
from plone.app.portlets.portlets.navigation import (
Assignment as NavAssignment,
) # noqa

target_manager = queryUtility(
IPortletManager, name="plone.leftcolumn", context=context
)
target_manager_assignments = getMultiAdapter(
(context, target_manager), IPortletAssignmentMapping
)

navtree = NavAssignment(
includeTop=includeTop,
currentFolderOnly=currentFolderOnly,
bottomLevel=bottomLevel,
topLevel=topLevel,
)

if "navigation" not in target_manager_assignments.keys():
target_manager_assignments["navigation"] = navtree


def setupPortletAt(portal, portlet_type, manager, path, name="", **kw):
"""
setupPortletAt(portal, 'portlets.Events', 'plone.rightcolumn', '/vereinigungen/fachliche-vereinigungen/sektion-kondensierte-materie/halbleiterphysik') # noqa
"""
portlet_factory = getUtility(IFactory, name=portlet_type)
assignment = portlet_factory(**kw)
mapping = assignment_mapping_from_key(
portal, manager, CONTEXT_CATEGORY, path, create=True
)

if not name:
chooser = INameChooser(mapping)
name = chooser.chooseName(None, assignment)

mapping[name] = assignment
if fti is not None:
# This prevents to add the behavior twice
new = [
currentbehavior
for currentbehavior in fti.behaviors
if currentbehavior != behavior
]
new.append(behavior)
fti.behaviors = tuple(new)


def remove_behavior(portal_type, behavior):
fti = queryUtility(IDexterityFTI, name=portal_type)
if fti is not None:
new = [
currentbehavior
for currentbehavior in fti.behaviors
if currentbehavior != behavior
]
fti.behaviors = tuple(new)


def create_default_homepage_draftjs(context):
Expand Down
7 changes: 7 additions & 0 deletions src/plone/volto/upgrades.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from copy import deepcopy
from plone import api
from plone.restapi.behaviors import IBlocks
from plone.volto.setuphandlers import NO_RICHTEXT_BEHAVIOR_CONTENT_TYPES
from plone.volto.setuphandlers import remove_behavior


def from12to13_migrate_listings(context):
Expand Down Expand Up @@ -62,3 +64,8 @@ def migrate_listing(originBlocks):
for brain in pc.unrestrictedSearchResults(object_provides=IBlocks.__identifier__):
obj = brain.getObject()
obj.blocks = migrate_listing(obj.blocks)


def remove_plone_richtext_behavior(context):
for type_ in NO_RICHTEXT_BEHAVIOR_CONTENT_TYPES:
remove_behavior(type_, "plone.richtext")
14 changes: 14 additions & 0 deletions src/plone/volto/upgrades.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,18 @@
import_steps="catalog"
/>

<genericsetup:upgradeSteps
profile="plone.volto:default"
source="1012"
destination="1013"
>
<genericsetup:upgradeDepends
title="Update types info for Plone Site"
import_steps="typeinfo"
/>
<genericsetup:upgradeStep
title="remove plone.richtext from Plone Site, Document, News Item, Event"
handler=".upgrades.remove_plone_richtext_behavior"
/>
</genericsetup:upgradeSteps>
</configure>

0 comments on commit ebfa43e

Please sign in to comment.