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

Add the dictionary data in events and history tables. Modify the reporting to use it.

parent eafaaf4e
......@@ -55,11 +55,25 @@ def list():
# It is mandatory to preserve the data fields order
for row in report.select(db.history):
li = []
for field in cfg['fields']:
value = row[field['name']]
# standard database type
if field['name'].count('.') == 1:
value = row[field['name']]
# json database type
elif field['name'].count('.') == 2:
i = field['name'].rindex(".")
fieldname = field['name'][:i]
key = field['name'][i+1:]
if key in row[fieldname]:
value = row[fieldname][key]
else:
value = ""
if isinstance(value, date):
value = value.strftime("%Y-%m-%d")
......
......@@ -63,10 +63,12 @@
'Coût': 'Coût',
'Created By': 'Created By',
'Created On': 'Created On',
'Data': 'Data',
'Data base scheme': 'Schéma base de donnée',
'Data people': 'Les données des personnes',
'Database field encoded as tablename.fieldname.': 'Champ de la base de donnée encodé tablename.fieldname.',
'database schema': 'schéma de la base de données',
'Define the data model. At each property is associate a type or a default value. Valid type are boolean, date, number and string.': 'Definit le modéle des données. A chaque propriété est associé un type ou une value par défault. Les type sont boolean, date, number et string.',
'Defined a year or a time period !!!': 'Defined a year or a time period !!!',
'Definition': 'Définition',
'Demanded': 'Demandé',
......@@ -161,6 +163,7 @@
'Initials': 'Initiales',
'install': 'installé',
'Invalid email': 'Invalid email',
'Invalid json': 'Invalid json',
'invalid json': 'invalid json',
'Invalid login': 'Invalid login',
'Is Active': 'Is Active',
......@@ -252,6 +255,7 @@
'project leader,...': 'project leader,...',
'projects': 'projets',
'Projet': 'Projet',
'Property': 'Property',
'Python API': 'Python API',
'Python Code': 'Python Code',
'Quality': 'Qualité',
......
......@@ -2,10 +2,19 @@
""" events
"""
tp_data = \
T("Define the data model. "
"At each property is associate a type or a default value. "
"Valid type are boolean, date, number and string.")
db.define_table("events",
Field("event", "string", length=255, notnull=True, unique=True),
Field("category", "string", length=255, notnull=True),
Field("definition", "text"),
Field("data", "json", comment=tp_data, label="Model"),
migrate="events.table")
db.events._before_delete.append(INHIBIT_CASCADE_DELETE)
# NOTE: we have to remove the json validator to work !!
db.events.data.requires = None
......@@ -22,8 +22,12 @@ db.define_table("history",
Field("hardware_model", "string", length=255, label=T("Model")),
Field("hardware_cost", "double", label=T("Cost")),
Field("note", "text"),
Field("data", "json"),
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')
db.history.trainee_category.requires = IS_IN_USET((undef, 'PHY', 'IR'))
db.history.trainee_category.requires = IS_IN_USET((undef, 'PHY', 'IR'))
\ No newline at end of file
......@@ -7,6 +7,11 @@
# FIELDS CONFIGURATiON
#
#-------------------------------------------------------------------------------
fieldsModifier = dbui.FieldsModifier('events')
fieldsModifier.configure_field('data',
headers=[T('Property'), T('Type')],
modifyKeys=True,
height=150)
#-------------------------------------------------------------------------------
#
......
......@@ -8,6 +8,8 @@
#
#-------------------------------------------------------------------------------
fieldsModifier = dbui.FieldsModifier('history')
fieldsModifier.configure_field('data', modifyKeys=True, height=150)
fieldsModifier.configure_field('start_date', flex=1)
fieldsModifier.configure_field('end_date', flex=1)
fieldsModifier.merge_fields('start_date', 'end_date', fieldLabel=T('Period'))
......@@ -35,19 +37,22 @@ formModifier.merge_fields('id_fundings',
formModifier.merge_fields('percentage',
title=T('FTE'))
formModifier.merge_fields('id_organizations',
'id_organization_levels',
'responsibility',
title=T('Responsibility'))
formModifier.merge_fields('hardware_model',
'hardware_cost',
title=T('Hardware'))
formModifier.merge_fields('trainee_title',
'trainee_university',
'trainee_category',
title=T('Stage'))
# formModifier.merge_fields('id_organizations',
# 'id_organization_levels',
# 'responsibility',
# title=T('Responsibility'))
#
# formModifier.merge_fields('hardware_model',
# 'hardware_cost',
# title=T('Hardware'))
#
# formModifier.merge_fields('trainee_title',
# 'trainee_university',
# 'trainee_category',
# title=T('Stage'))
formModifier.merge_fields('data',
title=T('Data'))
formModifier.merge_fields('note',
title=T('Note'))
......@@ -68,6 +73,7 @@ gridModifier = dbui.GridModifier('history')
gridModifier.configure(plugins=['pGridPaging'])
gridModifier.hide_columns('cdd_flag',
'data',
'id_organization_levels',
'id_organizations',
'id_projects',
......
"""reporting tools module
"""
import json
import re
......@@ -48,19 +49,27 @@ def to_dataFields(cfg_columns):
"""
li = []
db = current.globalenv['db']
# extract the list of database field names from the column configuration
columns = re.findall("dataIndex *: *'([a-z_\.]+)'", cfg_columns)
# convert the database field into and Exr.data.Field
# convert the database field into and Ext.data.Field
for column in columns:
cfg = dict()
cfg['name'] = column
# standard field
if column.count(".") == 1:
tablename, fieldname = column.split('.')
field = db[tablename][fieldname]
tablename, fieldname = column.split('.')
field = db[tablename][fieldname]
# json type
elif column.count(".") == 2:
i = column.rindex(".")
tablename, fieldname = column[:i].split('.')
field = db[tablename][fieldname]
cfg['type'] = field.type
if field.type in ('string', 'text', 'json'):
cfg['type'] = 'string'
......@@ -87,7 +96,7 @@ def to_dataFields(cfg_columns):
cfg['type'] = field.type
li.append(cfg)
return li
......
static/docs/database.png

124 KB | W: | H:

static/docs/database.png

116 KB | W: | H:

static/docs/database.png
static/docs/database.png
static/docs/database.png
static/docs/database.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -22,4 +22,4 @@
<type label="Upload" length="0" sql="upload" quote="'"/>
<type label="Password" length="0" sql="password" quote="'"/>
</group>
</datatypes><table x="231" y="31" name="people"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="first_name" null="0" autoincrement="0"><datatype>string</datatype></row><row name="last_name" null="0" autoincrement="0"><datatype>string</datatype></row><row name="initials" null="0" autoincrement="0"><datatype>string</datatype></row><row name="birth_date" null="1" autoincrement="0"><datatype>date</datatype></row><row name="note" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="233" y="192" name="teams"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="team" null="0" autoincrement="0"><datatype>string</datatype></row><row name="domain" null="1" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="233" y="292" name="projects"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="project" null="0" autoincrement="0"><datatype>string</datatype></row><row name="agencies" null="1" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="640" y="32" name="people_categories"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="code" null="0" autoincrement="0"><datatype>string</datatype></row><row name="category" null="0" autoincrement="0"><datatype>string</datatype></row><row name="definition" null="1" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="445" y="48" name="history"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="id_people" null="0" autoincrement="0"><datatype>integer</datatype><relation table="people" row="id" /></row><row name="id_teams" null="0" autoincrement="0"><datatype>integer</datatype><relation table="teams" row="id" /></row><row name="id_projects" null="0" autoincrement="0"><datatype>integer</datatype><relation table="projects" row="id" /></row><row name="id_people_categories" null="0" autoincrement="0"><datatype>integer</datatype><relation table="people_categories" row="id" /></row><row name="id_fundings" null="0" autoincrement="0"><datatype>integer</datatype><relation table="fundings" row="id" /></row><row name="id_events" null="0" autoincrement="0"><datatype>integer</datatype><relation table="events" row="id" /></row><row name="cdd_flag" null="0" autoincrement="0"><datatype>boolean</datatype><default>False</default></row><row name="start_date" null="0" autoincrement="0"><datatype>date</datatype></row><row name="end_date" null="1" autoincrement="0"><datatype>date</datatype></row><row name="percentage" null="1" autoincrement="0"><datatype>integer</datatype></row><row name="trainee_title" null="1" autoincrement="0"><datatype>text</datatype></row><row name="trainee_university" null="1" autoincrement="0"><datatype>text</datatype></row><row name="trainee_category" null="0" autoincrement="0"><datatype>string</datatype></row><row name="id_organizations" null="0" autoincrement="0"><datatype>integer</datatype><relation table="organizations" row="id" /></row><row name="id_organization_levels" null="0" autoincrement="0"><datatype>integer</datatype><relation table="organization_levels" row="id" /></row><row name="responsibility" null="1" autoincrement="0"><datatype>string</datatype></row><row name="hardware_model" null="1" autoincrement="0"><datatype>string</datatype></row><row name="hardware_cost" null="1" autoincrement="0"><datatype>integer</datatype></row><row name="note" null="0" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="236" y="391" name="organizations"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="organization" null="0" autoincrement="0"><datatype>string</datatype></row><row name="definition" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="650" y="154" name="fundings"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="agency" null="0" autoincrement="0"><datatype>string</datatype></row><row name="definition" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="667" y="384" name="organization_levels"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="level" null="0" autoincrement="0"><datatype>string</datatype></row><row name="definition" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="661" y="261" name="events"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="code" null="0" autoincrement="0"><datatype>string</datatype></row><row name="event" null="0" autoincrement="0"><datatype>string</datatype></row><row name="definitiion" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="901" y="286" name="views"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="view" null="0" autoincrement="0"><datatype>string</datatype></row><row name="title" null="1" autoincrement="0"><datatype>string</datatype></row><row name="conditions" null="1" autoincrement="0"><datatype>text</datatype></row><row name="group_field" null="1" autoincrement="0"><datatype>string</datatype></row><row name="sorters" null="1" autoincrement="0"><datatype>integer</datatype></row><row name="columns" null="0" autoincrement="0"><datatype>text</datatype></row><row name="features" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table></sql>
\ No newline at end of file
</datatypes><table x="268" y="38" name="people"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="first_name" null="0" autoincrement="0"><datatype>string</datatype></row><row name="last_name" null="0" autoincrement="0"><datatype>string</datatype></row><row name="initials" null="0" autoincrement="0"><datatype>string</datatype></row><row name="birth_date" null="1" autoincrement="0"><datatype>date</datatype></row><row name="note" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="272" y="192" name="teams"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="team" null="0" autoincrement="0"><datatype>string</datatype></row><row name="domain" null="1" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="276" y="290" name="projects"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="project" null="0" autoincrement="0"><datatype>string</datatype></row><row name="agencies" null="1" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="639" y="27" name="people_categories"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="code" null="0" autoincrement="0"><datatype>string</datatype></row><row name="category" null="0" autoincrement="0"><datatype>string</datatype></row><row name="definition" null="1" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="445" y="48" name="history"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="id_people" null="0" autoincrement="0"><datatype>integer</datatype><relation table="people" row="id" /></row><row name="id_teams" null="0" autoincrement="0"><datatype>integer</datatype><relation table="teams" row="id" /></row><row name="id_projects" null="0" autoincrement="0"><datatype>integer</datatype><relation table="projects" row="id" /></row><row name="id_people_categories" null="0" autoincrement="0"><datatype>integer</datatype><relation table="people_categories" row="id" /></row><row name="id_fundings" null="0" autoincrement="0"><datatype>integer</datatype><relation table="fundings" row="id" /></row><row name="id_events" null="0" autoincrement="0"><datatype>integer</datatype><relation table="events" row="id" /></row><row name="cdd_flag" null="0" autoincrement="0"><datatype>boolean</datatype><default>False</default></row><row name="start_date" null="0" autoincrement="0"><datatype>date</datatype></row><row name="end_date" null="1" autoincrement="0"><datatype>date</datatype></row><row name="percentage" null="1" autoincrement="0"><datatype>integer</datatype></row><row name="trainee_title" null="1" autoincrement="0"><datatype>text</datatype></row><row name="trainee_university" null="1" autoincrement="0"><datatype>text</datatype></row><row name="trainee_category" null="0" autoincrement="0"><datatype>string</datatype></row><row name="id_organizations" null="0" autoincrement="0"><datatype>integer</datatype><relation table="organizations" row="id" /></row><row name="id_organization_levels" null="0" autoincrement="0"><datatype>integer</datatype><relation table="organization_levels" row="id" /></row><row name="responsibility" null="1" autoincrement="0"><datatype>string</datatype></row><row name="hardware_model" null="1" autoincrement="0"><datatype>string</datatype></row><row name="hardware_cost" null="1" autoincrement="0"><datatype>integer</datatype></row><row name="note" null="0" autoincrement="0"><datatype>text</datatype></row><row name="data" null="1" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="273" y="387" name="organizations"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="organization" null="0" autoincrement="0"><datatype>string</datatype></row><row name="definition" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="638" y="149" name="fundings"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="agency" null="0" autoincrement="0"><datatype>string</datatype></row><row name="definition" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="638" y="406" name="organization_levels"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="level" null="0" autoincrement="0"><datatype>string</datatype></row><row name="definition" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="637" y="255" name="events"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="code" null="0" autoincrement="0"><datatype>string</datatype></row><row name="event" null="0" autoincrement="0"><datatype>string</datatype></row><row name="definitiion" null="1" autoincrement="0"><datatype>text</datatype></row><row name="data" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="901" y="286" name="views"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="view" null="0" autoincrement="0"><datatype>string</datatype></row><row name="title" null="1" autoincrement="0"><datatype>string</datatype></row><row name="conditions" null="1" autoincrement="0"><datatype>text</datatype></row><row name="group_field" null="1" autoincrement="0"><datatype>string</datatype></row><row name="sorters" null="1" autoincrement="0"><datatype>integer</datatype></row><row name="columns" null="0" autoincrement="0"><datatype>text</datatype></row><row name="features" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table></sql>
\ No newline at end of file
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