Skip to content

Commit

Permalink
Merge pull request #411 from plone/plonebase
Browse files Browse the repository at this point in the history
use plone.base
  • Loading branch information
jensens authored Mar 17, 2023
2 parents a7d7d6a + 3c70daa commit 6325639
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 64 deletions.
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,13 @@ The different aspects involved on a translation are adapted, so it's possible to
Language get/set via an unified adapter
---------------------------------------

In order to access and modify the language of a content type regardless the type (Archetypes/Dexterity) there is a interface/adapter::
In order to access and modify the language of a content type there is a interface/adapter::

Products.CMFPlone.interfaces.ILanguage
plone.base.interfaces.ILanguage

You can use::

from Products.CMFPlone.interfaces import ILanguage
from plone.base.interfaces import ILanguage
language = ILanguage(context).get_language()

or in case you want to set the language of a content::
Expand Down
2 changes: 2 additions & 0 deletions news/411.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Use plone.base imports. Removes deprecation warnings.
[jensens]
28 changes: 14 additions & 14 deletions src/plone/app/multilingual/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<!-- Control panel -->
<browser:page
name="language-controlpanel"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
for="plone.base.interfaces.IPloneSiteRoot"
class=".controlpanel.LanguageControlPanel"
permission="plone.app.controlpanel.Language"
layer="..interfaces.IPloneAppMultilingualInstalled"
Expand All @@ -90,14 +90,14 @@
<!-- Migration Tab -->
<browser:page
name="lp-migration"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
for="plone.base.interfaces.IPloneSiteRoot"
class=".controlpanel.MigrationView"
permission="plone.app.multilingual.ManageTranslations"
layer="..interfaces.IPloneAppMultilingualInstalled"/>

<browser:page
name="multilingual-map"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
for="plone.base.interfaces.IPloneSiteRoot"
class=".controlpanel.multilingualMapView"
permission="plone.app.multilingual.ManageTranslations"
layer="..interfaces.IPloneAppMultilingualInstalled"/>
Expand All @@ -106,7 +106,7 @@
<browser:viewlet
zcml:condition="installed plone.app.controlpanel"
name="plone.app.multilingual.supported-languages-notice"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
for="plone.base.interfaces.IPloneSiteRoot"
view="plone.app.controlpanel.interfaces.IPloneControlPanelView"
manager="plone.app.layout.viewlets.interfaces.IAboveContent"
class=".viewlets.OneLanguageConfiguredNoticeViewlet"
Expand All @@ -116,8 +116,8 @@
<browser:viewlet
zcml:condition="not-installed plone.app.controlpanel"
name="plone.app.multilingual.supported-languages-notice"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
view="Products.CMFPlone.interfaces.controlpanel.IPloneControlPanelView"
for="plone.base.interfaces.IPloneSiteRoot"
view="plone.base.interfaces.controlpanel.IPloneControlPanelView"
manager="plone.app.layout.viewlets.interfaces.IAboveContent"
class=".viewlets.OneLanguageConfiguredNoticeViewlet"
template="templates/languages-notice.pt"
Expand Down Expand Up @@ -172,22 +172,22 @@
<!-- Not Translated Yet -->
<browser:page
name="not_translated_yet"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
for="plone.base.interfaces.IPloneSiteRoot"
class=".helper_views.not_translated_yet"
permission="zope.Public"
layer="..interfaces.IPloneAppMultilingualInstalled"/>

<!-- Multilingual Map ajax helper -->
<browser:page
name="multilingual-map-ajax"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
for="plone.base.interfaces.IPloneSiteRoot"
class=".controlpanel.multilingualMapViewJSON"
permission="plone.app.multilingual.ManageTranslations"
layer="..interfaces.IPloneAppMultilingualInstalled"/>

<!-- Default browser view -->
<browser:view
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
for="plone.base.interfaces.IPloneSiteRoot"
class=".switcher.LanguageSwitcher"
name="language-switcher"
permission="zope.Public"
Expand Down Expand Up @@ -258,31 +258,31 @@
<!-- Optional initial step - reindex Language index -->
<browser:page
name="reindex-language-index"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
for="plone.base.interfaces.IPloneSiteRoot"
class=".migrator.LP2PAMReindexLanguageIndex"
permission="cmf.ManagePortal"
layer="..interfaces.IPloneAppMultilingualInstalled"/>

<!-- Step 1 - Relocates the content if needed -->
<browser:page
name="relocate-content"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
for="plone.base.interfaces.IPloneSiteRoot"
class=".migrator.moveContentToProperRLF"
permission="cmf.ManagePortal"
layer="..interfaces.IPloneAppMultilingualInstalled"/>

<!-- Step 2 - Migrate multilingual catalog info -->
<browser:page
name="transfer-lp-catalog"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
for="plone.base.interfaces.IPloneSiteRoot"
class=".migrator.LP2PAMView"
permission="cmf.ManagePortal"
layer="..interfaces.IPloneAppMultilingualInstalled"/>

<!-- Step 3 - Cleanup tasks after migration -->
<browser:page
name="after-migration-cleanup"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
for="plone.base.interfaces.IPloneSiteRoot"
class=".migrator.LP2PAMAfterView"
permission="cmf.ManagePortal"
layer="..interfaces.IPloneAppMultilingualInstalled"/>
Expand All @@ -299,7 +299,7 @@
<!-- To delete -->
<browser:page
name="lp-migration-after"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
for="plone.base.interfaces.IPloneSiteRoot"
class=".controlpanel.MigrationViewAfter"
permission="plone.app.multilingual.ManageTranslations"
layer="..interfaces.IPloneAppMultilingualInstalled"/>
Expand Down
4 changes: 1 addition & 3 deletions src/plone/app/multilingual/browser/controlpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
from plone.app.uuid.utils import uuidToObject
from plone.base.interfaces import ILanguage
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.controlpanel.browser.language import ( # noqa
LanguageControlPanelForm,
)
from Products.CMFPlone.controlpanel.browser.language import LanguageControlPanelForm
from Products.Five import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from Products.statusmessages.interfaces import IStatusMessage
Expand Down
8 changes: 3 additions & 5 deletions src/plone/app/multilingual/browser/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
from plone.app.multilingual.interfaces import IPloneAppMultilingualInstalled
from plone.app.multilingual.interfaces import ITG
from plone.app.multilingual.interfaces import ITranslatable
from plone.app.multilingual.interfaces import ITranslationManager
from plone.app.multilingual.interfaces import LANGUAGE_INDEPENDENT
from plone.app.multilingual.permissions import ManageTranslations
from plone.base.interfaces import ILanguage
from plone.memoize import view
from plone.registry.interfaces import IRegistry
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.defaultpage import is_default_page
from Products.CMFPlone.utils import safe_unicode
from plone.base.defaultpage import is_default_page
from plone.base.utils import safe_text
from zope.browsermenu.menu import BrowserMenu
from zope.browsermenu.menu import BrowserSubMenuItem
from zope.component import getUtility
Expand Down Expand Up @@ -97,9 +96,8 @@ def getMenuItems(self, context, request):
)
for brain in results:
assets_folder_url = brain.getURL() + "/folder_contents"
assets_folder_title = safe_unicode(brain.Title)
assets_folder_title = safe_text(brain.Title)
break

# Menu items
results = []
results_folder = []
Expand Down
7 changes: 3 additions & 4 deletions src/plone/app/multilingual/browser/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from plone.app.dexterity.behaviors.exclfromnav import IExcludeFromNavigation
from plone.app.layout.navigation.interfaces import INavigationRoot
from plone.app.multilingual import _
from plone.app.multilingual.dx.interfaces import IDexterityTranslatable
from plone.app.multilingual.interfaces import ITranslatable
from plone.app.multilingual.interfaces import ITranslationManager
from plone.app.multilingual.interfaces import LANGUAGE_INDEPENDENT
Expand All @@ -12,7 +11,7 @@
from plone.i18n.locales.languages import _combinedlanguagelist
from plone.i18n.locales.languages import _languagelist
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.utils import _createObjectByType
from plone.base.utils import unrestricted_construct_instance
from Products.Five import BrowserView
from zope.component.hooks import getSite
from zope.event import notify
Expand Down Expand Up @@ -148,8 +147,8 @@ def setUpLanguage(self, code, name):
)

if folder is None:
_createObjectByType(self.folder_type, self.context, folderId)
_createObjectByType(
unrestricted_construct_instance(self.folder_type, self.context, folderId)
unrestricted_construct_instance(
self.folder_type_language_independent,
self.context[folderId],
assets_folder_id,
Expand Down
6 changes: 3 additions & 3 deletions src/plone/app/multilingual/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@
<utility
factory=".setuphandlers.HiddenProfiles"
name="plone.app.multilingual"
provides="Products.CMFPlone.interfaces.INonInstallable"/>
provides="plone.base.interfaces.INonInstallable"/>

<genericsetup:registerProfile
name="default"
title="Multilingual Support"
description="Install to enable multilingual content support with plone.app.multilingual"
directory="profiles/default"
provides="Products.GenericSetup.interfaces.EXTENSION"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
for="plone.base.interfaces.IPloneSiteRoot"
post_handler=".setuphandlers.init_pam"/>

<genericsetup:registerProfile
Expand All @@ -154,7 +154,7 @@
description="Uninstall, removes multilingual content support with plone.app.multilingual"
directory="profiles/uninstall"
provides="Products.GenericSetup.interfaces.EXTENSION"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"/>
for="plone.base.interfaces.IPloneSiteRoot"/>

<genericsetup:importStep
name="plone.app.multilingual_default"
Expand Down
4 changes: 2 additions & 2 deletions src/plone/app/multilingual/dx/cloner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from plone.app.multilingual.interfaces import ITranslationManager
from plone.base.interfaces import ILanguage
from plone.dexterity.utils import iterSchemata
from Products.CMFPlone.utils import safe_unicode
from plone.base.utils import safe_text
from z3c.relationfield import RelationValue
from z3c.relationfield.interfaces import IRelationList
from z3c.relationfield.interfaces import IRelationValue
Expand Down Expand Up @@ -96,7 +96,7 @@ def copy_fields(self, translation):
field_changed = value != translation_value
if field_changed:
changed = True
setattr(translation_adapter, field_name, safe_unicode(value))
setattr(translation_adapter, field_name, safe_text(value))

# If at least one field has been copied over to the translation
# we need to inform subscriber to trigger an ObjectModifiedEvent
Expand Down
2 changes: 1 addition & 1 deletion src/plone/app/multilingual/dx/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

<adapter
for="plone.dexterity.interfaces.IDexterityContent"
provides="Products.CMFPlone.interfaces.ILanguage"
provides="plone.base.interfaces.ILanguage"
factory=".language.Language"/>

<adapter
Expand Down
4 changes: 2 additions & 2 deletions src/plone/app/multilingual/profiles/default/registry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<registry>

<records prefix="plone.bundles/multilingual"
interface='Products.CMFPlone.interfaces.IBundleRegistry'>
interface='plone.base.interfaces.IBundleRegistry'>
<value key="enabled">True</value>
<value key="csscompilation">++resource++plone.app.multilingual.stylesheet/multilingual.css</value>
</records>

<records interface="Products.CMFPlone.interfaces.ITinyMCEResourceTypesSchema" prefix="plone">
<records interface="plone.base.interfaces.ITinyMCEResourceTypesSchema" prefix="plone">
<value key="contains_objects" purge="false"><element>LIF</element></value>
</records>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@

<!-- remove old resource and bundle registration -->
<record name="plone.bundles/plone-legacy.resources"
interface="Products.CMFPlone.interfaces.resources.IBundleRegistry" field="resources">
interface="plone.base.interfaces.resources.IBundleRegistry" field="resources">
<value purge="false">
<element remove="true">multilingual</element>
</value>
</record>
<records prefix="plone.resources/multilingual"
interface='Products.CMFPlone.interfaces.IResourceRegistry'
interface='plone.base.interfaces.IResourceRegistry'
remove="true">
</records>

<!-- register new bundle -->
<records prefix="plone.bundles/multilingual"
interface='Products.CMFPlone.interfaces.IBundleRegistry'>
interface='plone.base.interfaces.IBundleRegistry'>
<value key="enabled">True</value>
<value key="compile">False</value>
<value key="merge_with">logged-in</value>
Expand Down
13 changes: 1 addition & 12 deletions src/plone/app/multilingual/setuphandlers.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
from logging import getLogger
from plone.app.multilingual.browser.setup import SetupMultilingualSite
from plone.app.multilingual.interfaces import ITranslatable
from plone.app.multilingual.itg import addAttributeTG
from plone.base.interfaces import INonInstallable
from Products.CMFPlone.utils import getToolByName
from Products.CMFCore.utils import getToolByName
from zope.component.hooks import getSite
from zope.interface import implementer

import pkg_resources


try:
pkg_resources.get_distribution("plone.app.contenttypes")
except pkg_resources.DistributionNotFound:
HAS_PLONE_APP_CONTENTTYPES = False
else:
HAS_PLONE_APP_CONTENTTYPES = True


@implementer(INonInstallable)
class HiddenProfiles:
Expand Down
6 changes: 3 additions & 3 deletions src/plone/app/multilingual/tests/test_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from plone.registry.interfaces import IRegistry
from plone.testing.z2 import Browser
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.utils import safe_nativestring
from plone.base.utils import safe_text
from urllib.parse import parse_qs
from urllib.parse import urlparse
from zope.component import getUtility
Expand Down Expand Up @@ -759,9 +759,9 @@ def assertUrlsEqual(self, url1, url2):
"""The order of query-strings is sometimes random in python 3
This compares urls disregarding the order.
"""
parsed_url_1 = urlparse(safe_nativestring(url1))
parsed_url_1 = urlparse(safe_text(url1))
parse_qs_1 = parse_qs(parsed_url_1.query)
parsed_url_2 = urlparse(safe_nativestring(url2))
parsed_url_2 = urlparse(safe_text(url2))
parse_qs_2 = parse_qs(parsed_url_2.query)
self.assertEqual(parsed_url_1[0], parsed_url_2[0])
self.assertEqual(parsed_url_1[1], parsed_url_2[1])
Expand Down
6 changes: 2 additions & 4 deletions src/plone/app/multilingual/tests/test_uninstall.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from plone import api
from plone.app.multilingual.testing import ( # noqa
PLONE_APP_MULTILINGUAL_INTEGRATION_TESTING,
)
from plone.app.multilingual.testing import PLONE_APP_MULTILINGUAL_INTEGRATION_TESTING
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from Products.CMFPlone.utils import get_installer
from plone.base.utils import get_installer

import unittest

Expand Down
4 changes: 2 additions & 2 deletions src/plone/app/multilingual/upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from plone.base.interfaces import ILanguage
from plone.registry.interfaces import IRegistry
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.utils import _createObjectByType
from plone.base.utils import unrestricted_construct_instance
from time import time
from zope.component import getUtility

Expand Down Expand Up @@ -70,7 +70,7 @@ def migration_pam_1_to_2(context):
old = portal[old_id]
logger.info(f"{code} - Phase 2: Moving objects into new LRF...")

_createObjectByType(type_name, portal, code)
unrestricted_construct_instance(type_name, portal, code)
new = portal[code]
new.setTitle(name)
ILanguage(new).set_language(code)
Expand Down
6 changes: 3 additions & 3 deletions src/plone/app/multilingual/upgrades.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
name="to_3"
title="Update new registry key"
directory="profiles/upgrades/to_3"
for="Products.CMFPlone.interfaces.IMigratingPloneSiteRoot"
for="plone.base.interfaces.IMigratingPloneSiteRoot"
provides="Products.GenericSetup.interfaces.EXTENSION"
/>

Expand All @@ -40,7 +40,7 @@
name="to_4"
title="Update bundle registration"
directory="profiles/upgrades/to_4"
for="Products.CMFPlone.interfaces.IMigratingPloneSiteRoot"
for="plone.base.interfaces.IMigratingPloneSiteRoot"
provides="Products.GenericSetup.interfaces.EXTENSION"
/>

Expand All @@ -56,7 +56,7 @@
name="to_1000"
title="Update to 1000"
directory="profiles/upgrades/to_1000"
for="Products.CMFPlone.interfaces.IMigratingPloneSiteRoot"
for="plone.base.interfaces.IMigratingPloneSiteRoot"
provides="Products.GenericSetup.interfaces.EXTENSION"
/>

Expand Down

0 comments on commit 6325639

Please sign in to comment.