--- a/src/pyams_utils/data.py Wed Nov 20 19:26:23 2019 +0100
+++ b/src/pyams_utils/data.py Fri Nov 22 18:51:37 2019 +0100
@@ -12,10 +12,10 @@
"""PyAMS_utils.data module
-The *IObjectData* interface is a generic interface which can be used to assign custom data to any object.
-This object data may be any object which can be serialized to JSON, and assigned to any HTML *data* attribute.
-It can typically be used to set a *data-ams-data* attribute to objects, which is afterwards converted to
-classic *data-* attributes by **MyAMS.js** framework.
+The *IObjectData* interface is a generic interface which can be used to assign custom data to any
+object. This object data may be any object which can be serialized to JSON, and assigned to any
+HTML *data* attribute. It can typically be used to set a *data-ams-data* attribute to objects,
+which is afterwards converted to classic *data-* attributes by **MyAMS.js** framework.
For example, for a custom widget in a form::
@@ -34,8 +34,6 @@
<div data-ams-colorpicker-position="top left">...</div>
"""
-__docformat__ = 'restructuredtext'
-
import json
from pyramid.interfaces import IRequest
@@ -47,6 +45,9 @@
from pyams_utils.interfaces.tales import ITALESExtension
+__docformat__ = 'restructuredtext'
+
+
@adapter_config(context=IObjectData, provides=IObjectDataRenderer)
class ObjectDataRenderer(ContextAdapter):
"""Object data JSON renderer"""
@@ -57,12 +58,14 @@
return json.dumps(data.object_data) if data is not None else None
-@adapter_config(name='object_data', context=(Interface, Interface, Interface), provides=ITALESExtension)
+@adapter_config(name='object_data', context=(Interface, Interface, Interface),
+ provides=ITALESExtension)
class ObjectDataExtension(ContextRequestViewAdapter):
"""extension:object_data TALES extension
This TALES extension is to be used in Chameleon templates to define a custom data attribute
- which stores all object data (see :py:class:`pyams_utils.interfaces.data.IObjectData` interface), like this::
+ which stores all object data (see :py:class:`pyams_utils.interfaces.data.IObjectData`
+ interface), like this::
<div tal:attributes="data-ams-data extension:object_data(context)">...</div>
"""
@@ -74,13 +77,16 @@
renderer = IObjectDataRenderer(context, None)
if renderer is not None:
return renderer.get_object_data()
+ return None
-@adapter_config(name='request_data', context=(Interface, IRequest, Interface), provides=ITALESExtension)
+@adapter_config(name='request_data', context=(Interface, IRequest, Interface),
+ provides=ITALESExtension)
class PyramidRequestDataExtension(ContextRequestViewAdapter):
"""extension:request_data TALES extension for Pyramid request
- This TALES extension can be used to get a request data, previously stored in the request via an annotation.
+ This TALES extension can be used to get a request data, previously stored in the request via
+ an annotation.
For example::
<div tal:content="extension:request_data('my.annotation.key')">...</div>
@@ -91,11 +97,13 @@
return self.request.annotations.get(params)
-@adapter_config(name='request_data', context=(Interface, IBrowserRequest, Interface), provides=ITALESExtension)
+@adapter_config(name='request_data', context=(Interface, IBrowserRequest, Interface),
+ provides=ITALESExtension)
class BrowserRequestDataExtension(ContextRequestViewAdapter):
"""extension:request_data TALES extension for Zope browser request
- This TALES extension can be used to get a request data, previously stored in the request via an annotation.
+ This TALES extension can be used to get a request data, previously stored in the request via
+ an annotation.
For example::
<div tal:content="extension:request_data('my.annotation.key')">...</div>