|
1 # |
|
2 # Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net> |
|
3 # All Rights Reserved. |
|
4 # |
|
5 # This software is subject to the provisions of the Zope Public License, |
|
6 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. |
|
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
|
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
|
10 # FOR A PARTICULAR PURPOSE. |
|
11 # |
|
12 |
|
13 __docformat__ = 'restructuredtext' |
|
14 |
|
15 |
|
16 # import standard library |
|
17 |
|
18 # import interfaces |
|
19 from pyams_content.shared.view.portlet.interfaces import IViewItemsPortletSettings |
|
20 from pyams_portal.interfaces import IPortalContext, IPortletRenderer |
|
21 from pyams_skin.layer import IPyAMSLayer |
|
22 from pyams_utils.interfaces import PUBLIC_PERMISSION |
|
23 |
|
24 # import packages |
|
25 from pyams_content.workflow import PUBLISHED_STATES |
|
26 from pyams_portal.portlet import PortletSettings, portlet_config, Portlet, PortletRenderer |
|
27 from pyams_sequence.utility import get_sequence_target |
|
28 from pyams_template.template import template_config |
|
29 from pyams_utils.adapter import adapter_config |
|
30 from zope.interface import implementer, Interface |
|
31 from zope.schema.fieldproperty import FieldProperty |
|
32 |
|
33 from pyams_content import _ |
|
34 |
|
35 |
|
36 VIEW_PORTLET_NAME = 'pyams_content.portlet.view' |
|
37 |
|
38 |
|
39 @implementer(IViewItemsPortletSettings) |
|
40 class ViewItemsPortletSettings(PortletSettings): |
|
41 """View items portlet settings""" |
|
42 |
|
43 view = FieldProperty(IViewItemsPortletSettings['view']) |
|
44 |
|
45 def get_view(self): |
|
46 if self.view is not None: |
|
47 return get_sequence_target(self.view, state=PUBLISHED_STATES) |
|
48 |
|
49 def get_items(self, context): |
|
50 view = self.get_view() |
|
51 if view is not None: |
|
52 return view.get_results(context) |
|
53 |
|
54 |
|
55 @portlet_config(permission=PUBLIC_PERMISSION) |
|
56 class ViewItemsPortlet(Portlet): |
|
57 """View items portlet""" |
|
58 |
|
59 name = VIEW_PORTLET_NAME |
|
60 label = _("View items") |
|
61 |
|
62 toolbar_image = None |
|
63 toolbar_css_class = 'fa fa-fw fa-2x fa-th-list' |
|
64 |
|
65 settings_class = ViewItemsPortletSettings |
|
66 |
|
67 |
|
68 @adapter_config(context=(IPortalContext, IPyAMSLayer, Interface, IViewItemsPortletSettings), provides=IPortletRenderer) |
|
69 @template_config(template='templates/view-items-list.pt', layer=IPyAMSLayer) |
|
70 class ViewItemsPortletRenderer(PortletRenderer): |
|
71 """View items portlet renderer""" |
|
72 |
|
73 label = _("Simple list view") |