Commit b6536ae9 authored by Klaus Wölfel's avatar Klaus Wölfel Committed by Ivan Tyagov

composition: Allow to define default models

Models with workflow state "default" are only considered in composition if no
other valid model is defined. This allows to implement "ingest anything"
policy in wendelin.
parent 53d8645c
...@@ -54,28 +54,36 @@ def _getEffectiveModel(self, start_date, stop_date): ...@@ -54,28 +54,36 @@ def _getEffectiveModel(self, start_date, stop_date):
if not reference: if not reference:
return self return self
query_list = [Query(reference=reference), def get_model_list(excluded_validation_state_list):
Query(portal_type=self.getPortalType()), query_list = [Query(reference=reference),
Query(validation_state=('deleted', 'invalidated'), Query(portal_type=self.getPortalType()),
Query(validation_state=excluded_validation_state_list,
operator='NOT')] operator='NOT')]
if start_date is not None: if start_date is not None:
query_list.append(ComplexQuery(Query(effective_date=None), query_list.append(ComplexQuery(Query(effective_date=None),
Query(effective_date=start_date, Query(effective_date=start_date,
range='<='), range='<='),
logical_operator='OR')) logical_operator='OR'))
if stop_date is not None: if stop_date is not None:
query_list.append(ComplexQuery(Query(expiration_date=None), query_list.append(ComplexQuery(Query(expiration_date=None),
Query(expiration_date=stop_date, Query(expiration_date=stop_date,
range='>'), range='>'),
logical_operator='OR')) logical_operator='OR'))
# XXX What to do the catalog returns nothing (either because 'self' was just # XXX What to do the catalog returns nothing (either because 'self' was just
# created and not yet indexed, or because it was invalidated) ? # created and not yet indexed, or because it was invalidated) ?
# For the moment, we return self if self is invalidated and we raise otherwise. # For the moment, we return self if self is invalidated and we raise otherwise.
# This way, if this happens in activity it may succeed when activity is retried. # This way, if this happens in activity it may succeed when activity is retried.
model_list = self.getPortalObject().portal_catalog.unrestrictedSearchResults( return self.getPortalObject().portal_catalog.unrestrictedSearchResults(
query=ComplexQuery(logical_operator='AND', *query_list), query=ComplexQuery(logical_operator='AND', *query_list),
sort_on=(('version', 'descending'),)) sort_on=(('version', 'descending'),))
# Only include default model if no other valid model found
model_list = get_model_list(
excluded_validation_state_list=('deleted', 'invalidated', 'default'))
if not model_list:
model_list = get_model_list(
excluded_validation_state_list=('deleted', 'invalidated'))
if not model_list: if not model_list:
if self.getValidationState() == 'invalidated': if self.getValidationState() == 'invalidated':
return self return self
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment