Commit 72fb3f7f authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Modify the database schema by introducing funding agencies. Add the

toolbox scripts.
parent 0d5a5ae5
""" Toolbox to ease the maintenance/migration of the database.
"""
import csv
import os
import re
def load_csv():
"""Load a csv file in a database table.
The csv file is produced by using the sqlitebrowser.
This method preserved id for the primary and the foreign keys.
The action is steered via the URL:
http://localhost:8000/track_teams/scripts/load_csv?table=foo&fn=foo.csv
The csv file is located in the web2py directory.
"""
if 'table' not in request.vars:
return 'Specify the name of the table !!!'
tablename = request.vars.table
if tablename not in db.tables:
return 'Invalid database table name "%s"' % tablename
if 'fn' not in request.vars:
return 'Specify the name of the csv file !!!'
fn = request.vars.fn
fi = open(fn, 'r')
reader = csv.DictReader(fi)
for di in reader:
db[tablename][0] = di
return 'File "%s" loaded in "%s"' % (fn, tablename)
doc/database.png

101 KB | W: | H:

doc/database.png

91 KB | W: | H:

doc/database.png
doc/database.png
doc/database.png
doc/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="593" y="21" 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="phd_flag" null="1" autoincrement="0"><datatype>boolean</datatype></row><row name="hdr_flag" null="1" autoincrement="0"><datatype>boolean</datatype></row><row name="phd_date" null="1" autoincrement="0"><datatype>date</datatype></row><row name="hdr_date" null="1" autoincrement="0"><datatype>integer</datatype></row><row name="note" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="596" y="281" name="teams"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="team" null="0" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="590" y="393" name="projects"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="project" null="0" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="932" y="139" name="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="definition" null="1" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="803" y="57" 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_categories" null="0" autoincrement="0"><datatype>integer</datatype><relation table="categories" 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="note" null="0" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="327" y="56" name="responsabilities"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="id_people" null="1" autoincrement="0"><datatype>integer</datatype><relation table="people" row="id" /></row><row name="id_teams" null="1" 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="responsability" null="0" autoincrement="0"><datatype>string</datatype></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="id_organizations" null="0" autoincrement="0"><datatype>integer</datatype><relation table="organizations" row="id" /></row><row name="id_levels" null="0" autoincrement="0"><datatype>integer</datatype><relation table="levels" row="id" /></row><row name="note" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="348" y="316" name="hardware"><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="model" null="0" autoincrement="0"><datatype>string</datatype></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="cost" null="1" autoincrement="0"><datatype>integer</datatype></row><row name="note" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="109" y="154" 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="note" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="133" y="277" name="levels"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="level" null="0" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="807" y="316" name="budgets"><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="year" null="0" autoincrement="0"><datatype>integer</datatype></row><row name="line" null="1" autoincrement="0"><datatype>string</datatype></row><row name="demanded" null="1" autoincrement="0"><datatype>integer</datatype></row><row name="notified" null="1" autoincrement="0"><datatype>integer</datatype></row><row name="executed" null="1" autoincrement="0"><datatype>integer</datatype></row><row name="note" 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="593" y="21" 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="phd_flag" null="1" autoincrement="0"><datatype>boolean</datatype></row><row name="hdr_flag" null="1" autoincrement="0"><datatype>boolean</datatype></row><row name="phd_date" null="1" autoincrement="0"><datatype>date</datatype></row><row name="hdr_date" null="1" autoincrement="0"><datatype>integer</datatype></row><row name="note" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="596" y="281" name="teams"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="team" null="0" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="590" y="393" name="projects"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="project" null="0" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="932" y="139" name="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="definition" null="1" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="803" y="57" 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_categories" null="0" autoincrement="0"><datatype>integer</datatype><relation table="categories" row="id" /></row><row name="id_agencies" null="0" autoincrement="0"><datatype>integer</datatype><relation table="agencies" 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="note" null="0" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="327" y="56" name="responsabilities"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="id_people" null="1" autoincrement="0"><datatype>integer</datatype><relation table="people" row="id" /></row><row name="id_teams" null="1" 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="responsability" null="0" autoincrement="0"><datatype>string</datatype></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="id_organizations" null="0" autoincrement="0"><datatype>integer</datatype><relation table="organizations" row="id" /></row><row name="id_levels" null="0" autoincrement="0"><datatype>integer</datatype><relation table="levels" row="id" /></row><row name="note" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="348" y="316" name="hardware"><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="model" null="0" autoincrement="0"><datatype>string</datatype></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="cost" null="1" autoincrement="0"><datatype>integer</datatype></row><row name="note" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="109" y="154" 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="note" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="133" y="277" name="levels"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="level" null="0" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="805" y="339" name="budgets"><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="year" null="0" autoincrement="0"><datatype>integer</datatype></row><row name="line" null="1" autoincrement="0"><datatype>string</datatype></row><row name="demanded" null="1" autoincrement="0"><datatype>integer</datatype></row><row name="notified" null="1" autoincrement="0"><datatype>integer</datatype></row><row name="executed" null="1" autoincrement="0"><datatype>integer</datatype></row><row name="note" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="937" y="266" name="agencies"><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></sql>
\ No newline at end of file
# coding: utf8
{
'%Y-%m-%d': '%Y-%m-%d',
'Agency': 'Agence',
'Birth Date': 'Né le',
'CDD': 'CDD',
'Category': 'Catégorie',
......@@ -59,6 +60,7 @@
'Year': 'Année',
'Year End': 'Year End',
'Year Start': 'Year Start',
'agencies': 'agencies',
'budgets': 'budgets',
'careers': 'carrières',
'categories': 'catégories',
......
......@@ -56,6 +56,11 @@ db = DAL('sqlite://storage.sqlite', migrate=True)
# basic tables
#
#-------------------------------------------------------------------------------
db.define_table("agencies",
Field("agency", "string", notnull=True),
Field("definition", "text"),
migrate="agencies.table")
db.define_table("categories",
Field("code", "string", notnull=True),
Field("definition", "text"),
......@@ -143,6 +148,7 @@ db.define_table("history",
Field("id_teams", db.teams, default=undef_id, label='Team'),
Field("id_projects", db.projects, default=undef_id, label='Project'),
Field("id_categories", db.categories, default=undef_id, label='Category'),
Field("id_agencies", db.agencies, default=undef_id, label='Agency'),
Field("cdd_flag", "boolean", default=False, label="CDD"),
Field("start_date", "date", default=today, notnull=True),
Field("end_date", "date"),
......@@ -162,6 +168,9 @@ IS_IN_DB(db, 'projects.id', 'projects.project')
db.history.id_categories.requires = \
IS_IN_DB(db, 'categories.id', 'categories.code')
db.history.id_agencies.requires = \
IS_IN_DB(db, 'agencies.id', 'agencies.agency')
db.define_table("responsabilities",
Field("id_people", db.people, default=undef_id, label='Person'),
......
......@@ -4,6 +4,9 @@
Insert defaults values in the tables
"""
if not db(db.agencies.id).count():
db.agencies.insert(id=undef_id, agency=undef, definition=undef)
if not db(db.categories.id).count():
db.categories.insert(id=undef_id, code=undef, definition=undef)
......
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