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

Remove trailing spaces.

parent ec0c73a2
""" mytool controllers
""" mytool controllers
A collection of tools specific to the applications
......@@ -17,17 +17,17 @@ MSG_CVT = T(" - Conversion error: %s.")
def userModelConsistency():
""" A user data block is associated to each event.
It is configurable by the user and defined in the events table.
The definition of the user data block (model) and the content
of the history.data field have to be kept in synchronization.
This job is done by this controller.
"""
# decode the request
changes = json.loads(request.vars.changes)
event = request.vars.fieldEvent
model = json.loads(request.vars.fieldData)
# build a map of the modified keys.
# each operation is a list containing (action, old key, new key).
# the action is equal to: add, destroy, update
......@@ -37,15 +37,15 @@ def userModelConsistency():
#
update_keys = {}
for action, oldkey, newkey in changes:
if action != 'update':
continue
# simplify the case where key1 > key2 > key3 to key1 > key3
# remove the case where key1 > key2 > ... > key1
if update_keys:
ok = False
for k, v in update_keys.iteritems():
if oldkey == v:
update_keys[k] = newkey
......@@ -53,70 +53,70 @@ def userModelConsistency():
if k == newkey:
del update_keys[k]
break
if ok:
continue
# basic case
update_keys[oldkey] = newkey
# get the event id
id_event = get_id(db.events, event=event)
if id_event == None:
return
# set-up the default values dealing with data conversion
for key in model:
value = model[key]['value']
type = model[key]['type']
type = model[key]['type']
if value:
try:
if type == "boolean":
value = value.lower() in ('true', 'vrai', 'y', 'yes', '1')
elif type == "date":
value = datetime.strptime(value, "%Y-%m-%d")
value = value.isoformat()
elif type == "float":
value = float(value)
elif type == "integer":
value = int(value)
if type == "string" and value[0] == "[" and value[-1] == "]":
# reference to a set, pick the first value as default
li = json.loads(value)
value = (li[0] if li else None)
elif type == "reference":
value = None
except ValueError as e:
return MSG_CVT % e
model[key]['value'] = value
# scan and modify the history table
# the delete of old key is implicit since they are not copied
query = db.history.id_events == id_event
rows = db(query).select()
for row in rows:
data = {}
rd = (row.data if isinstance(row.data, dict) else dict())
# copy existing key or add new key
for key in model:
data[key] = (rd[key] if key in rd else model[key]['value'])
# modify key name
for oldkey, newkey in update_keys.iteritems():
if oldkey in rd:
data[newkey] = rd[oldkey]
db(db.history.id == row.id).update(data=data)
return MSG % len(rows)
\ No newline at end of file
""" Report controllers
""" Report controllers
"""
import urllib
......@@ -7,11 +7,11 @@ import re
from plugin_dbui import INLINE_ALERT
from report_objects import (do_title,
Graph,
List,
Metric1D,
Metric2D,
from report_objects import (do_title,
Graph,
List,
Metric1D,
Metric2D,
ReportException)
from selector import MySelector, SelectorActiveItemsException
......@@ -19,9 +19,9 @@ from selector import MySelector, SelectorActiveItemsException
def graph_extjs():
"""Plot 2D metric as a C{Ext.char.series.Area} using the ExtJS library.
This action is kept as a test bench of ExtJS chart classes.
@deprecated: use the more generic graph_mpl
"""
ui_table = virtdb.selector
selector = MySelector(ui_table, exclude_fields=('metric',))
......@@ -33,23 +33,23 @@ def graph_extjs():
config.metric_field_z = 'people.id'
config.aggregation_z = 'size'
# generate the metric according to user specification
report = Metric2D(config, selector)
# extract the configurations for the Ext.data.Store
store = report.to_store()
# Extra the stack keys (value for metric.field_vertical)
stack_keys = [el for el in report.df.columns]
# delegate the rendering of the graph to the view
return dict(cfg_store=json.dumps(store), stack_keys=stack_keys, view=config)
def graph_mpl():
"""Plot list or metric using the matplotlib library
"""
# selector and configuration
try:
......@@ -58,19 +58,19 @@ def graph_mpl():
except SelectorActiveItemsException as e:
return INLINE_ALERT % (T("Error..."), T(str(e)))
config = db.graphs[request.vars.id_graphs]
# build the graph
try:
graph = Graph(config, selector)
except (IndexError, TypeError, ValueError) as e:
return INLINE_ALERT % ("Error", e)
# build the report title
title = do_title(config, selector)
# delegate the rendering to the view
return dict(data=graph.to_svg(), title=title)
......@@ -78,51 +78,51 @@ def graph_mpl():
def grid():
"""Render the report through the C{App.grid.Panel}.
The report can be a list, a metrics 1d or 2d.
The controller extracts the configuration of the report form the database.
It builds the DataFrame, extracts the the configuration
for the C{Ext.data.Store} as well as the C{App.grid.Panel}.
It builds the DataFrame, extracts the the configuration
for the C{Ext.data.Store} as well as the C{App.grid.Panel}.
The former contains the data displayed in the grid.
The report identifier is defined in the viewport
and send using the baseParams techniques. Possible identifiers
are C{id_lists], C{id_metrics1d} and C{id_metrics2d}.
The identifier is used to instantiate the proper class.
"""
try:
ui_table = virtdb.selector
selector = MySelector(ui_table)
except SelectorActiveItemsException as e:
return INLINE_ALERT % (T("Error..."), T(str(e)))
# extract the report configuration and the build the report
try:
if "id_lists" in request.vars:
config = db.lists[request.vars.id_lists]
report = List(config, selector)
elif "id_metrics1d" in request.vars:
config = db.metrics1d[request.vars.id_metrics1d]
report = Metric1D(config, selector)
elif "id_metrics2d" in request.vars:
config = db.metrics2d[request.vars.id_metrics2d]
report = Metric2D(config, selector)
else:
return INLINE_ALERT % ("Error", "Report id is not defined.")
except (IndexError, ReportException, TypeError, ValueError) as e:
return INLINE_ALERT % ("JSON Error...", e)
# extract the configurations for the Ext.data.Store and App.grid.Panel.
store = report.to_store()
grid = report.to_grid()
# build the report title
title = do_title(config, selector)
# delegate the grid rendering to the view
return dict(cfg_store=json.dumps(store), grid=grid, title=title)
......@@ -2,7 +2,7 @@
""" authentication
user identification and role
"""
from gluon.tools import Auth
......@@ -21,7 +21,7 @@ auth.settings.registration_requires_verification = False
auth.settings.remember_me_form = False
auth.settings.reset_password_requires_verification = True
# go to the login page after change password, logout and registration
# go to the login page after change password, logout and registration
auth.settings.change_password_next = URL('user', args='login')
auth.settings.logout_next = URL('user', args='login')
auth.settings.register_next = URL('user', args='login')
......@@ -38,7 +38,7 @@ auth.settings.everybody_group_id = ID_USER
if not db(db.auth_user.id).count():
auth.settings.everybody_group_id = ID_ADMIN
auth.settings.registration_requires_approval = False
# tune authentication fields for the extJS interface
db.auth_user.registration_key.readable = True
db.auth_user.registration_key.writable = True
......@@ -53,6 +53,6 @@ IS_IN_DB(db, 'auth_user.last_name')
# JSON conversion of datetime failed in the action plugin_dbui.dbui_conf
# Convert the date in advance help
# TODO: implement a proper datetime conversion when running json.dumps()
db.auth_event.time_stamp.default = db.auth_event.time_stamp.default.isoformat()
db.auth_event.time_stamp.default = db.auth_event.time_stamp.default.isoformat()
db.auth_cas.created_on.default = db.auth_cas.created_on.default.isoformat()
# -*- coding: utf-8 -*-
""" fundings
""" fundings
"""
db.define_table("fundings",
......
......@@ -18,7 +18,7 @@ def_columns = \
"text": "?",
"xtype": "numbercolumn"
}]"""
if MIGRATE:
def_columns = None
......
# -*- coding: utf-8 -*-
""" alias_object_categories
alias tables for object_categories
"""
db.object_categories.with_alias('alias_object_categories')
# -*- coding: utf-8 -*-
""" alias_people_categories
alias tables for people_categories
"""
db.people_categories.with_alias('alias_people_categories')
# -*- coding: utf-8 -*-
""" events
""" events
"""
#-------------------------------------------------------------------------------
......
# -*- coding: utf-8 -*-
""" fundings
""" fundings
"""
#-------------------------------------------------------------------------------
......
# -*- coding: utf-8 -*-
""" graphs
""" graphs
"""
table = 'graphs'
......@@ -11,8 +11,8 @@ table = 'graphs'
fieldsModifier = dbui.FieldsModifier(table)
fieldsModifier.configure_field('definition', height=110)
fieldsModifier.configure_field('plot',
fieldsModifier.configure_field('plot',
height=240,
hideLabel=True)
......@@ -47,17 +47,17 @@ fieldsModifier.configure_field('report_name',
#
#-------------------------------------------------------------------------------
formModifier = dbui.FormModifier(table)
formModifier.merge_fields('name',
'title',
'report_type',
'report_name',
'definition',
title=T('General'))
formModifier.merge_fields('plot',
title=T('Configure'))
formModifier.set_mapper(dbui.map_tabpanel)
formModifier.configure(fieldDefaults={"labelWidth": 135},
......@@ -74,7 +74,7 @@ gridModifier.configure_column('report_type', width=20)
gridModifier.hide_columns('plot',
'report_name',
'title')
#-------------------------------------------------------------------------------
#
# STORE CONFIGURATiON
......
......@@ -10,7 +10,7 @@
fieldsModifier = dbui.FieldsModifier('history')
fieldsModifier.configure_field('id_events', itemId='keyid_events')
fieldsModifier.configure_field('data',
fieldsModifier.configure_field('data',
comboBoxItemId='keyid_events',
dictField='EventsData',
store='eventsStore',
......@@ -64,7 +64,7 @@ gridModifier.configure(plugins=['pGridPaging'])
gridModifier.hide_columns('data',
'id_object_categories',
'id_people_categories',
'id_people_categories',
'note',
'percentage')
......
# -*- coding: utf-8 -*-
""" lists
""" lists
"""
#-------------------------------------------------------------------------------
......@@ -9,7 +9,7 @@
#-------------------------------------------------------------------------------
fieldsModifier = dbui.FieldsModifier('lists')
fieldsModifier.configure_field('columns',
fieldsModifier.configure_field('columns',
editorHeight=240,
hideLabel=True,
language='json',
......@@ -17,43 +17,43 @@ fieldsModifier.configure_field('columns',
fieldsModifier.configure_field('definition', height=100)
fieldsModifier.configure_field('features',
fieldsModifier.configure_field('features',
editorHeight=240,
hideLabel=True,
language='json',
xtype='xaceeditorfield')
fieldsModifier.configure_field('sorters',
height=210,
hideHeader=True,
minimumRows=10)
#-------------------------------------------------------------------------------
#
# FORM CONFIGURATiON
#
#-------------------------------------------------------------------------------
formModifier = dbui.FormModifier('lists')
formModifier.merge_fields('name',
'title',
'definition',
'conditions',
title=T('General'))
formModifier.merge_fields('group_field',
'sorters',
title=T('Group'))
formModifier.merge_fields('columns',
title=T('Columns'))
formModifier.merge_fields('features',
title=T('Summary'))
formModifier.set_mapper(dbui.map_tabpanel)
formModifier.configure(width=450)
#-------------------------------------------------------------------------------
#
# GRID CONFIGURATiON
......@@ -67,7 +67,7 @@ gridModifier.hide_columns('title',
'features',
'group_field',
'sorters')
#-------------------------------------------------------------------------------
#
# STORE CONFIGURATiON
......
# -*- coding: utf-8 -*-
""" metrics1d
""" metrics1d
"""
table = "metrics1d"
......@@ -10,7 +10,7 @@ table = "metrics1d"
#-------------------------------------------------------------------------------
fieldsModifier = dbui.FieldsModifier(table)
fieldsModifier.configure_field('columns',
fieldsModifier.configure_field('columns',
editorHeight=240,
hideLabel=True,
language='json',
......@@ -24,22 +24,22 @@ fieldsModifier.configure_field('definition', height=100)
#
#-------------------------------------------------------------------------------
formModifier = dbui.FormModifier(table)
formModifier.merge_fields('name',
'title',
'definition',
'conditions',
title=T('General'))
formModifier.merge_fields('group_field',
title=T('Group'))
formModifier.merge_fields('columns',
title=T('Columns'))
formModifier.set_mapper(dbui.map_tabpanel)
formModifier.configure(width=450)
#-------------------------------------------------------------------------------
#
# GRID CONFIGURATiON
......@@ -51,7 +51,7 @@ gridModifier.hide_columns('title',
'columns',
'conditions',
'group_field')
#-------------------------------------------------------------------------------
#
# STORE CONFIGURATiON
......
# -*- coding: utf-8 -*-
""" metrics2d
""" metrics2d
"""
table = "metrics2d"
......@@ -12,26 +12,26 @@ fieldsModifier = dbui.FieldsModifier(table)
fieldsModifier.configure_field('conditions', height=110)
fieldsModifier.configure_field('definition', height=110)
#-------------------------------------------------------------------------------
#
# FORM CONFIGURATiON
#
#-------------------------------------------------------------------------------
formModifier = dbui.FormModifier(table)
formModifier.merge_fields('name',
'title',
'definition',
'conditions',
title=T('General'))
formModifier.merge_fields('group_field_x',
'group_field_y',
'metric_field_z',
'aggregation_z',
title=T('Aggregate'))
formModifier.set_mapper(dbui.map_tabpanel)
formModifier.configure(width=450)
......@@ -48,7 +48,7 @@ gridModifier.hide_columns('aggregation_z',
'group_field_y',
'metric_field_z',
'title')
#-------------------------------------------------------------------------------
#
# STORE CONFIGURATiON
......
# -*- coding: utf-8 -*-
""" teams
""" teams
"""
#-------------------------------------------------------------------------------
......
......@@ -5,44 +5,44 @@
"""
if not db(db.events.id).count():
db.events.insert(id=undef_id,
db.events.insert(id=undef_id,
event=undef,
definition=undef)
if not db(db.fundings.id).count():
db.fundings.insert(id=undef_id,
agency=undef,
db.fundings.insert(id=undef_id,
agency=undef,
definition=undef)
if not db(db.object_categories.id).count():
db.object_categories.insert(id=undef_id,
db.object_categories.insert(id=undef_id,