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

Use the new classes EvtModelXXX and EvtUiXXX in the models.

parent 9f0c6a44
......@@ -10,23 +10,23 @@ MIGRATE = False
MIGRATE_USER = False
# Roles
ID_ADMIN, ADMIN, DEF_ADMIN = 1, 'admin', 'administrators, team leader,...'
ID_USER, USER, DEF_USER = 2, 'user', 'project leader,...'
ID_ADMIN, ADMIN, DEF_ADMIN = 1, "admin", "administrators, team leader,..."
ID_USER, USER, DEF_USER = 2, "user", "project leader,..."
#-------------------------------------------------------------------------------
#.............................................................................
#
# MYSQL database
#
#-------------------------------------------------------------------------------
try:
mysql = DBURIS[request.application]
db = DAL(mysql, lazy_tables=False, migrate_enabled=MIGRATE, pool_size=10)
except:
raise HTTP(500, T("Can't access the MySQL database !!!"))
#-------------------------------------------------------------------------------
#.............................................................................
#
# virtual database
#
#-------------------------------------------------------------------------------
virtdb = DAL(None)
......@@ -5,37 +5,43 @@
import plugin_dbui as dbui
from datetime import datetime
from plugin_tev import INHIBIT_CASCADE_DELETE
from gluon.tools import PluginManager
#-------------------------------------------------------------------------------
from plugin_tev import (EvtModelCore,
EvtModelReport,
EvtModelSelector,
EvtUiCore,
EvtUiReport,
EvtUiSelector)
#.............................................................................
#
# PLUGIN DBUI
# Plugin dbui configuration
#
#-------------------------------------------------------------------------------
plugins = PluginManager()
plugins.dbui.app_css = 'static/my.css'
plugins.dbui.app_debug = 'static/src'
plugins.dbui.app_libmin = 'static/track_events-min.js'
plugins.dbui.app_lg = 'static/track_events/locale/myapp-lang-fr.js'
plugins.dbui.app_script = 'static/app.js'
plugins.dbui.app_css = "static/my.css"
plugins.dbui.app_debug = "static/src"
plugins.dbui.app_libmin = "static/track_events-min.js"
plugins.dbui.app_lg = "static/track_events/locale/myapp-lang-fr.js"
plugins.dbui.app_script = "static/app.js"
# plugins.dbui.app_script_dir = None
#-------------------------------------------------------------------------------
#.............................................................................
#
# LANGUAGE
# Language
#
#-------------------------------------------------------------------------------
T.set_current_languages('en', 'en-gb', 'en-us') # mother tongue
T.force('fr-fr') # user language
T.set_current_languages("en", "en-gb", "en-us") # mother tongue
T.force("fr-fr") # user language
T.lazy = False # immediate translation
#-------------------------------------------------------------------------------
#.............................................................................
#
# CONSTANTS
# Constants
#
#-------------------------------------------------------------------------------
FORMATS = ['csv', 'html', 'pdf', 'tex']
FORMATS = ["csv", "html", "pdf", "tex"]
now = datetime.now()
today = now.strftime("%Y-%m-%d")
......@@ -43,32 +49,40 @@ undef = T(dbui.UNDEF)
undef_id = dbui.UNDEF_ID
year = now.year
#-------------------------------------------------------------------------------
#.............................................................................
#
# COMMON CONFIGURATION FOR FORMS AND GRIDS
# Common configuration for forms and grids
#
#-------------------------------------------------------------------------------
tables = ['auth_group',
'auth_membership',
'auth_user',
'domains',
'events',
'fundings',
'graphs',
'history',
'lists',
'metrics1d',
'metrics2d',
'object_categories',
'objects',
'people',
'people_categories',
'projects',
'teams']
dbui.configure_forms(tables, plugins=['pFormToolTip'], width=350)
dbui.configure_grids(tables, plugins=['pGridRowEditorConfirmDelete',
'pGridRowEditorContextMenu',
'pGridRowEditorDblClick',
'pGridToolbar'])
tables = ["auth_group",
"auth_membership",
"auth_user"]
tables.extend(EvtModelCore.tables())
tables.extend(EvtModelReport.tables())
dbui.configure_forms(tables, plugins=["pFormToolTip"], width=350)
dbui.configure_grids(tables, plugins=["pGridRowEditorConfirmDelete",
"pGridRowEditorContextMenu",
"pGridRowEditorDblClick",
"pGridToolbar"])
#.............................................................................
#
# Create the database models
#
EvtModelCore.create(db, T)
EvtModelReport.create(db, T)
EvtModelSelector.create(virtdb, db, T)
#.............................................................................
#
# Tune the user interface
#
EvtUiCore.tune(db, T)
EvtUiReport.tune(db, T)
selector_panel = EvtUiSelector.selector(virtdb, db, T)
# -*- coding: utf-8 -*-
""" domains
"""
db.define_table("domains",
Field("domain", "string", length=255, notnull=True, unique=True),
migrate="domains.table")
db.domains._before_delete.append(INHIBIT_CASCADE_DELETE)
db.domains._before_delete.append(dbui.INHIBIT_DELETE_UNDEF)
db.domains._before_update.append(dbui.INHIBIT_UPDATE_UNDEF)
# -*- coding: utf-8 -*-
""" events
"""
db.define_table("events",
Field("event", "string", length=255, notnull=True, unique=True),
Field("definition", "text"),
Field("data", "json", label="Model"),
migrate="events.table")
db.events._before_delete.append(INHIBIT_CASCADE_DELETE)
db.events._before_delete.append(dbui.INHIBIT_DELETE_UNDEF)
db.events._before_update.append(dbui.INHIBIT_UPDATE_UNDEF)
# NOTE: we have to remove the json validator to work !!
db.events.data.requires = None
# -*- coding: utf-8 -*-
""" fundings
"""
db.define_table("fundings",
Field("agency", "string", length=255, notnull=True, unique=True),
Field("definition", "text"),
migrate="fundings.table")
db.fundings._before_delete.append(INHIBIT_CASCADE_DELETE)
db.fundings._before_delete.append(dbui.INHIBIT_DELETE_UNDEF)
db.fundings._before_update.append(dbui.INHIBIT_UPDATE_UNDEF)
# -*- coding: utf-8 -*-
""" graphs
"""
def_plot = \
"""{
"kind": "?",
"stacked": false
}"""
if MIGRATE:
def_plot = None
db.define_table("graphs",
Field("name", "string", length=255, notnull=True, unique=True),
Field("title", "string", length=255),
Field("report_type", "string", length=255, notnull=True),
Field("report_name", "string", length=255, notnull=True),
Field("plot", "text", notnull=True, default=def_plot),
Field("definition", "text"),
migrate="graphs.table")
# -*- coding: utf-8 -*-
""" lists
"""
tp_columns = \
T("Configure the column of the grid displayed in the view.")
tp_conditions = \
T("Database query to select history records:<br> "
"(db.events.event == 'People') & (db.history.data.like('%cdd%'))<br>")
tp_fields = \
T("Row are grouped according to the value of that field. "
"It can be any field of the history table including those of the foreign tables, "
"the individual property of the history.data dictionary, or 'year'.")
tp_features = \
T("Summary value can be computed for columns.")
tp_sorters = \
T("Entries are sorted according to the value of these fields. "
"It can be any field of the history table including those of the foreign tables, "
"the individual property of the history.data dictionary, or 'year'. "
"Descending order is obtained by using the '~field' construct.")
def_columns = \
"""[{
"xtype": "rownumberer"
}, {
"dbfield": "?.?",
"flex": 1,
"text": "?",
"xtype": "gridcolumn"
}]"""
def_features = \
"""[{
"ftype": "groupingsummary",
"groupHeaderTpl": "{name}",
"startCollapsed": false
}, {
"ftype": "summary"
}]"""
if MIGRATE:
def_columns = None
def_features = None
db.define_table("lists",
Field("name", "string", length=255, notnull=True, unique=True),
Field("title", "string", length=255),
Field("conditions", "text", comment=tp_conditions),
Field("group_field", "string", length=255, comment=tp_fields),
Field("sorters", "list:string", comment=tp_sorters),
Field("columns", "text", default=def_columns, comment=tp_columns, notnull=True),
Field("features", "text", default=def_features, comment=tp_features),
Field("definition", "text"),
migrate="lists.table")
\ No newline at end of file
# -*- coding: utf-8 -*-
""" metrics1d
"""
tp_fields = \
T("Metric are computed for each value of that field. "
"It can be any field of the history table including those of the foreign tables, "
"the individual property of the history.data dictionary or 'year'")
def_columns = \
"""[{
"aggregate": "?",
"align": "right",
"dbfield": "?.?",
"format": "0.0",
"text": "?",
"xtype": "numbercolumn"
}]"""
if MIGRATE:
def_columns = None
db.define_table("metrics1d",
Field("name", "string", length=255, notnull=True, unique=True),
Field("title", "string", length=255),
Field("conditions", "text", comment=tp_conditions),
Field("group_field", "string", length=255, comment=tp_fields, notnull=True),
Field("columns", "text", default=def_columns, comment=tp_columns, notnull=True),
Field("definition", "text"),
migrate="metrics1d.table")
# -*- coding: utf-8 -*-
""" metrics
"""
tp_agg = \
T("The aggregation function applies on the metric field. "
"It is computed on the subset of row having a given values for "
"the group_field x and y.")
db.define_table("metrics2d",
Field("name", "string", length=255, notnull=True, unique=True),
Field("title", "string", length=255),
Field("conditions", "text", comment=tp_conditions),
Field("group_field_x", "string", length=255, notnull=True, comment=tp_fields),
Field("group_field_y", "string", length=255, notnull=True, comment=tp_fields),
Field("metric_field_z", "string", length=255, notnull=True, comment=tp_fields),
Field("aggregation_z", "string", length=255, notnull=True, comment=tp_agg),
Field("definition", "text"),
migrate="metrics2d.table")
# -*- coding: utf-8 -*-
""" object_categories
"""
db.define_table("object_categories",
Field("code", "string", length=255, notnull=True, unique=True),
Field("category", "string", length=255, notnull=True),
Field("definition", "text"),
migrate="object_categories.table")
db.object_categories._before_delete.append(INHIBIT_CASCADE_DELETE)
db.object_categories._before_delete.append(dbui.INHIBIT_DELETE_UNDEF)
db.object_categories._before_update.append(dbui.INHIBIT_UPDATE_UNDEF)
# -*- coding: utf-8 -*-
""" objects
"""
db.define_table("objects",
Field("reference", "string", length=255, notnull=True, unique=True),
Field("serial_number", "string", length=255),
Field("batch_number", "string", length=255),
Field("note", "text"),
migrate="objects.table")
db.objects._before_delete.append(INHIBIT_CASCADE_DELETE)
db.objects._before_delete.append(dbui.INHIBIT_DELETE_UNDEF)
db.objects._before_update.append(dbui.INHIBIT_UPDATE_UNDEF)
# -*- coding: utf-8 -*-
""" people
"""
db.define_table("people",
Field("first_name", "string", length=255, notnull=True),
Field("last_name", "string", length=255, notnull=True),
Field("initials", "string", length=255, notnull=True),
Field("birth_date", "date"),
Field("note", "text"),
migrate="people.table")
db.people._before_delete.append(INHIBIT_CASCADE_DELETE)
db.people._before_delete.append(dbui.INHIBIT_DELETE_UNDEF)
db.people._before_update.append(dbui.INHIBIT_UPDATE_UNDEF)
# -*- coding: utf-8 -*-
""" people_categories
"""
db.define_table("people_categories",
Field("code", "string", length=255, notnull=True, unique=True, label=T("Quality")),
Field("category", "string", length=255, notnull=True),
Field("definition", "text"),
migrate="people_categories.table")
db.people_categories._before_delete.append(INHIBIT_CASCADE_DELETE)
db.people_categories._before_delete.append(dbui.INHIBIT_DELETE_UNDEF)
db.people_categories._before_update.append(dbui.INHIBIT_UPDATE_UNDEF)
# -*- coding: utf-8 -*-
""" projects
"""
db.define_table("projects",
Field("project", "string", length=255, notnull=True, unique=True),
migrate="projects.table")
db.projects._before_delete.append(INHIBIT_CASCADE_DELETE)
db.projects._before_delete.append(dbui.INHIBIT_DELETE_UNDEF)
db.projects._before_update.append(dbui.INHIBIT_UPDATE_UNDEF)
# -*- coding: utf-8 -*-
""" teams
"""
db.define_table("teams",
Field("team", "string", length=255, notnull=True, unique=True),
migrate="teams.table")
db.teams._before_delete.append(INHIBIT_CASCADE_DELETE)
db.teams._before_delete.append(dbui.INHIBIT_DELETE_UNDEF)
db.teams._before_update.append(dbui.INHIBIT_UPDATE_UNDEF)
# -*- 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 -*-
""" history
"""
db.define_table("history",
Field("id_events", "reference events", default=undef_id, label='Event'),
Field("id_domains", "reference domains", default=undef_id, label='Domain'),
Field("id_teams", "reference teams", default=undef_id, label='Team'),
Field("id_projects", "reference projects", default=undef_id, label='Project'),
Field("id_fundings", "reference fundings", default=undef_id, label='Funding'),
Field("id_people", "reference people", default=undef_id, label='Person'),
Field("id_people_categories", "reference people_categories", default=undef_id, label='People category'),
Field("percentage", "integer", default=None),
Field("id_objects", "reference objects", default=undef_id, label='Object'),
Field("id_object_categories", "reference object_categories", default=undef_id, label='Object category'),
Field("start_date", "date", default=today, notnull=True),
Field("end_date", "date"),
Field("note", "text"),
Field("data", "json", default=dict()),
migrate="history.table")
# NOTE: we have to remove the json validator to work !!
db.history.data.requires = None
db.history.id_events.requires = IS_IN_DB(db, 'events.event')
db.history.id_people.requires = IS_IN_DB(db, 'people.last_name')
# -*- coding: utf-8 -*-
""" teams
"""
#-------------------------------------------------------------------------------
#
# FIELDS CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# FORM CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# GRID CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# STORE CONFIGURATiON
#
#-------------------------------------------------------------------------------
storeModifier = dbui.StoreModifier('domains')
storeModifier.orderby(db.domains.domain)
\ No newline at end of file
# -*- coding: utf-8 -*-
""" events
"""
#-------------------------------------------------------------------------------
#
# FIELDS CONFIGURATiON
#
#-------------------------------------------------------------------------------
fieldsModifier = dbui.FieldsModifier('events')
fieldsModifier.configure_field('data',
colProperty={'width': 70},
colType={'width': 70},
fieldLabel='',
xtype='xuserdata')
#-------------------------------------------------------------------------------
#
# FORM CONFIGURATiON
#
#-------------------------------------------------------------------------------
formModifier = dbui.FormModifier('events')
formModifier.merge_fields('event',
'definition',
title=T('General'))
formModifier.merge_fields('data',
title=T('Data model'))
formModifier.set_mapper(dbui.map_tabpanel)
formModifier.configure(plugins=['pUserDataConsistency'], width=450)
#-------------------------------------------------------------------------------
#
# GRID CONFIGURATiON
#
#-------------------------------------------------------------------------------
gridModifier = dbui.GridModifier('events')
gridModifier.configure_column('event', width=30)
gridModifier.hide_columns('data')
row_widget = {
'ptype': 'rowwidget',
'widget': {
'xtype': 'xuserdata',
'bind': {
'value': '{record.EventsData}'
},
'defaults': {'anchor': '90%'},
'colProperty': {'width': 80},
'colType': {'width': 80},
'padding': '10 0 12 50',
'readOnly': True
}
}
gridModifier.configure(plugins=[row_widget])
#-------------------------------------------------------------------------------
#
# STORE CONFIGURATiON
#
#-------------------------------------------------------------------------------
storeModifier = dbui.StoreModifier('events')
storeModifier.orderby(db.events.event)
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