# -*- coding: utf-8 -*- """ event.py """ from gluon.storage import Storage from gluon.tools import PluginManager from dataframes import (get_items, get_items_per_year, get_items_small, get_items_small_per_year, get_objectlike_items, get_objectlike_items_per_year, get_peoplelike_items, get_peoplelike_items_per_year, get_people_per_year) class EventException(BaseException): pass class Event(object): """Initialise the plugin event. Note: It has to be performed after the initialisation of the plugin dbui. """ @staticmethod def define_paths(lg="en"): """Define paths for the plugin_event. Args: lg (str): the language. Possible values are ``en`` or ``fr``. Note: The corresponding files will be loaded via the controller ``plugin_dbui/index`` """ dbui = PluginManager("dbui").dbui dbui.plugins_paths["event"] = { "css": "static/plugin_event/resources/css/", "debug": None, "lg": "static/plugin_event/locale/event-lang-%s.js" % lg, "libmin": "static/plugin_event/event-min.js"} @staticmethod def get_source(name): """Get the source identified by its name. Raised: EventException Args: name (str): name of the source to be used in the UI. Returns: reference: the function to generate the DataFrame. """ event = PluginManager("event").event if event is None: raise EventException("Plugin event is not configured.") sources = event.sources if sources is None: raise EventException("Plugin event sources are not configured.") if name not in sources: raise EventException("The source %s is not registered" % name) return sources[name].func @staticmethod def get_sources(): """Return the list of registered sources. Raises: EventException Returns: iterator: names of the registered sources. """ event = PluginManager("event").event if event is None: raise EventException("Plugin event is not configured.") sources = event.sources if sources is None: raise EventException("Sources are not configured.") return sources.iterkeys() @staticmethod def register_source(name, func): """Register sources which are used in the reporting section. Args: name (str): name of the source to be used in the UI. func (reference): the function generating the DataFrame. """ event = PluginManager("event").event if event.sources is None: event.sources = Storage() event.sources[name] = Storage(func=func) @staticmethod def register_sources(): """Register all sources defined in plugin_event. """ Event.register_source("items", get_items) Event.register_source("items / year", get_items_per_year) Event.register_source("items small", get_items_small) Event.register_source("items small / year", get_items_small_per_year) Event.register_source("object like", get_objectlike_items) Event.register_source("object like / year", get_objectlike_items_per_year) Event.register_source("people like", get_peoplelike_items) Event.register_source("people like / year", get_peoplelike_items_per_year) Event.register_source("people / year", get_people_per_year)