Get view's internal references into given order
authorThierry Florac <thierry.florac@onf.fr>
Fri, 26 Oct 2018 09:01:36 +0200
changeset 1042 375c07107cf2
parent 1041 e22f30b4ef3a
child 1043 18aaa69eee31
Get view's internal references into given order
src/pyams_content/shared/view/reference.py
--- a/src/pyams_content/shared/view/reference.py	Fri Oct 26 09:00:07 2018 +0200
+++ b/src/pyams_content/shared/view/reference.py	Fri Oct 26 09:01:36 2018 +0200
@@ -12,27 +12,22 @@
 
 __docformat__ = 'restructuredtext'
 
-
-# import standard library
-from persistent import Persistent
-
-# import interfaces
+from hypatia.catalog import CatalogQuery
 from hypatia.interfaces import ICatalog
-from pyams_content.shared.view.interfaces import IWfView, IViewSettings, IViewInternalReferencesSettings, \
-    IViewQueryParamsExtension, IViewQueryFilterExtension, VIEW_REFERENCES_SETTINGS_KEY, ALWAYS_REFERENCE_MODE
-from pyams_sequence.interfaces import ISequentialIdInfo
-
-# import packages
-from hypatia.catalog import CatalogQuery
-from hypatia.query import Any, NotEq
-from pyams_catalog.query import CatalogResultSet, and_
-from pyams_content.workflow import VISIBLE_STATES
-from pyams_utils.adapter import adapter_config, ContextAdapter, get_annotation_adapter
-from pyams_utils.registry import get_utility
+from hypatia.query import Any, Eq, NotEq
+from persistent import Persistent
 from zope.container.contained import Contained
 from zope.interface import implementer
 from zope.schema.fieldproperty import FieldProperty
 
+from pyams_catalog.query import CatalogResultSet, and_
+from pyams_content.shared.view.interfaces import ALWAYS_REFERENCE_MODE, IViewInternalReferencesSettings, \
+    IViewQueryFilterExtension, IViewQueryParamsExtension, IViewSettings, IWfView, VIEW_REFERENCES_SETTINGS_KEY
+from pyams_content.workflow import VISIBLE_STATES
+from pyams_sequence.interfaces import ISequentialIdInfo
+from pyams_utils.adapter import ContextAdapter, adapter_config, get_annotation_adapter
+from pyams_utils.registry import get_utility
+
 
 @implementer(IViewInternalReferencesSettings)
 class ViewInternalReferencesSettings(Persistent, Contained):
@@ -86,7 +81,8 @@
             return items
         if (not items) or (settings.references_mode == ALWAYS_REFERENCE_MODE):
             catalog = get_utility(ICatalog)
-            params = Any(catalog['oid'], settings.references) & \
-                Any(catalog['workflow_state'], VISIBLE_STATES)
-            items.prepend(CatalogResultSet(CatalogQuery(catalog).query(params)))
+            for reference in settings.references:
+                params = Eq(catalog['oid'], reference) & \
+                         Any(catalog['workflow_state'], VISIBLE_STATES)
+                items.prepend(CatalogResultSet(CatalogQuery(catalog).query(params)))
         return items