Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refs #136 - Update dynamic schema on all ZEO clients on change #137

Merged
merged 3 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions news/136.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Make sure that Dynamic schema is updated on all ZEO clients on change
[@avoinea]
7 changes: 4 additions & 3 deletions plone/dexterity/fti.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ def lookupSchema(self):
# Otherwise, look up a dynamic schema. This will query the model for
# an unnamed schema if it is the first time it is looked up.
# See schema.py

schemaName = portalTypeToSchemaName(self.getId())
mtime = getattr(self, "_p_mtime", None) or ""
schemaName = portalTypeToSchemaName(self.getId(), suffix=str(mtime))
return getattr(plone.dexterity.schema.generated, schemaName)

def lookupModel(self):
Expand Down Expand Up @@ -553,7 +553,8 @@ def ftiModified(object, event):
if (fti.model_source or fti.model_file) \
and ('model_source' in mod or 'model_file' in mod or 'schema_policy' in mod):

schemaName = portalTypeToSchemaName(portal_type)
mtime = getattr(fti, "_p_mtime", None) or ""
schemaName = portalTypeToSchemaName(portal_type, suffix=str(mtime))
schema = getattr(plone.dexterity.schema.generated, schemaName)

model = fti.lookupModel()
Expand Down
7 changes: 5 additions & 2 deletions plone/dexterity/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ class SchemaNameEncoder(object):
('.', '_2_'),
('-', '_3_'),
('/', '_4_'),
('|', '_5_'),
)

def encode(self, s):
Expand All @@ -321,11 +322,13 @@ def split(self, s):
return [self.decode(a) for a in s.split('_0_')]


def portalTypeToSchemaName(portal_type, schema=u"", prefix=None):
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:]
if suffix:
prefix = '|'.join([prefix, suffix])

encoder = SchemaNameEncoder()
return encoder.join(prefix, portal_type, schema)
Expand Down Expand Up @@ -377,7 +380,6 @@ def __call__(self, name, module):
module using setattr(). This means that the factory will not be
invoked again.
"""

try:
prefix, portal_type, schemaName = splitSchemaName(name)
except ValueError:
Expand Down Expand Up @@ -412,6 +414,7 @@ def __call__(self, name, module):
if name in self._transient_SCHEMA_CACHE:
del self._transient_SCHEMA_CACHE[name]

log.debug("Dynamic schema generated: %s", name)
setattr(module, name, schema)

return schema
Expand Down