Commit ccb13c85 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update controllers and modules to protect undefined year range

parent b3da34a3
......@@ -36,7 +36,7 @@ def citations():
histogram)
from plugin_dbui import Selector
from reporting_tools import repr_team_project
from reporting_tools import protect_years
mplstyle()
......@@ -58,6 +58,8 @@ def citations():
virtdb.graph_citation_selector,
exclude_fields=("graphs", "year_start", "year_end"))
protect_years(selector)
year_start = selector.year_start
year_end = selector.year_end
......@@ -218,11 +220,18 @@ def publications_versus_time():
either as a line chart or as a stacked histograms.
"""
from reporting_tools import protect_years
# user criteria and graph configuration
selector = request.vars
graph = db.graphs[selector.Graph_selectorId_graphs]
axis = graph.stack_axis
# protection
protect_years(selector,
kstart="Graph_selectorYear_start",
kend="Graph_selectorYear_end")
# figure and style
mplstyle()
fig = Figure()
......
......@@ -5,9 +5,9 @@ from gluon.dal import Field
from plugin_dbui import Selector
from reporting_tools import (get_converter,
get_sections,
protect_years,
repr_team_project)
MSG_NO_LIST = T("Please select a list....")
......@@ -26,6 +26,8 @@ def index():
if not selector.id_lists:
return MSG_NO_LIST
protect_years(selector)
# retrieve the list data
mylist = db.lists[selector.id_lists]
......
......@@ -3,10 +3,9 @@
"""
import json
from plugin_dbui import inline_alert, JSONEncoder, Selector
from pydal.helpers.methods import smart_query
from reporting_tools import get_converter, repr_team_project
from reporting_tools import get_converter, protect_years, repr_team_project
MSG_NO_METRIC = "Please select a metric...."
......@@ -27,6 +26,8 @@ def index():
if not selector.id_metrics:
return inline_alert(T("Error"), T(MSG_NO_METRIC))
protect_years(selector)
# retrieve metric data
metric = db.metrics[selector.id_metrics]
......@@ -107,7 +108,7 @@ def index():
if row[fields["vertical"]] != key:
key = row[fields["vertical"]]
cfg["data"].append([key])
cfg["data"][-1].extend([""]*(len(labels["horizontal"]) + 1))
cfg["data"][-1].extend([""] * (len(labels["horizontal"]) + 1))
cfg["data"][-1][-1] = 0
i = labels["horizontal"].index(row[fields["horizontal"]]) + 1
......@@ -134,23 +135,23 @@ def index():
def top_citations():
"""controller to display publications with highest citations score.
"""
citations = db.citations
projects = db.projects
publications = db.publications
publishers = db.publishers
teams = db.teams
# get the user constraint.
# the selector fields year_start, year_end are excluded
# from the selector query.
tpl = ("id_authors_roles",
"id_teams",
"id_projects",
"top",
tpl = ("id_authors_roles",
"id_teams",
"id_projects",
"top",
"year_start", "year_end")
selector = Selector(virtdb.top_citations_selector, exclude_fields=tpl)
# query directive for the citations table
......@@ -163,14 +164,14 @@ def top_citations():
if len(id_role) > 0:
query &= publications.id_authors_roles == id_role
id_team = selector.id_teams
id_team = selector.id_teams
if len(id_team) > 0:
query &= publications.id_teams == id_team
id_project = selector.id_projects
id_project = selector.id_projects
if len(id_project) > 0:
query &= publications.id_projects == id_project
if selector.year_start and not selector.year_end:
query &= (publications.year == selector.year_start)
......@@ -178,10 +179,10 @@ def top_citations():
q_start = publications.year >= selector.year_start
q_end = publications.year <= selector.year_end
query &= ((q_start) & (q_end))
# configure the Ext.data.ArrayStore for the grid
max_count = citations.count.max()
irows = db(query).iterselect(
teams.domain,
teams.team,
......@@ -193,9 +194,9 @@ def top_citations():
publications.pages,
max_count,
groupby=citations.id_publications,
orderby=~max_count,
orderby=~max_count,
limitby=(0, selector.top))
data = [
[
el.teams.domain,
......@@ -207,7 +208,7 @@ def top_citations():
el._extra["MAX(`citations`.`count`)"],
el.publications.year
] for el in irows]
fields = [
{"name": "domain", "type": "string"},
{"name": "team", "type": "string"},
......@@ -215,7 +216,7 @@ def top_citations():
{"name": "reference", "type": "string"},
{"name": "citations", "type": "int"},
{"name": "year", "type": "int"}]
cfg = dict(fields=fields, data=data)
# configure the grid
......@@ -224,22 +225,22 @@ def top_citations():
{"text": T("domain"), "dataIndex": "domain", "flex": 1},
{"text": T("team"), "dataIndex": "team", "flex": 0.9},
{
"text": T("project"),
"dataIndex": "project",
"flex": 0.5,
"text": T("project"),
"dataIndex": "project",
"flex": 0.5,
"hidden": True
},
},
{"text": T("reference"), "dataIndex": "reference", "flex": 2.5},
{
"text": T("citations"),
"dataIndex": "citations",
"flex": 0.5,
"text": T("citations"),
"dataIndex": "citations",
"flex": 0.5,
"align": "end"
},
{"text": T("year"), "dataIndex": "year", "flex": 0.5}
]
return dict(cfg_store=json.dumps(cfg, cls=JSONEncoder),
return dict(cfg_store=json.dumps(cfg, cls=JSONEncoder),
columns=json.dumps(columns, cls=JSONEncoder),
team_project=repr_team_project(db, selector),
selector=selector)
......@@ -14,7 +14,6 @@ from harvest_tools import DRY_RUN
from .harvester import CONTROLLERS, STORES
from pydal import Field
FORMATS = ["bib", "html", "odt", "pdf", "tex"]
MODE_CHANGE_STATUS = "change status"
MODE_LOAD_IN_DB = "load in the database"
......@@ -257,8 +256,8 @@ class Selector(object):
table = virtdb.define_table(
"graph_selector",
Field("year_start", "integer", default=year),
Field("year_end", "integer"),
Field("year_start", "integer"),
Field("year_end", "integer", default=year),
Field("id_teams", "reference teams", label="Team"),
Field("id_projects", "reference projects", label="Project"),
Field("id_categories", "reference categories", label="Category"),
......
......@@ -3,11 +3,11 @@
"""
import re
from .list_postprocessing import (clean,
highlight_my_authors,
highlight_my_speaker,
remove_undef)
from gluon import current
from gluon.storage import Storage
from pydal.helpers.methods import smart_query
......@@ -163,6 +163,28 @@ def get_sections(db, selector, row):
return sections
def protect_years(selector, kstart="year_start", kend="year_end"):
"""define value for year_start and year_end when not defined.
Args:
plugin_dbui.Selector
"""
is_not_start = selector[kstart] in ("", None, 0)
is_not_end = selector[kend] in ("", None, 0)
min_year = current.app.dashboard_start_year
min_year = (min_year if isinstance(min_year, int) else "")
max_year = current.request.now.year
if is_not_start and is_not_end:
selector[kstart] = min_year
selector[kend] = max_year
elif is_not_start:
selector[kstart] = min_year
def ref_url(name="List"):
"""Get the URL string uses to build the current request.
......
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