Back to index

plone3  3.1.7
dashboard.py
Go to the documentation of this file.
00001 from zope.interface import implements
00002 from zope.component import adapts, queryUtility
00003 
00004 from zope.app.container.interfaces import INameChooser
00005 
00006 from Products.PluggableAuthService.interfaces.authservice import IPropertiedUser
00007 
00008 from plone.portlets.interfaces import IPortletManager
00009 from plone.portlets.constants import USER_CATEGORY
00010 
00011 from plone.app.portlets.interfaces import IDefaultDashboard
00012 from plone.app.portlets import portlets
00013 
00014 from plone.app.portlets.storage import UserPortletAssignmentMapping
00015 
00016 def new_user(principal, event):
00017     """Initialise the dashboard for a new user
00018     """
00019     defaults = IDefaultDashboard(principal, None)
00020     if defaults is None:
00021         return
00022     
00023     userid = principal.getId()
00024     portlets = defaults()
00025     
00026     for name in ('plone.dashboard1', 'plone.dashboard2', 'plone.dashboard3', 'plone.dashboard4'):
00027         assignments = portlets.get(name)
00028         if assignments:
00029             column = queryUtility(IPortletManager, name=name)
00030             if column is not None:
00031                 category = column.get(USER_CATEGORY, None)
00032                 if category is not None:
00033                     manager = category.get(userid, None)
00034                     if manager is None:
00035                         manager = category[userid] = UserPortletAssignmentMapping(manager=name,
00036                                                                                   category=USER_CATEGORY,
00037                                                                                   name=userid)
00038                     chooser = INameChooser(manager)
00039                     for assignment in assignments:
00040                         manager[chooser.chooseName(None, assignment)] = assignment
00041     
00042 class DefaultDashboard(object):
00043     """The default default dashboard.
00044     """
00045     
00046     implements(IDefaultDashboard)
00047     adapts(IPropertiedUser)
00048     
00049     def __init__(self, principal):
00050         self.principal = principal
00051     
00052     def __call__(self):
00053         return {
00054             'plone.dashboard1' : (portlets.news.Assignment(), portlets.events.Assignment(),),
00055             'plone.dashboard2' : (portlets.recent.Assignment(),),
00056             'plone.dashboard3' : (),
00057             'plone.dashboard4' : (portlets.review.Assignment(),),
00058         }