diff -r 30602138e7f7 -r ac40004d7c73 src/pyams_content/shared/view/reference.py --- a/src/pyams_content/shared/view/reference.py Mon Jan 07 11:36:09 2019 +0100 +++ b/src/pyams_content/shared/view/reference.py Tue Jan 08 14:02:06 2019 +0100 @@ -47,7 +47,7 @@ refs = [] if self.select_context_references: references = IInternalReferencesList(context, None) - if references is not None: + if (references is not None) and references.references: refs.extend(references.references) if self.references: refs.extend(self.references) @@ -70,31 +70,44 @@ def get_params(self, context, request=None): settings = IViewInternalReferencesSettings(self.context) - catalog = get_utility(ICatalog) - # check view settings - if settings.exclude_context: - sequence = ISequentialIdInfo(context, None) - if sequence is not None: - oid = sequence.hex_oid - yield NotEq(catalog['oid'], oid) # check view references mode if settings.references_mode == ONLY_REFERENCE_MODE: - yield Any(catalog['oid'], settings.references), False + # references are retrieved by query filter extension, so no params are required! + yield None + else: + # check view settings + if settings.exclude_context: + sequence = ISequentialIdInfo(context, None) + if sequence is not None: + oid = sequence.hex_oid + catalog = get_utility(ICatalog) + yield NotEq(catalog['oid'], oid) @adapter_config(name='references', context=IWfView, provides=IViewQueryFilterExtension) class ViewInternalReferencesQueryFilterExtension(ContextAdapter): - """View internal references filter extension""" + """View internal references filter extension + + If internal references are selected, these references are forced. + """ weight = 999 def filter(self, context, items, request=None): settings = IViewInternalReferencesSettings(self.context) - if not settings.references: + references = settings.get_references(context) + if not references: return items - if (not items) or (settings.references_mode == ALWAYS_REFERENCE_MODE): + excluded_oid = None + if settings.exclude_context: + sequence = ISequentialIdInfo(context, None) + if sequence is not None: + excluded_oid = sequence.hex_oid + if (not items) or (settings.references_mode in (ALWAYS_REFERENCE_MODE, ONLY_REFERENCE_MODE)): catalog = get_utility(ICatalog) - for reference in settings.references: + for reference in reversed(references): + if reference == excluded_oid: + continue params = Eq(catalog['oid'], reference) & \ Any(catalog['workflow_state'], VISIBLE_STATES) items.prepend(CatalogResultSet(CatalogQuery(catalog).query(params)))