Commit 050c63d6 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update the class Event to add the methods get_source and get_sources.

parent 421aaf3c
......@@ -30,7 +30,8 @@ from dataframes import (active_period,
to_extjs_gridcolumns,
to_items_per_year)
from event import Event
from event import (Event,
EventException)
from matplotlib_tools import (bicolor,
create_pdf,
......
......@@ -7,6 +7,7 @@ import json
from dataframes import to_extjs_gridcolumns
from event import Event
from gluon import current
from gluon.tools import PluginManager
from plugin_dbui import CALLBACK_ERRORS, get_where_query
......@@ -90,7 +91,7 @@ def ON_CREATE_LISTS2(values):
year_start=year,
year_end=year)
func = PluginManager("event").event.sources[values["source"]].func
func = Event.get_source(values["source"]).func
df = func(**criteria)
......
......@@ -15,6 +15,10 @@ from dataframes import (get_items,
get_people_per_year)
class EventException(BaseException):
pass
class Event(object):
"""Initialise the plugin event.
......@@ -43,6 +47,56 @@ class Event(object):
"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 % 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.
......
......@@ -6,8 +6,8 @@ import numpy as np
from callbacks import ON_CREATE_LISTS2, ON_UPDATE_LISTS2
from event import Event
from gluon import current, IS_IN_SET
from gluon.tools import PluginManager
from pydal import Field
......@@ -256,8 +256,7 @@ class Report(object):
migrate="lists2.table")
sources = PluginManager("event").event.sources.keys()
sources.sort()
sources = sorted(Event.get_sources())
db.lists2.source.requires = IS_IN_SET(sources)
db.lists2._before_insert.append(ON_CREATE_LISTS2)
......@@ -416,9 +415,7 @@ class Report(object):
migrate="metrics2d2.table")
sources = PluginManager("event").event.sources.keys()
sources.sort()
sources = sorted(Event.get_sources())
table.source.requires = IS_IN_SET(sources)
funcs = AGGREGATE_FUNCS.keys()
......
......@@ -6,9 +6,9 @@ import json
import matplotlib as mpl
import pandas as pd
from event import Event
from gluon import current
from gluon.storage import Storage
from gluon.tools import PluginManager
from model_report import AGGREGATE_FUNCS
from matplotlib_tools import ticks_and_labels
from plugin_dbui import Selector, Store
......@@ -56,7 +56,6 @@ class BaseReport(object):
def __init__(self, table, id_report):
virtdb = current.globalenv["virtdb"]
plgevt = PluginManager("event").event
# ....................................................................
#
......@@ -77,7 +76,7 @@ class BaseReport(object):
criteria = selector.as_dict()
criteria["id_events"] = config.id_events
func = plgevt.sources[config.source].func
func = Event.get_source(config.source)
self.df = df = func(**criteria)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment