# -*- coding: utf-8 -*- """plugin_event controllers """ import traceback import urllib from plugin_event import (Graph, List, Metric2D, ReportException, Source) def grid(): """The list is rendered such as an ``Ext.grid.Panel`` widget. Its context menu allows to export the content of the table as a CSV, LaTeX or PDF format. The controller extracts the configuration of the report from the database. It builds the DataFrame, extracts the configuration for the ``Ext.data.Store`` as well as the ``Ext.grid.Panel``. The former contains the data displayed in the grid. """ try: report = List(request.vars.id_list) store = report.get_store_configuration() grid = report.get_grid_configuration() title = report.get_title() except (IndexError, ReportException, TypeError, ValueError): return CODE(traceback.format_exc()).xml() response.view = "plugin_event/grid.html" return dict(cfg_store=store, grid=grid, title=title) def metric2d(): """The metric 2D is a 2D table rendered by an ``Ext.grid.Panel`` widget and a graph rendered as an image. The context menu associated to the grid allows to export the content of the table as a CSV, LaTeX or PDF format. The context menu associated to the image allow to export in PNG or PDF format. The controller extracts the configuration of the report from the database. It builds the DataFrame, extracts the the configuration for the ``Ext.data.Store`` as well as the ``Ext.grid.Panel`` and generated the graph. """ extension = request.extension try: report = Metric2D(request.vars.id_metric2d) graph = Graph(report) title = report.get_title() if extension == "html": store = report.get_store_configuration() grid = report.get_grid_configuration() if graph.ax is not None: img = graph.to_svg() img = urllib.quote(img) response.view = "plugin_event/grid_and_graph.html" return dict(cfg_store=store, grid=grid, img=img, title=title) else: response.view = "plugin_event/grid.html" return dict(cfg_store=store, grid=grid, title=title) elif extension == "pdf": data = graph.to_pdf() response.view = "plugin_event/graph.pdf" return dict(data=data, title=title) elif extension == "png": data = graph.to_png() response.view = "plugin_event/graph.png" return dict(data=data, title=title) except (IndexError, ReportException, TypeError, ValueError): return CODE(traceback.format_exc()).xml() def source(): """Display the content of a source via an ``Ext.grid.Panel``. Values send by the selector are used to filter the content of the source. """ try: report = Source(request.vars.source) store = report.get_store_configuration() grid = report.get_grid_configuration() title = report.get_title() except (IndexError, ReportException, TypeError, ValueError): return CODE(traceback.format_exc()).xml() response.view = "plugin_event/grid.html" return dict(cfg_store=store, grid=grid, title=title)