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

Add the function do_title building the report title.

parent 5699b533
......@@ -10,7 +10,7 @@ import re
from plugin_dbui import INLINE_ALERT
from report_objects import List, Metric1D, Metric2D
from report_objects import do_title, List, Metric1D, Metric2D
from selector import MySelector
......@@ -71,9 +71,12 @@ def list():
store = report.to_store()
grid = report.to_grid()
# title
title = do_title(config, selector)
# delegate the grid rendering to the view
response.view = 'report/grid.html'
return dict(cfg_store=json.dumps(store), view=grid)
return dict(cfg_store=json.dumps(store), grid=grid, title=title)
def metric_1d():
......@@ -96,10 +99,13 @@ def metric_1d():
report = Metric1D(config, selector)
store = report.to_store()
grid = report.to_grid()
# title
title = do_title(config, selector)
# delegate to standard view
response.view = 'report/grid.html'
return dict(cfg_store=json.dumps(store), view=grid)
return dict(cfg_store=json.dumps(store), grid=grid, title=title)
def metric_2d():
......@@ -124,7 +130,10 @@ def metric_2d():
report = Metric2D(config, selector)
store = report.to_store()
grid = report.to_grid()
# title
title = do_title(config, selector)
# delegate the rendering to the standard view
response.view = 'report/grid.html'
return dict(cfg_store=json.dumps(store), view=grid)
return dict(cfg_store=json.dumps(store), grid=grid, title=title)
......@@ -130,7 +130,7 @@
'Format': 'Format',
'Formats': 'Formats',
'Forms': 'Formulaire',
'from %s to %s': 'du %s au %s',
'from %s to %s': 'de %s à %s',
'Fte': 'Fte',
'FTE': 'FTE',
'Fte Sum': 'Fte Sum',
......
......@@ -13,6 +13,42 @@ from gluon.storage import Storage
from plugin_dbui import Store
def do_title(config, selector):
"""Build the report title.
"""
db = current.globalenv['db']
T = current.T
# from the configuration
title = (config.title if config.title else config.name)
# add meta data
metadata = []
if selector.id_teams:
metadata.append(db.teams[selector.id_teams].team)
if selector.id_projects:
metadata.append(db.projects[selector.id_projects].project)
if selector.category:
metadata.append(selector.category)
if selector.id_people_categories:
code = db.people_categories[selector.id_people_categories].code
metadata.append(code)
# add period
if selector.year_start and not selector.year_end:
metadata.append(str(selector.year_start))
elif selector.year_start and selector.year_end:
years = (str(selector.year_start), str(selector.year_end))
metadata.append(T("from %s to %s") % years)
return "%s: %s" % (title, ' / '.join(metadata))
def get_value(row, tablename, fieldname, keyname='', **kwargs):
"""Return the row value of the database field
identify by the tablename, fieldname and keyname
......@@ -314,7 +350,7 @@ class List(BaseReport):
"""
config = self.config
grid = Storage(columns=[], features=[], title=config.title)
grid = Storage(columns=[], features=[])
# column from the configuration
for cfg in self._columns:
......@@ -525,7 +561,7 @@ class Metric1D(BaseReport):
config = self.config
index_groupby = self._index_groupby
grid = Storage(columns=[], features=[], title=config.title)
grid = Storage(columns=[], features=[])
# first column is for the group field
grid.columns = [{'text': current.T(index_groupby.title()),
......@@ -738,7 +774,7 @@ class Metric2D(BaseReport):
map_y = split_dbfield(address_y)
text_y = (map_y[2] if map_y[2] else map_y[1])
grid = Storage(columns=[], features=[], title=config.title)
grid = Storage(columns=[], features=[])
grid.columns.append({'text': current.T(text_y.title()),
'dataIndex': address_y.replace('.', ''),
......
......@@ -3,7 +3,8 @@
#
# The python controller return the variables:
# - cfg_store (string)
# - view (Storage)
# - grid (Storage)
# - title (string)
#
#--------------------------------------------------------------------------
# Prepare the data
......@@ -18,16 +19,16 @@
#
divgrid = "grid-%s" % id(cfg_store)
response.write(H2(view.title, _class="dbui-h2 dbui-small-cap"))
response.write(H2(title, _class="dbui-h2 dbui-small-cap"))
response.write(DIV(_id=divgrid))
#
# Export python variables to the javascript
#
jsvars = ["cfgStore = %s" % cfg_store,
"columns = %s" % view.columns,
"columns = %s" % grid.columns,
"divgrid = '%s'" % divgrid,
"features = %s" % view.features]
"features = %s" % grid.features]
jsvars = " var %s;" % ',\n'.join(jsvars)
response.write(SCRIPT(jsvars), escape=False)
......
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