source: products/quintagroup.portlet.collection/trunk/quintagroup/portlet/collection/collection.py @ 1572

Last change on this file since 1572 was 1572, checked in by fenix, 10 years ago

initial package import

File size: 5.0 KB
Line 
1import random
2
3from zope.interface import implements
4from zope.component import getMultiAdapter
5
6from plone.portlets.interfaces import IPortletDataProvider
7from plone.portlet.collection import collection as base
8
9from zope import schema
10from zope.formlib import form
11
12from plone.memoize.instance import memoize
13from plone.memoize import ram
14from plone.memoize.compress import xhtml_compress
15
16from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
17from plone.app.vocabularies.catalog import SearchableTextSourceBinder
18from plone.app.form.widgets.uberselectionwidget import UberSelectionWidget
19
20from Products.ATContentTypes.interface import IATTopic
21from plone.portlet.collection.collection import ICollectionPortlet
22
23from quintagroup.portlet.collection import MessageFactory as _
24
25class IQCollectionPortlet(ICollectionPortlet):
26    """A portlet which based on plone.portlet.collection and
27       adds more functionalities.
28    """
29
30    item_attributes = schema.List(title=_(u"Attributes to display"),
31                                  description=_(u"description_attributes", default=u"Select attributes to show for collection item."),
32                                  required=False,
33                                  default=[u"Title", u"Description"],
34                                  value_type=schema.Choice(vocabulary='quintagroup.portlet.collection.vocabularies.PortletAttributesVocabulary'))
35                                 
36    styling = schema.Choice(title=_(u"Portlet style"),
37                            description=_(u"description_styling", default=u"Choose a css style for the porlet."),
38                            required=False,
39                            default=u"",
40                            vocabulary='quintagroup.portlet.collection.vocabularies.PortletCSSVocabulary')
41
42
43    show_item_more = schema.Bool(title=_(u"Show more... link for collection items."),
44                                 description=_(u"If enabled, a more... link will appear in the bottom of the each collection item, "
45                                                "linking to the corresponding item."),
46                                 required=True,
47                                 default=True)
48                       
49    link_title = schema.Bool(title=_(u"Link title."),
50                                 description=_(u"If enabled, title will be shown as link to corresponding object. "),
51                                 required=True,
52                                 default=True)
53
54class Assignment(base.Assignment):
55    """
56    Portlet assignment.   
57    This is what is actually managed through the portlets UI and associated
58    with columns.
59    """
60
61    implements(IQCollectionPortlet)
62
63    item_attributes = [u"Title", u"Description"]
64    styling = u""
65    show_item_more = False
66    link_title = True
67
68    def __init__(self, header=u"", target_collection=None, limit=None,
69                 random=False, show_more=True, show_dates=False,
70                 item_attributes=[], styling=u"", show_item_more=False, link_title=True):
71
72        super(Assignment, self).__init__(header=header,
73            target_collection=target_collection, limit=limit,
74            random=random, show_more=show_more, show_dates=show_dates)
75
76        if len(item_attributes) > 0:
77            self.item_attributes = item_attributes
78        self.styling = styling
79        self.show_item_more = show_item_more
80        self.link_title = link_title
81       
82    @property
83    def title(self):
84        """This property is used to give the title of the portlet in the
85        "manage portlets" screen. Here, we use the title that the user gave.
86        """
87        return self.header
88
89
90class Renderer(base.Renderer):
91    """Portlet renderer.
92   
93    This is registered in configure.zcml. The referenced page template is
94    rendered, and the implicit variable 'view' will refer to an instance
95    of this class. Other methods can be added and referenced in the template.
96    """
97
98    render = ViewPageTemplateFile('collection.pt')
99
100    def showProperty(self, name):
101        return name in self.data.item_attributes
102
103       
104class AddForm(base.AddForm):
105    """Portlet add form.
106   
107    This is registered in configure.zcml. The form_fields variable tells
108    zope.formlib which fields to display. The create() method actually
109    constructs the assignment that is being added.
110    """
111    form_fields = form.Fields(IQCollectionPortlet)
112    form_fields['target_collection'].custom_widget = UberSelectionWidget
113   
114    label = _(u"Add Collection Portlet")
115    description = _(u"This portlet display a listing of items from a Collection.")
116
117    def create(self, data):
118        return Assignment(**data)
119
120class EditForm(base.EditForm):
121    """Portlet edit form.
122   
123    This is registered with configure.zcml. The form_fields variable tells
124    zope.formlib which fields to display.
125    """
126
127    form_fields = form.Fields(IQCollectionPortlet)
128    form_fields['target_collection'].custom_widget = UberSelectionWidget
129
130    label = _(u"Edit Collection Portlet")
131    description = _(u"This portlet display a listing of items from a Collection.")
Note: See TracBrowser for help on using the repository browser.