Skip to content

Commit

Permalink
[FIX] document field: adapt fix to handle multiple backends
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-halleux committed Jun 21, 2022
1 parent 791c02c commit 44262bb
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions cmis_field/fields/cmis_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,39 @@ class CmisDocument(fields.Field):
'create_method': None
}

def __init__(self, backend_name=None, string=None, **kwargs):
super(CmisDocument, self).__init__(
backend_name=backend_name, string=string, **kwargs)
def __init__(self, string=None, **kwargs):
super(CmisDocument, self).__init__(string=string, **kwargs)

def _is_registry_loading_mode(self, env):
"""
Check if we are in the installation process.
"""
return env.context.get("install_mode")

def get_backend(self, env, raise_if_not_found=True):
return env['cmis.backend'].get_by_name(
self.backend_name, raise_if_not_found)

def _description_backend(self, env):
backend = self.get_backend(env, raise_if_not_found=False)
if self.inherited:
# In the case of a cmis field inherited from another module
# the attribute backend_name is not inherited so we have to
# get it on the original fiel
backend = self.inherited_field.get_backend(env, raise_if_not_found=False)
else:
backend = self.get_backend(env, raise_if_not_found=False)
if len(backend) > 1:
if self._is_registry_loading_mode(env):
# While the registry is loading, specific attributes are not available
# on the field (such as `backend_name`). At this stage, the fields
# are accessed to validate the xml views of the module being
# loaded/updated. We can therefore safely takes the first backend
# into the list.
backend = backend[:1]
else:
msg = (_('Too many backend found. '
'Please check your configuration.'))
return {'backend_error': msg}
if not backend:
if self.backend_name:
msg = (_('Backend named %s not found. '
Expand Down

0 comments on commit 44262bb

Please sign in to comment.