Removed DocFieldProperty class and added __doc__ property to default FieldProperty class
authorThierry Florac <thierry.florac@onf.fr>
Thu, 12 Apr 2018 11:21:59 +0200
changeset 170 0013ddcfdc37
parent 169 5c6a816ffb86
child 171 d6c77b2b5c4b
child 253 146a0deffad8
Removed DocFieldProperty class and added __doc__ property to default FieldProperty class
src/pyams_utils/__init__.py
src/pyams_utils/property.py
src/pyams_utils/timezone/utility.py
src/pyams_utils/zodb.py
--- a/src/pyams_utils/__init__.py	Thu Apr 12 10:14:52 2018 +0200
+++ b/src/pyams_utils/__init__.py	Thu Apr 12 11:21:59 2018 +0200
@@ -18,11 +18,25 @@
 # import interfaces
 
 # import packages
+from zope.schema.fieldproperty import FieldProperty
 
 from pyramid.i18n import TranslationStringFactory
 _ = TranslationStringFactory('pyams_utils')
 
 
+def get_field_doc(self):
+    field = self._FieldProperty__field
+    if field.title and field.description:
+        return '{0}: {1}'.format(field.title, field.description)
+    elif field.title:
+        return field.title
+    else:
+        return super(self.__class__, self).__doc__
+
+
+FieldProperty.__doc__ = property(get_field_doc)
+
+
 def includeme(config):
     """pyams_utils features include"""
     from .include import include_package
--- a/src/pyams_utils/property.py	Thu Apr 12 10:14:52 2018 +0200
+++ b/src/pyams_utils/property.py	Thu Apr 12 11:21:59 2018 +0200
@@ -18,25 +18,6 @@
 # import interfaces
 
 # import packages
-from zope.schema.fieldproperty import FieldProperty
-
-
-class DocFieldProperty(FieldProperty):
-    """Field property with doc
-
-    This field property class extracts it's docstring from parent field description, if any.
-    It's main purpose is for documentation needs.
-    """
-
-    @property
-    def __doc__(self):
-        field = self._FieldProperty__field
-        if field.title and field.description:
-            return '{0}: {1}'.format(field.title, field.description)
-        elif field.title:
-            return field.title
-        else:
-            return super(FieldProperty, self).__doc__
 
 
 class cached(object):
--- a/src/pyams_utils/timezone/utility.py	Thu Apr 12 10:14:52 2018 +0200
+++ b/src/pyams_utils/timezone/utility.py	Thu Apr 12 11:21:59 2018 +0200
@@ -21,17 +21,17 @@
 
 # import packages
 from persistent import Persistent
-from pyams_utils.property import DocFieldProperty
 from pyams_utils.registry import utility_config
 from pyams_utils.site import check_required_utilities
 from zope.container.contained import Contained
 from zope.interface import implementer
+from zope.schema.fieldproperty import FieldProperty
 
 
 @implementer(IServerTimezone)
 class ServerTimezoneUtility(Persistent, Contained):
 
-    timezone = DocFieldProperty(IServerTimezone['timezone'])
+    timezone = FieldProperty(IServerTimezone['timezone'])
 
 
 REQUIRED_UTILITIES = ((IServerTimezone, '', ServerTimezoneUtility, 'Server timezone'),)
--- a/src/pyams_utils/zodb.py	Thu Apr 12 10:14:52 2018 +0200
+++ b/src/pyams_utils/zodb.py	Thu Apr 12 11:21:59 2018 +0200
@@ -27,7 +27,6 @@
 # import packages
 from persistent import Persistent
 from pyams_utils.adapter import adapter_config
-from pyams_utils.property import DocFieldProperty
 from pyams_utils.registry import get_utilities_for, get_global_registry
 from pyams_utils.vocabulary import vocabulary_config
 from pyramid.events import subscriber
@@ -36,6 +35,7 @@
 from zope.container.contained import Contained
 from zope.interface import implementer
 from zope.schema import getFieldNames
+from zope.schema.fieldproperty import FieldProperty
 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
 
 
@@ -102,15 +102,15 @@
     _db = None
     _connection = None
 
-    name = DocFieldProperty(IZEOConnection['name'])
-    server_name = DocFieldProperty(IZEOConnection['server_name'])
-    server_port = DocFieldProperty(IZEOConnection['server_port'])
-    storage = DocFieldProperty(IZEOConnection['storage'])
-    username = DocFieldProperty(IZEOConnection['username'])
-    password = DocFieldProperty(IZEOConnection['password'])
-    server_realm = DocFieldProperty(IZEOConnection['server_realm'])
-    blob_dir = DocFieldProperty(IZEOConnection['blob_dir'])
-    shared_blob_dir = DocFieldProperty(IZEOConnection['shared_blob_dir'])
+    name = FieldProperty(IZEOConnection['name'])
+    server_name = FieldProperty(IZEOConnection['server_name'])
+    server_port = FieldProperty(IZEOConnection['server_port'])
+    storage = FieldProperty(IZEOConnection['storage'])
+    username = FieldProperty(IZEOConnection['username'])
+    password = FieldProperty(IZEOConnection['password'])
+    server_realm = FieldProperty(IZEOConnection['server_realm'])
+    blob_dir = FieldProperty(IZEOConnection['blob_dir'])
+    shared_blob_dir = FieldProperty(IZEOConnection['shared_blob_dir'])
 
     def get_settings(self):
         """Get mapping of all connection settings