Skip to content

Commit

Permalink
Merge pull request #85 from plone/dxcontainer-siteroot
Browse files Browse the repository at this point in the history
Dx container site root
  • Loading branch information
jensens authored Aug 20, 2021
2 parents 12101f6 + 1fbd494 commit f0ca303
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Bug fixes:


- Fixes test to work clean with zope.interface.
Interfaces are hashed based on just their name and module.
Interfaces are hashed based on just their name and module.
So every one of these local `IBlank` interfaces will hash the same way, and be treated the same for purposes of zope.interface's `_dependents`.
Thus in tests mock interfaces must not be used under the same name in the same module.
[jensens] (#135)
Expand Down
4 changes: 4 additions & 0 deletions news/85.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fix ft._updateProperty so it doesn't break when receiving an empty value.
This happens when an DX FTI is part of a Generic Setup baseline import.
Update more code to work when the Plone Site is a dexterity item.
[jaroel]
6 changes: 5 additions & 1 deletion plone/dexterity/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from zope.security.interfaces import IPermission

import six
import warnings
import threading


Expand Down Expand Up @@ -766,7 +767,10 @@ def __getattr__(self, name):
pass

# Be specific about the implementation we use
return CMFOrderedBTreeFolderBase.__getattr__(self, name)
if self._tree is not None:
return CMFOrderedBTreeFolderBase.__getattr__(self, name)

raise AttributeError(name)

@security.protected(permissions.DeleteObjects)
def manage_delObjects(self, ids=None, REQUEST=None):
Expand Down
2 changes: 1 addition & 1 deletion plone/dexterity/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def description(self):
def __call__(self, *args, **kw):
fti = getUtility(IDexterityFTI, name=self.portal_type)

klass = resolveDottedName(fti.klass)
klass = resolveDottedName(fti.klass) if fti.klass else None
if klass is None or not callable(klass):
raise ValueError(
"Content class %s set for type %s is not valid"
Expand Down
8 changes: 5 additions & 3 deletions plone/dexterity/fti.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def __init__(self, *args, **kwargs):

# Set the content_meta_type from the klass

klass = utils.resolveDottedName(self.klass)
klass = utils.resolveDottedName(self.klass) if self.klass else None
if klass is not None:
self.content_meta_type = getattr(klass, "meta_type", None)

Expand Down Expand Up @@ -228,7 +228,7 @@ def Metatype(self):
if self.content_meta_type:
return self.content_meta_type
# BBB - this didn't use to be set
klass = utils.resolveDottedName(self.klass)
klass = utils.resolveDottedName(self.klass) if self.klass else None
if klass is not None:
self.content_meta_type = getattr(klass, "meta_type", None)
return self.content_meta_type
Expand Down Expand Up @@ -301,7 +301,9 @@ def _updateProperty(self, id, value):

# Update meta_type from klass
if id == "klass":
klass = utils.resolveDottedName(new_value)
klass = None
if new_value:
klass = utils.resolveDottedName(new_value)
if klass is not None:
self.content_meta_type = getattr(klass, "meta_type", None)

Expand Down
14 changes: 12 additions & 2 deletions plone/dexterity/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from zope.component import getAllUtilitiesRegisteredFor
from zope.component import getUtility
from zope.component import queryUtility
from zope.component.hooks import getSite
from zope.dottedname.resolve import resolve
from zope.globalrequest import getRequest
from zope.interface import alsoProvides
Expand Down Expand Up @@ -65,9 +66,11 @@ def lookup_fti(portal_type, cache=True):
if fti_cache is None:
fti_cache = dict()
setattr(request, FTI_CACHE_KEY, fti_cache)
fti = None
if portal_type in fti_cache:
fti = fti_cache[portal_type]
else:

if fti is None:
fti_cache[portal_type] = fti = queryUtility(
IDexterityFTI, name=portal_type
)
Expand Down Expand Up @@ -321,7 +324,14 @@ def split(self, s):
def portalTypeToSchemaName(portal_type, schema=u"", prefix=None, suffix=None):
"""Return a canonical interface name for a generated schema interface."""
if prefix is None:
prefix = "/".join(getUtility(ISiteRoot).getPhysicalPath())[1:]
siteroot = None
if portal_type == "Plone Site":
fti = queryUtility(IDexterityFTI, name=portal_type)
if fti is not None:
siteroot = fti.__parent__
if siteroot is None:
siteroot = getUtility(ISiteRoot)
prefix = "/".join(siteroot.getPhysicalPath())[1:]
if suffix:
prefix = "|".join([prefix, suffix])

Expand Down

0 comments on commit f0ca303

Please sign in to comment.