Back to index

plone3  3.1.7
review.py
Go to the documentation of this file.
00001 from zope import schema
00002 from zope.component import getMultiAdapter
00003 from zope.component import queryUtility
00004 from zope.formlib import form
00005 from zope.interface import implements
00006 
00007 from plone.app.portlets.portlets import base
00008 from plone.i18n.normalizer.interfaces import IIDNormalizer
00009 from plone.memoize.instance import memoize
00010 from plone.portlets.interfaces import IPortletDataProvider
00011 
00012 from Acquisition import aq_inner
00013 from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
00014 from Products.CMFCore.utils import getToolByName
00015 from Products.CMFPlone import PloneMessageFactory as _
00016 
00017 class IReviewPortlet(IPortletDataProvider):
00018     
00019     pass
00020 
00021 class Assignment(base.Assignment):
00022     implements(IReviewPortlet)
00023 
00024     @property
00025     def title(self):
00026         return _(u"Review list")
00027 
00028 class Renderer(base.Renderer):
00029 
00030     render = ViewPageTemplateFile('review.pt')
00031 
00032     @property
00033     def anonymous(self):
00034         context = aq_inner(self.context)
00035         portal_state = getMultiAdapter((context, self.request),
00036                                        name=u'plone_portal_state')
00037         return portal_state.anonymous()
00038 
00039     @property
00040     def available(self):
00041         return not self.anonymous and len(self._data())
00042 
00043     def review_items(self):
00044         return self._data()
00045 
00046     def full_review_link(self):
00047         context = aq_inner(self.context)
00048         portal_state = getMultiAdapter((context, self.request),
00049                                        name=u'plone_portal_state')
00050         return '%s/full_review_list' % portal_state.portal_url()
00051 
00052     @memoize
00053     def _data(self):
00054         if self.anonymous:
00055             return []
00056         context = aq_inner(self.context)
00057         workflow = getToolByName(context, 'portal_workflow')
00058 
00059         plone_view = getMultiAdapter((context, self.request), name=u'plone')
00060         getIcon = plone_view.getIcon
00061         toLocalizedTime = plone_view.toLocalizedTime
00062 
00063         idnormalizer = queryUtility(IIDNormalizer)
00064         norm = idnormalizer.normalize
00065         objects = workflow.getWorklistsResults()
00066         items = []
00067         for obj in objects:
00068             review_state = workflow.getInfoFor(obj, 'review_state')
00069             items.append(dict(
00070                 path = obj.absolute_url(),
00071                 title = obj.pretty_title_or_id(),
00072                 description = obj.Description(),
00073                 icon = getIcon(obj).html_tag(),
00074                 creator = obj.Creator(),
00075                 review_state = review_state,
00076                 review_state_class = 'state-%s ' % norm(review_state),
00077                 mod_date = toLocalizedTime(obj.ModificationDate()),
00078             ))
00079         return items
00080 
00081 
00082 class AddForm(base.NullAddForm):
00083     form_fields = form.Fields(IReviewPortlet)
00084     label = _(u"Add Review Portlet")
00085     description = _(u"This portlet displays a queue of documents awaiting review.")
00086 
00087     def create(self):
00088         return Assignment()