Back to index

plone3  3.1.7
reviewlist.py
Go to the documentation of this file.
00001 from zope.component import getMultiAdapter
00002 
00003 from Acquisition import aq_inner
00004 from Products.Five import BrowserView
00005 from Products.CMFCore.utils import getToolByName
00006 from plone.app.content.browser.tableview import Table, TableKSSView
00007 import urllib
00008 
00009 class FullReviewListView(BrowserView):
00010 
00011     def revlist(self):
00012         return self.context.my_worklist()
00013 
00014     def url(self):
00015         return self.context.absolute_url()+'/full_review_list'
00016 
00017     def review_table(self):
00018         table = ReviewListTable(self.context, self.request)
00019         return table.render()
00020 
00021 class ReviewListTable(object):
00022     """   
00023     The review list table renders the table and its actions.
00024     """                
00025 
00026     def __init__(self, context, request, **kwargs):
00027         self.context = context
00028         self.request = request
00029 
00030         url = self.context.absolute_url()
00031         view_url = url + '/full_review_list'
00032         self.table = Table(request, url, view_url, self.items,
00033                            buttons=self.buttons)
00034 
00035     def render(self):
00036         return self.table.render()
00037 
00038     @property
00039     def items(self):
00040         plone_utils = getToolByName(self.context, 'plone_utils')
00041         portal_url = getToolByName(self.context, 'portal_url')
00042         plone_view = getMultiAdapter((self.context, self.request), name=u'plone')
00043         portal_workflow = getToolByName(self.context, 'portal_workflow')
00044         portal_properties = getToolByName(self.context, 'portal_properties')
00045         site_properties = portal_properties.site_properties
00046         
00047         use_view_action = site_properties.getProperty('typesUseViewActionInListings', ())
00048         browser_default = self.context.browserDefault()
00049 
00050         results = list()
00051         for i, obj in enumerate(self.context.my_worklist()):
00052             if i % 2 == 0:
00053                 table_row_class = "even"
00054             else:
00055                 table_row_class = "odd"
00056             
00057             url = obj.absolute_url()
00058             path = '/'.join(obj.getPhysicalPath())
00059             icon = plone_view.getIcon(obj);
00060             
00061             type_class = 'contenttype-' + plone_utils.normalizeString(
00062                 obj.portal_type)
00063 
00064             review_state = portal_workflow.getInfoFor( obj, 'review_state', '')
00065 
00066             state_class = 'state-' + plone_utils.normalizeString(review_state)
00067             relative_url = portal_url.getRelativeContentURL(obj)
00068             obj_type = obj.portal_type
00069 
00070             modified = plone_view.toLocalizedTime(
00071                 obj.ModificationDate(), long_format=1)
00072             
00073             if obj_type in use_view_action:
00074                 view_url = url + '/view'
00075             elif obj.is_folderish:
00076                 view_url = url + "/folder_contents"              
00077             else:
00078                 view_url = url
00079 
00080             is_browser_default = len(browser_default[1]) == 1 and (
00081                 obj.id == browser_default[1][0])
00082                                  
00083             results.append(dict(
00084                 url = url,
00085                 id  = obj.getId(),
00086                 quoted_id = urllib.quote_plus(obj.getId()),
00087                 path = path,
00088                 title_or_id = obj.pretty_title_or_id(),
00089                 description = obj.Description(),
00090                 obj_type = obj_type,
00091                 size = obj.getObjSize(),
00092                 modified = modified,
00093                 icon = icon.html_tag(),
00094                 type_class = type_class,
00095                 wf_state = review_state,
00096                 state_title = portal_workflow.getTitleForStateOnType(review_state,
00097                                                            obj_type),
00098                 state_class = state_class,
00099                 is_browser_default = is_browser_default,
00100                 folderish = obj.is_folderish,
00101                 relative_url = relative_url,
00102                 view_url = view_url,
00103                 table_row_class = table_row_class,
00104                 is_expired = self.context.isExpired(obj),
00105             ))
00106         return results
00107 
00108     @property
00109     def show_sort_column(self):
00110         return False
00111 
00112     def buttons(self):
00113         buttons = []
00114         portal_actions = getToolByName(self.context, 'portal_actions')
00115         button_actions = portal_actions.listActionInfos(object=aq_inner(self.context), categories=('folder_buttons', ))
00116 
00117         # Do not show buttons if there is no data, unless there is data to be
00118         # pasted
00119         if False:#not len(self.batch):
00120             if self.context.cb_dataValid():
00121                 for button in button_actions:
00122                     if button['id'] == 'paste':
00123                         return [self.setbuttonclass(button)]
00124             else:
00125                 return []
00126 
00127         for button in button_actions:
00128             # Make proper classes for our buttons
00129             if button['id'] != 'paste' or self.context.cb_dataValid():
00130                 buttons.append(self.setbuttonclass(button))
00131         return buttons
00132 
00133     def setbuttonclass(self, button):
00134         if button['id'] == 'paste':
00135             button['cssclass'] = 'standalone'
00136         else:
00137             button['cssclass'] = 'context'
00138         return button
00139 
00140 class ReviewListKSSView(TableKSSView):
00141     table = ReviewListTable