Permalink
Browse files

Added dashboard export support.

  • Loading branch information...
phgross committed Apr 17, 2012
1 parent 414d3b3 commit 35c005469cab7e1d5494cab0b41bb5bfa5211c80
Showing with 86 additions and 1 deletion.
  1. +2 −1 collective/jsonify/__init__.py
  2. +57 −0 collective/jsonify/dashboard.py
  3. +27 −0 collective/jsonify/methods.py
@@ -1,5 +1,6 @@
-
from collective.jsonify.methods import get_item
from collective.jsonify.methods import get_item_with_file
from collective.jsonify.methods import get_children
from collective.jsonify.methods import get_catalog_results
+from collective.jsonify.methods import get_dashboards
+from collective.jsonify.methods import get_users
@@ -0,0 +1,57 @@
+from Acquisition import aq_base
+from Products.CMFCore.utils import getToolByName
+from plone.portlets.constants import USER_CATEGORY
+from plone.portlets.interfaces import IPortletManager
+from zope.component import getUtility
+
+
+EXCLUDED_ATTRIBUTES = ['__name__', '__parent__']
+
+
+class DashboardWrapper(dict):
+ """Gets the all dasbhoard configurations in a format
+ that can be used by the blueprints in collective.jsonmigrator"""
+
+ def __init__(self, context, userid):
+ self.context = context
+ self._context = aq_base(context)
+ self.portal = getToolByName(
+ self.context, 'portal_url').getPortalObject()
+ self.pr = self.portal.portal_repository
+ self.portal_path = '/'.join(self.portal.getPhysicalPath())
+ self.portal_utils = getToolByName(self.context, 'plone_utils')
+ self.charset = self.portal.portal_properties.site_properties.default_charset
+ # newer seen it missing ... but users can change it
+ if not self.charset:
+ self.charset = 'utf-8'
+
+ self.userid = userid
+
+ for method in dir(self):
+ if method.startswith('get_'):
+ getattr(self, method)()
+
+ def get_peronal_dashboard(self):
+
+ dashboard_names = ['plone.dashboard1',
+ 'plone.dashboard2',
+ 'plone.dashboard3',
+ 'plone.dashboard4']
+
+ for name in dashboard_names:
+ dashboard = getUtility(IPortletManager, name=name)
+ AssignmentMapping = dashboard.get(
+ USER_CATEGORY, {}).get(self.userid, {})
+
+ self['userid'] = self.userid
+
+ self['_manager_%s' % name] = []
+
+ for assignment in AssignmentMapping.values():
+ data = {'module': assignment.__module__,
+ 'id': assignment.getId(), }
+ for attr in assignment.__dict__.keys():
+ if attr not in EXCLUDED_ATTRIBUTES:
+ data[attr] = getattr(assignment, attr, '')
+
+ self['_manager_%s' % name].append(data)
@@ -3,6 +3,7 @@
import pprint
import traceback
from collective.jsonify.wrapper import Wrapper, WrapperWithoutFile
+from collective.jsonify.dashboard import DashboardWrapper
from AccessControl.SecurityManagement import newSecurityManager
try:
@@ -79,3 +80,29 @@ def get_catalog_results(self):
item_paths = [item.getPath() for item
in self.unrestrictedSearchResults(**query) ]
return json.dumps(item_paths)
+
+def get_users(self):
+ """return all userids used for export the dashboards"""
+
+ pm = self.portal_membership
+ userids = [user.getId() for user in pm.listMembers()]
+ return json.dumps(userids)
+
+def get_dashboards(self):
+ """Return the dashboard from the given user
+ """
+
+ userid = self.REQUEST.get('userid', '')
+
+ try:
+ context_dict = DashboardWrapper(self, userid)
+ except Exception, e:
+ tb = pprint.pformat(traceback.format_tb(sys.exc_info()[2]))
+ return 'ERROR: exception wrapping object: %s\n%s' % (str(e), tb)
+
+ try:
+ JSON = json.dumps(context_dict)
+ except Exception, e:
+ return 'ERROR: wrapped object is not serializable: %s' % str(e)
+
+ return JSON

0 comments on commit 35c0054

Please sign in to comment.