# HG changeset patch # User Damien Correia # Date 1523526196 -7200 # Node ID 146a0deffad83100722acb83020eebcaefa18079 # Parent 05af55de9eabd3fe08da6870f78161b681bf2560# Parent 0013ddcfdc375ca15462be51a54355281c01bc62 merge default diff -r 05af55de9eab -r 146a0deffad8 src/pyams_utils/__init__.py --- a/src/pyams_utils/__init__.py Mon Apr 09 17:05:53 2018 +0200 +++ b/src/pyams_utils/__init__.py Thu Apr 12 11:43:16 2018 +0200 @@ -21,11 +21,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 diff -r 05af55de9eab -r 146a0deffad8 src/pyams_utils/cache.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_utils/cache.py Thu Apr 12 11:43:16 2018 +0200 @@ -0,0 +1,38 @@ +# +# Copyright (c) 2008-2015 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# + +__docformat__ = 'restructuredtext' + + +# import standard library + +# import interfaces +from persistent.interfaces import IPersistent +from pyams_utils.interfaces import ICacheKeyValue + +# import packages +from pyams_utils.adapter import adapter_config + + +@adapter_config(context=object, provides=ICacheKeyValue) +def object_cache_key_adapter(obj): + return str(id(obj)) + + +@adapter_config(context=str, provides=ICacheKeyValue) +def string_cache_key_adapter(obj): + return obj + + +@adapter_config(context=IPersistent, provides=ICacheKeyValue) +def persistent_cache_key_adapter(obj): + return str(int.from_bytes(obj._p_oid, byteorder='big')) diff -r 05af55de9eab -r 146a0deffad8 src/pyams_utils/property.py --- a/src/pyams_utils/property.py Mon Apr 09 17:05:53 2018 +0200 +++ b/src/pyams_utils/property.py Thu Apr 12 11:43:16 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): diff -r 05af55de9eab -r 146a0deffad8 src/pyams_utils/site.py --- a/src/pyams_utils/site.py Mon Apr 09 17:05:53 2018 +0200 +++ b/src/pyams_utils/site.py Thu Apr 12 11:43:16 2018 +0200 @@ -17,7 +17,7 @@ # import interfaces from pyams_utils.interfaces import PYAMS_APPLICATION_SETTINGS_KEY, PYAMS_APPLICATION_DEFAULT_NAME, \ - PYAMS_APPLICATION_FACTORY_KEY + PYAMS_APPLICATION_FACTORY_KEY, PUBLIC_PERMISSION from pyams_utils.interfaces.site import ISiteRoot, ISiteRootFactory, INewLocalSiteCreatedEvent, ISiteUpgradeEvent, \ ISiteGenerations, SITE_GENERATIONS_KEY, IConfigurationManager from zope.annotation.interfaces import IAnnotations @@ -30,7 +30,7 @@ from pyams_utils.registry import get_utilities_for, query_utility from pyramid.exceptions import NotFound from pyramid.path import DottedNameResolver -from pyramid.security import Allow, ALL_PERMISSIONS +from pyramid.security import Allow, Everyone, ALL_PERMISSIONS from pyramid.threadlocal import get_current_registry from pyramid_zodbconn import get_connection from zope.container.folder import Folder @@ -47,10 +47,13 @@ A site root can be used as base application root in your ZODB. It's also site root responsibility to manage your local site manager. - BaseSiteRoot defines a basic ACL which gives all permissions to system administrator. + BaseSiteRoot defines a basic ACL which gives all permissions to system administrator, + and 'public' permission to everyone. But this ACL is generally overriden in subclasses + which also inherit from :class:`pyams_security.security.ProtectedObject`. """ - __acl__ = [(Allow, 'system:admin', ALL_PERMISSIONS)] + __acl__ = [(Allow, 'system:admin', ALL_PERMISSIONS), + (Allow, Everyone, {PUBLIC_PERMISSION})] config_klass = None diff -r 05af55de9eab -r 146a0deffad8 src/pyams_utils/timezone/utility.py --- a/src/pyams_utils/timezone/utility.py Mon Apr 09 17:05:53 2018 +0200 +++ b/src/pyams_utils/timezone/utility.py Thu Apr 12 11:43:16 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'),) diff -r 05af55de9eab -r 146a0deffad8 src/pyams_utils/zmi/timezone.py --- a/src/pyams_utils/zmi/timezone.py Mon Apr 09 17:05:53 2018 +0200 +++ b/src/pyams_utils/zmi/timezone.py Thu Apr 12 11:43:16 2018 +0200 @@ -35,6 +35,8 @@ class ServerTimezonePropertiesEditForm(AdminDialogEditForm): """Server timezone properties edit form""" + prefix = 'timezone_properties.' + legend = _("Update server timezone properties") fields = field.Fields(IServerTimezone) ajax_handler = 'properties.json' diff -r 05af55de9eab -r 146a0deffad8 src/pyams_utils/zmi/zeo.py --- a/src/pyams_utils/zmi/zeo.py Mon Apr 09 17:05:53 2018 +0200 +++ b/src/pyams_utils/zmi/zeo.py Thu Apr 12 11:43:16 2018 +0200 @@ -117,6 +117,8 @@ class ZEOConnectionPropertiesEditForm(AdminDialogEditForm): """ZEO connection properties edit form""" + prefix = 'zeo_properties.' + @property def title(self): translate = self.request.localizer.translate @@ -218,14 +220,18 @@ settings = '{0}\n\n'.format(pprint.pformat(self.context.get_settings())) status, arguments = changes if status == 200: - return {'status': 'success', - 'content': {'html': '{0}
{1}'.format(settings, arguments)}, - 'close_form': False} + return { + 'status': 'success', + 'content': {'html': '{0}
{1}'.format(settings, arguments)}, + 'close_form': False + } else: typ, value, tb = arguments message = 'An error occurred: {type}
{message}'.format(type=typ, message='
'.join( traceback.format_exception(typ, value, tb))) - return {'status': 'info', - 'content': {'html': '{0}
{1}'.format(settings, message)}, - 'close_form': False} + return { + 'status': 'info', + 'content': {'html': '{0}
{1}'.format(settings, message)}, + 'close_form': False + } diff -r 05af55de9eab -r 146a0deffad8 src/pyams_utils/zodb.py --- a/src/pyams_utils/zodb.py Mon Apr 09 17:05:53 2018 +0200 +++ b/src/pyams_utils/zodb.py Thu Apr 12 11:43:16 2018 +0200 @@ -17,7 +17,6 @@ # import interfaces from persistent.interfaces import IPersistent -from pyams_utils.interfaces import ICacheKeyValue from pyams_utils.interfaces.site import IOptionalUtility from pyams_utils.interfaces.zeo import IZEOConnection from transaction.interfaces import ITransactionManager @@ -28,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 @@ -37,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 @@ -71,16 +70,6 @@ # recent spelling. -@adapter_config(context=object, provides=ICacheKeyValue) -def object_key_adapter(obj): - return str(id(obj)) - - -@adapter_config(context=str, provides=ICacheKeyValue) -def string_key_adapter(obj): - return obj - - # # ZEO connection management # @@ -113,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