equal
deleted
inserted
replaced
17 import logging |
17 import logging |
18 logger = logging.getLogger('PyAMS (portal)') |
18 logger = logging.getLogger('PyAMS (portal)') |
19 |
19 |
20 import venusian |
20 import venusian |
21 |
21 |
22 from inspect import isclass |
|
23 |
|
24 # import interfaces |
22 # import interfaces |
25 from pyams_form.interfaces.form import IFormContextPermissionChecker |
23 from pyams_form.interfaces.form import IFormContextPermissionChecker |
26 from pyams_portal.interfaces import IPortlet, IPortletSettings, IPortletConfiguration, IPortletPreviewer, \ |
24 from pyams_portal.interfaces import IPortlet, IPortletSettings, IPortletConfiguration, IPortletPreviewer, \ |
27 IPortletRenderer, IPortalPortletsConfiguration, IPortalTemplate, IPortalContext, IPortalPage, \ |
25 IPortletRenderer, IPortalPortletsConfiguration, IPortalTemplate, IPortalContext, IPortalPage, \ |
28 IPortalTemplateConfiguration, MANAGE_TEMPLATE_PERMISSION, IPortletRendererSettings |
26 IPortalTemplateConfiguration, MANAGE_TEMPLATE_PERMISSION, IPortletRendererSettings |
30 |
28 |
31 # import packages |
29 # import packages |
32 from persistent import Persistent |
30 from persistent import Persistent |
33 from persistent.mapping import PersistentMapping |
31 from persistent.mapping import PersistentMapping |
34 from pyams_utils.adapter import adapter_config, ContextAdapter, get_adapter_weight, get_annotation_adapter |
32 from pyams_utils.adapter import adapter_config, ContextAdapter, get_adapter_weight, get_annotation_adapter |
35 from pyams_utils.factory import get_object_factory |
33 from pyams_utils.factory import get_object_factory, is_interface |
36 from pyams_utils.request import check_request |
34 from pyams_utils.request import check_request |
37 from pyams_utils.vocabulary import vocabulary_config |
35 from pyams_utils.vocabulary import vocabulary_config |
38 from pyams_viewlet.viewlet import ViewContentProvider |
36 from pyams_viewlet.viewlet import ViewContentProvider |
39 from pyramid.exceptions import ConfigurationError |
37 from pyramid.exceptions import ConfigurationError |
40 from pyramid.renderers import render |
38 from pyramid.renderers import render |
217 |
215 |
218 _renderer = FieldProperty(IPortletSettings['renderer']) |
216 _renderer = FieldProperty(IPortletSettings['renderer']) |
219 |
217 |
220 __name__ = '++settings++' |
218 __name__ = '++settings++' |
221 |
219 |
222 def __init__(self, configuration): |
220 def __init__(self, configuration=None): |
223 self.__parent__ = configuration |
221 self.__parent__ = configuration |
224 |
222 |
225 @property |
223 @property |
226 def visible(self): |
224 def visible(self): |
227 return self._renderer != 'hidden' |
225 return self._renderer != 'hidden' |
254 |
252 |
255 @property |
253 @property |
256 def configuration(self): |
254 def configuration(self): |
257 return self.__parent__ |
255 return self.__parent__ |
258 |
256 |
|
257 @configuration.setter |
|
258 def configuration(self, value): |
|
259 if self.__parent__ is None: |
|
260 self.__parent__ = value |
|
261 |
|
262 |
|
263 @adapter_config(context=IPortletSettings, provides=IFormContextPermissionChecker) |
|
264 class PortletSettingsPermissionChecker(ContextAdapter): |
|
265 """Portlet settings permission checker""" |
|
266 |
|
267 edit_permission = MANAGE_TEMPLATE_PERMISSION |
|
268 |
259 |
269 |
260 @adapter_config(context=IPortletSettings, provides=IPortletRendererSettings) |
270 @adapter_config(context=IPortletSettings, provides=IPortletRendererSettings) |
261 def portlet_renderer_settings_adapter(context): |
271 def portlet_renderer_settings_adapter(context): |
262 renderer = context.get_renderer() |
272 renderer = context.get_renderer() |
263 if not renderer.settings_interface: |
273 if not renderer.settings_interface: |
283 _settings = FieldProperty(IPortletConfiguration['settings']) |
293 _settings = FieldProperty(IPortletConfiguration['settings']) |
284 |
294 |
285 def __init__(self, portlet): |
295 def __init__(self, portlet): |
286 self.portlet_name = portlet.name |
296 self.portlet_name = portlet.name |
287 factory = portlet.settings_factory |
297 factory = portlet.settings_factory |
288 if isclass(factory) and issubclass(factory, Interface): |
298 if is_interface(factory): |
289 factory = get_object_factory(factory) |
299 factory = get_object_factory(factory) |
290 assert factory is not None, "Missing portlet settings factory" |
300 assert factory is not None, "Missing portlet settings factory" |
291 self._settings = factory(self) |
301 settings = factory() |
|
302 settings.configuration = self |
|
303 self._settings = settings |
292 |
304 |
293 @property |
305 @property |
294 def can_inherit(self): |
306 def can_inherit(self): |
295 return not IPortalTemplate.providedBy(self.__parent__) |
307 return not IPortalTemplate.providedBy(self.__parent__) |
296 |
308 |
357 |
369 |
358 @adapter_config(context=IPortletConfiguration, provides=IFormContextPermissionChecker) |
370 @adapter_config(context=IPortletConfiguration, provides=IFormContextPermissionChecker) |
359 class PortletConfigurationPermissionChecker(ContextAdapter): |
371 class PortletConfigurationPermissionChecker(ContextAdapter): |
360 """Portlet configuration permission checker""" |
372 """Portlet configuration permission checker""" |
361 |
373 |
362 @property |
374 edit_permission = MANAGE_TEMPLATE_PERMISSION |
363 def edit_permission(self): |
|
364 return MANAGE_TEMPLATE_PERMISSION |
|
365 |
375 |
366 |
376 |
367 # |
377 # |
368 # Template portlets configuration |
378 # Template portlets configuration |
369 # |
379 # |