--- a/src/pyams_sequence/utility.py Mon Jul 02 17:26:40 2018 +0200
+++ b/src/pyams_sequence/utility.py Mon Jul 09 11:42:45 2018 +0200
@@ -104,29 +104,22 @@
return content
-def get_reference_target(reference, state=None):
+def get_reference_target(reference, state=None, request=None):
"""Get target of given reference OID"""
catalog = get_utility(ICatalog)
params = Eq(catalog['oid'], reference)
- if handle_workflow:
+ results = list(CatalogResultSet(CatalogQuery(catalog).query(params)))
+ if results:
if state:
- if not isinstance(state, (list, tuple, set)):
- state = (state,)
- params &= Any(catalog['workflow_state'], state)
- results = list(CatalogResultSet(CatalogQuery(catalog).query(params)))
- if results:
- return results[0]
+ results = list(filter(lambda x: get_version_in_state(x, state), results))
else:
- request = check_request()
- if IPyAMSUserLayer.providedBy(request): # front-office request
+ if request is None:
+ request = check_request()
+ if IPyAMSUserLayer.providedBy(request):
getter = get_visible_version
else:
getter = get_last_version
- results = list(map(getter, CatalogResultSet(CatalogQuery(catalog).query(params))))
- if results:
- return results[0]
- else:
- results = list(CatalogResultSet(CatalogQuery(catalog).query(params)))
+ results = list(map(getter, results))
if results:
return results[0]