incubator-bloodhound-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g..@apache.org
Subject svn commit: r1307985 - in /incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard: api.py layouts/bootstrap.py web_ui.py
Date Sun, 01 Apr 2012 01:31:20 GMT
Author: gjm
Date: Sun Apr  1 01:31:20 2012
New Revision: 1307985

URL: http://svn.apache.org/viewvc?rev=1307985&view=rev
Log:
Dashboard code import: BH_Dashboard: Refactorings applied before introducing layout container
widget

Modified:
    incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/api.py
    incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/layouts/bootstrap.py
    incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/web_ui.py

Modified: incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/api.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/api.py?rev=1307985&r1=1307984&r2=1307985&view=diff
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/api.py (original)
+++ incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/api.py Sun Apr  1 01:31:20
2012
@@ -26,6 +26,7 @@ The core of the dashboard architecture.
 __metaclass__ = type
 
 from datetime import date, time, datetime, timedelta
+from sys import version_info
 
 from trac.core import Component, ExtensionPoint, implements, \
         Interface, TracError
@@ -93,6 +94,7 @@ class DashboardSystem(Component):
     implements(IPermissionRequestor)
 
     widget_providers = ExtensionPoint(IWidgetProvider)
+    layout_providers = ExtensionPoint(ILayoutProvider)
 
     # IPermissionRequestor methods
     def get_permission_actions(self):
@@ -124,8 +126,29 @@ class DashboardSystem(Component):
                     return None
         return (get_and_check(param) for param in params)
 
+    def _resolve(self, objnm, epnm, accessor, errmsg='Invalid object name %s'):
+        """Determine the provider implementing a given widget / layout / ...
+
+        :param objnm:     name used to lookup provider
+        :param epnm:      attribute name used for entry point
+        :param accessor:  function used to determine names bound to provider
+        """
+        for p in getattr(self, epnm):
+            if objnm in accessor(self, p):
+                return p
+        else:
+            raise LookupError(errmsg % (objnm,))
+
+    def resolve_layout(self, nm):
+        return self._resolve(nm, 'layout_providers', 
+                lambda _, lp: lp.get_layouts() , "No provider for layout %s")
+
+    def resolve_widget(self, nm):
+        return self._resolve(nm, 'widget_providers', 
+                lambda _, wp: wp.get_widgets() , "No provider for widget %s")
+
 #--------------------------------------
-# Exfeption classes
+# Exception classes
 #--------------------------------------
 
 # Maybe it is better to move these to a separate file 
@@ -230,3 +253,24 @@ class EnumField:
                 title=_('Enum conversion error'))
         return value
 
+class JsonField:
+    """Deserialize JSON string
+    """
+    def __init__(self):
+        """Initialize JSON field converter
+        """
+        # TODO: Add further options
+
+    def __call__(self, value):
+        """Perform the actual conversion
+        """
+        try:
+            if version_info < (2, 6):
+                from simplejson import loads
+            else:
+                from json import loads
+        except ImportError :
+            raise TracError('Unable to load library to parse JSON string')
+        else:
+            return loads(value)
+

Modified: incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/layouts/bootstrap.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/layouts/bootstrap.py?rev=1307985&r1=1307984&r2=1307985&view=diff
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/layouts/bootstrap.py (original)
+++ incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/layouts/bootstrap.py Sun Apr
 1 01:31:20 2012
@@ -30,8 +30,7 @@ from trac.web.chrome import add_styleshe
 from bhdashboard.api import ILayoutProvider
 
 class BootstrapLayout(Component):
-    """Display a tag cloud representing frequency of values assigned to 
-    ticket fields.
+    """Implement some basic bootstrap layouts
     """
     implements(ILayoutProvider)
 
@@ -39,7 +38,7 @@ class BootstrapLayout(Component):
     def get_layouts(self):
         """Supported layouts.
         """
-        yield 'bootstrap'
+        yield 'bootstrap_grid'
 
     def get_layout_description(self, name):
         """Return plain text description of the layout with specified name.

Modified: incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/web_ui.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/web_ui.py?rev=1307985&r1=1307984&r2=1307985&view=diff
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/web_ui.py (original)
+++ incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/web_ui.py Sun Apr  1 01:31:20
2012
@@ -120,7 +120,6 @@ class DashboardModule(Component):
         from bhdashboard.widgets.ticket import TicketFieldCloudWidget
         from bhdashboard.widgets.timeline import TimelineWidget
 
-        ctx = Context.from_request(req)
         dashboard_query = 'status=accepted&status=assigned&status=new' \
                 '&status=reopened&group=time&col=id&col=summary&col=owner'
\
                 '&col=status&col=priority&order=priority&groupdesc=1&desc=1'
@@ -143,7 +142,7 @@ class DashboardModule(Component):
                     ],
                 'widgets' : [
                         {
-                            'args' : ['TicketQuery', ctx, 
+                            'args' : ['TicketQuery', None, 
                                     {'args' : {'max' : 10,
                                             'query' : dashboard_query,
                                             'title' : 'Dashboard'}
@@ -151,10 +150,10 @@ class DashboardModule(Component):
                             'altlinks' : False
                         },
                         {
-                            'args' : ['Timeline', ctx, {'args' : {}}]
+                            'args' : ['Timeline', None, {'args' : {}}]
                         },
                         {
-                            'args' : ['TicketFieldCloud', ctx, 
+                            'args' : ['TicketFieldCloud', None, 
                                     {'args' : {'field' : 'component',
                                             'verbose' : True}
                                     }]
@@ -162,7 +161,8 @@ class DashboardModule(Component):
                     ]
             }
 
-        template = layout.expand_layout('bootstrap', ctx, {
+        ctx = Context.from_request(req)
+        template = layout.expand_layout('bootstrap_grid', ctx, {
                 'schema' : schema
             })['template']
         return template, schema
@@ -177,12 +177,14 @@ class DashboardModule(Component):
         widgets_spec = schema.pop('widgets', [])
         widgets_index = dict([k, list(v)] for k,v in \
                 groupby(widgets_spec, lambda w : w['args'][0]))
+        ctx = Context.from_request(req)
         for wp in DashboardSystem(self.env).widget_providers:
             for wnm in wp.get_widgets():
                 substitutions = widgets_index.pop(wnm, [])
                 i = -1
                 for i, w in enumerate(substitutions):
                     w['c'] = wp
+                    w['args'][1] = ctx
                 self.log.debug('Widget %s (%s substitutions)', wnm, i + 1)
         if len(widgets_index) > 0:
             raise LookupError('Unknown provider for widgets %s', 



Mime
View raw message