def render_widget(self, name, context, options): """Count ocurrences of values assigned to given ticket field. """ dbsys = DashboardSystem(self.env) params = ('layout', 'schema', 'show_captions', 'title') layout, schema, show_captions, title = \ self.bind_params(name, options, *params) lp = dbsys.resolve_layout(layout) dbmod = DashboardModule(self.env) layout_data = lp.expand_layout(layout, context, { 'schema': schema, 'embed': True }) widgets = dbmod.expand_widget_data(context, schema) return layout_data['template'], \ { 'title' : title, 'data' : dict( context=context, layout=schema, widgets=widgets, title='', default={ 'height' : dbmod.default_widget_height or None } ), }, \ context
def render_widget(self, name, context, options): """Count ocurrences of values assigned to given ticket field. """ dbsys = DashboardSystem(self.env) params = ('layout', 'schema', 'show_captions', 'title') layout, schema, show_captions, title = \ self.bind_params(name, options, *params) lp = dbsys.resolve_layout(layout) dbmod = DashboardModule(self.env) layout_data = lp.expand_layout(layout, context, { 'schema' : schema, 'embed' : True }) widgets = dbmod.expand_widget_data(context, schema) return layout_data['template'], \ { 'title' : title, 'data' : dict( context=context, layout=schema, widgets=widgets, title='', default={ 'height' : dbmod.default_widget_height or None } ), }, \ context
def expand_layout_data(self, context, layout_name, schema, embed=False): """Determine the template needed to render a specific layout and the data needed to place the widgets at expected location. """ layout = DashboardSystem(self.env).resolve_layout(layout_name) template = layout.expand_layout(layout_name, context, { 'schema': schema, 'embed': embed })['template'] return template, schema
def expand_widget_data(self, context, schema): """Expand raw widget data and format it for use in template """ # TODO: Implement dynamic dashboard specification widgets_spec = schema.get('widgets', {}) widgets_index = dict( [wnm, wp] for wp in DashboardSystem(self.env).widget_providers for wnm in wp.get_widgets()) self.log.debug("Bloodhound: Widget index %s" % (widgets_index, )) for w in widgets_spec.itervalues(): w['c'] = widgets_index.get(w['args'][0]) w['args'][1] = context self.log.debug("Bloodhound: Widget specs %s" % (widgets_spec, )) chrome = Chrome(self.env) render = chrome.render_template data_strm = ((k, w, self._render_widget(w['c'], *w['args'])) for k, w in widgets_spec.iteritems()) return dict([ k, { 'title': data['title'], 'content': render( wctx.req, template, data['data'], fragment=True), 'ctxtnav': w.get('ctxtnav', True) and data.get('ctxtnav') or None, 'altlinks': w.get('altlinks', True) and data.get('altlinks') or None, 'visible': w['c'] is not None or not w.get('hide_disabled', False) } ] for k, w, (template, data, wctx) in data_strm)
def setUp(self): r"""Include the appropriate widget provider in global namespace before running all test cases in the suite. In this case three objects are added to the global namespace : - `widget` the component implementing the widget under test - `ctx` context used to render the widget for anonymous user - `auth_ctx` context used to render the widget for authenticated user """ # Fail here if BloodhoundDashboardPlugin is not available. Thus # this fact will be reported as a failure and subsequent test # cases will be run anyway. from bhdashboard.api import DashboardSystem self.dbsys = DashboardSystem(self.env) # Add request objects DocTestTracLoader.doctestSuiteClass.setUp(self) widgetns = self.ns_from_name() if widgetns is None: # TODO: If doctests belong to a widget provider class then # instantiate it. In the mean time ... self.partial_setup() else: try: self.setup_widget(widgetns) except InvalidIdentifier: self.partial_setup()
def bind_params(self, name, options, *params): return DashboardSystem(self.env).bind_params( options, self.get_widget_params(name), *params)