Added "oid" TALES extension
authorThierry Florac <thierry.florac@onf.fr>
Fri, 16 Nov 2018 12:05:51 +0100
changeset 77 aee019c4058e
parent 76 652a0f7b56c4
child 78 78dc9447f0cc
Added "oid" TALES extension
src/pyams_sequence/sequence.py
--- a/src/pyams_sequence/sequence.py	Tue Oct 30 14:26:01 2018 +0100
+++ b/src/pyams_sequence/sequence.py	Fri Nov 16 12:05:51 2018 +0100
@@ -12,18 +12,14 @@
 
 __docformat__ = 'restructuredtext'
 
-
-# import standard library
-
-# import interfaces
-from pyams_sequence.interfaces import ISequentialIdInfo, ISequentialIdTarget, ISequentialIntIds
+from persistent import Persistent
+from zope.interface import Interface, implementer
+from zope.schema.fieldproperty import FieldProperty
 
-# import packages
-from persistent import Persistent
-from pyams_utils.adapter import adapter_config, get_annotation_adapter
+from pyams_sequence.interfaces import ISequentialIdInfo, ISequentialIdTarget, ISequentialIntIds
+from pyams_utils.adapter import ContextRequestViewAdapter, adapter_config, get_annotation_adapter
+from pyams_utils.interfaces.tales import ITALESExtension
 from pyams_utils.registry import get_utility
-from zope.interface import implementer
-from zope.schema.fieldproperty import FieldProperty
 
 
 @implementer(ISequentialIdInfo)
@@ -58,3 +54,14 @@
     """Sequential ID info factory"""
     return get_annotation_adapter(context, SEQUENCE_INFO_KEY, SequentialIdInfo,
                                   notify=False, locate=False)
+
+
+@adapter_config(name='oid', context=(Interface, Interface, Interface), provides=ITALESExtension)
+class OidTalesExtension(ContextRequestViewAdapter):
+    """tales:oid(context) TALES extension"""
+
+    @staticmethod
+    def render(context):
+        info = ISequentialIdInfo(context, None)
+        if info is not None:
+            return info.public_oid