Back to index

plone3  3.1.7
overview.py
Go to the documentation of this file.
00001 from plone.memoize.instance import memoize
00002 from zope.i18n import translate
00003 
00004 from Acquisition import aq_base
00005 from Acquisition import aq_inner
00006 
00007 from Products.CMFCore.utils import getToolByName
00008 from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
00009 
00010 from plone.app.controlpanel.form import ControlPanelView
00011 
00012 
00013 def three_column_list(input_list):
00014     list_len = len(input_list)
00015 
00016     # Calculate the length of the sublists
00017     sublist_len = (list_len % 3 == 0 and list_len / 3 or list_len / 3 + 1)
00018 
00019     # Calculate the list end point given the list number
00020     def _list_end(num):
00021         return (num == 2 and list_len or (num + 1) * sublist_len)
00022 
00023     # Generate only filled columns
00024     final = []
00025     for i in range(3):
00026         column = input_list[i*sublist_len:_list_end(i)]
00027         if len(column) > 0:
00028             final.append(column)
00029     return final
00030 
00031 
00032 class OverviewControlPanel(ControlPanelView):
00033 
00034     template = ViewPageTemplateFile('overview.pt')
00035 
00036     base_category = 'controlpanel'
00037     ignored_categories = ('controlpanel_user')
00038 
00039     def __call__(self):
00040         self.request.set('disable_border', 1)
00041         return self.template()
00042 
00043     @memoize
00044     def action(self):
00045         return getToolByName(aq_inner(self.context), 'portal_actions')
00046 
00047     @memoize
00048     def migration(self):
00049         return getToolByName(aq_inner(self.context), 'portal_migration')
00050 
00051     @memoize
00052     def core_versions(self):
00053         return self.migration().coreVersions()
00054 
00055     def pil(self):
00056         return 'PIL' in self.core_versions()
00057 
00058     def version_overview(self):
00059         versions = [
00060             'Plone ' + self.migration().getInstanceVersion(),
00061         ]
00062         core_versions = self.core_versions()
00063         for v in ('CMF', 'Zope', 'Python'):
00064             versions.append(v + ' ' + core_versions.get(v))
00065         pil = core_versions.get('PIL', None)
00066         if pil is not None:
00067             versions.append('PIL ' + pil)
00068         return versions
00069 
00070     @memoize
00071     def is_dev_mode(self):
00072         qi = getToolByName(aq_inner(self.context), 'portal_quickinstaller')
00073         return qi.isDevelopmentMode()
00074 
00075     def mailhost_warning(self):
00076         mailhost = getToolByName(aq_inner(self.context), 'MailHost', None)
00077         if mailhost is None:
00078             return True
00079         mailhost = getattr(aq_base(mailhost), 'smtp_host', None)
00080         email = getattr(aq_inner(self.context), 'email_from_address', None)
00081         if mailhost and email:
00082             return False
00083         return True
00084 
00085     def categories(self):
00086         root = self.action().get(self.base_category, None)
00087         if root is None:
00088             return ()
00089         category_ids = [i for i in root.objectIds()
00090                           if i not in self.ignored_categories]
00091         def _title(id):
00092             title = root[c].getProperty('title')
00093             domain = root[c].getProperty('i18n_domain', 'plone')
00094             return translate(title, domain=domain, context=self.request)
00095         return [dict(id=c, title=_title(c)) for c in category_ids]
00096 
00097     def sublists(self, category):
00098         categories = self.base_category + '/' + category
00099         actions = self.action().listActionInfos(categories=categories)
00100         def _title(v):
00101             return translate(v.get('title'),
00102                              domain='plone',
00103                              context=self.request)
00104         actions.sort(key=_title)
00105         return three_column_list(actions)