# HG changeset patch # User Thierry Florac # Date 1505131159 -7200 # Node ID b3d0c3b4c94071d6810d502daca5ac097b382f45 # Parent 7ffbf5c15128a4b106e86479433e456312cd5e4a Added 'get_base_oid' method to sequences interfaces diff -r 7ffbf5c15128 -r b3d0c3b4c940 src/pyams_sequence/interfaces/__init__.py --- a/src/pyams_sequence/interfaces/__init__.py Wed Jul 12 17:45:40 2017 +0200 +++ b/src/pyams_sequence/interfaces/__init__.py Mon Sep 11 13:59:19 2017 +0200 @@ -53,6 +53,9 @@ def get_short_oid(self, oid, obj_prefix=None): """Get short ID based on given numeric object ID""" + def get_base_oid(self, oid, obj_prefix=None): + """Get base ID (without prefix) based on given numeric object ID""" + def get_internal_id(self, oid): """Get internal ID matching given OID""" @@ -69,8 +72,14 @@ hex_oid = TextLine(title=_("Unique ID"), required=False) + def get_full_oid(self): + """Get full OID""" + def get_short_oid(self): - """Get short ID""" + """Get short OID""" + + def get_base_oid(self): + """Get base OID""" class ISequentialIdTarget(IAttributeAnnotatable): diff -r 7ffbf5c15128 -r b3d0c3b4c940 src/pyams_sequence/sequence.py --- a/src/pyams_sequence/sequence.py Wed Jul 12 17:45:40 2017 +0200 +++ b/src/pyams_sequence/sequence.py Mon Sep 11 13:59:19 2017 +0200 @@ -16,12 +16,13 @@ # import standard library # import interfaces -from pyams_sequence.interfaces import ISequentialIdInfo, ISequentialIdTarget +from pyams_sequence.interfaces import ISequentialIdInfo, ISequentialIdTarget, ISequentialIntIds from zope.annotation.interfaces import IAnnotations # import packages from persistent import Persistent from pyams_utils.adapter import adapter_config +from pyams_utils.registry import get_utility from zope.interface import implementer from zope.schema.fieldproperty import FieldProperty @@ -33,6 +34,18 @@ oid = FieldProperty(ISequentialIdInfo['oid']) hex_oid = FieldProperty(ISequentialIdInfo['hex_oid']) + def get_full_oid(self): + sequence = get_utility(ISequentialIntIds) + return sequence.get_full_oid(self.oid) + + def get_short_oid(self): + sequence = get_utility(ISequentialIntIds) + return sequence.get_short_oid(self.oid) + + def get_base_oid(self): + sequence = get_utility(ISequentialIntIds) + return sequence.get_base_oid(self.oid) + SEQUENCE_INFO_KEY = 'pyams_sequence.info' diff -r 7ffbf5c15128 -r b3d0c3b4c940 src/pyams_sequence/utility.py --- a/src/pyams_sequence/utility.py Wed Jul 12 17:45:40 2017 +0200 +++ b/src/pyams_sequence/utility.py Mon Sep 11 13:59:19 2017 +0200 @@ -131,6 +131,10 @@ obj_prefix=obj_prefix or '', hex_id=oid) + def get_base_oid(self, oid, obj_prefix=None): + return '{obj_prefix} {hex_id:x}'.format(obj_prefix=obj_prefix or '', + hex_id=oid) + def get_internal_id(self, oid): if oid.startswith('+'): oid = oid[1:]