# HG changeset patch # User Thierry Florac # Date 1498638263 -7200 # Node ID aa2472483e0011bac42dad15368659f3a2a54156 # Parent a19dd404951e3bfbcc88a278493f14412813dbd8 Updated sequence utility interface diff -r a19dd404951e -r aa2472483e00 src/pyams_sequence/interfaces/__init__.py --- a/src/pyams_sequence/interfaces/__init__.py Wed Jun 07 10:52:03 2017 +0200 +++ b/src/pyams_sequence/interfaces/__init__.py Wed Jun 28 10:24:23 2017 +0200 @@ -53,6 +53,12 @@ def get_short_oid(self, oid, obj_prefix=None): """Get short ID based on given numeric object ID""" + def get_internal_id(self, oid): + """Get internal ID matching given OID""" + + def query_object_from_oid(self, oid): + """Query object with given OID""" + class ISequentialIdInfo(Interface): """Sequential ID info interface""" diff -r a19dd404951e -r aa2472483e00 src/pyams_sequence/utility.py --- a/src/pyams_sequence/utility.py Wed Jun 07 10:52:03 2017 +0200 +++ b/src/pyams_sequence/utility.py Wed Jun 28 10:24:23 2017 +0200 @@ -69,6 +69,17 @@ sequence.get_short_oid(info.oid))} +def get_sequence_target(oid, state): + """Get content matching given OID""" + sequence = get_utility(ISequentialIntIds) + content = sequence.query_object_from_oid(oid) + if handle_workflow and (IWorkflowVersion.providedBy(content) or IWorkflowManagedContent.providedBy(content)): + versions = IWorkflowVersions(content).get_versions(state, sort=True) + if versions: + content = versions[0] + return content + + @implementer(ISequentialIntIds) class SequentialIntIds(IntIds): """Sequential IntIds utility""" @@ -106,10 +117,10 @@ hex_id=oid) def get_full_oid(self, oid, obj_prefix=None): - if self.prefix and oid.startswith(self.prefix or ''): - return oid if oid.startswith('+'): oid = oid[1:] + elif self.prefix and oid.startswith(self.prefix): + return oid return '{prefix}{obj_prefix}{zeros}{hex_id}'.format(prefix=self.prefix or '', obj_prefix=obj_prefix or '', zeros='0' * (self.hex_oid_length - len(oid)), @@ -120,6 +131,17 @@ obj_prefix=obj_prefix or '', hex_id=oid) + def get_internal_id(self, oid): + if oid.startswith('+'): + oid = oid[1:] + elif self.prefix and oid.startswith(self.prefix): + oid = oid[len(self.prefix):] + return int(oid, 16) + + def query_object_from_oid(self, oid): + internal_id = self.get_internal_id(oid) + return self.queryObject(internal_id) + @subscriber(IObjectAddedEvent, context_selector=ISequentialIdTarget) def handle_added_intid_target(event):