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

Remove obsolete controller toolbox and wizard.

parent 0751cb66
""" Toolbox to ease the maintenance/migration of the database.
"""
import csv
import os
import re
def export_csv():
"""export a table as csv file.
The action is steered via the URL:
http://localhost:8000/track_teams/toolbox/export_csv?table=foo&fn=foo.csv
The csv file is located in the web2py main 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, 'w')
writer = csv.DictWriter(fi,
db[tablename].fields,
quoting=csv.QUOTE_MINIMAL)
# write the header
headers = {}
for el in db[tablename].fields:
headers[el] = el
writer.writerow(headers)
# write rows
for row in db(db[tablename]).select():
writer.writerow(row.as_dict())
# close and exit
fi.close()
return 'Table "%s" export in "%s"' % (tablename, fn)
def import_csv():
"""import a csv file in a database table.
The csv file is produced by using the export_csv method.
This method preserved id for the primary and the foreign keys.
The action is steered via the URL:
http://localhost:8000/track_teams/toolbox/import_csv?table=foo&fn=foo.csv
The csv file is located in the web2py main 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" import in "%s"' % (fn, tablename)
def test():
""" test selection on date
"""
print
query = db.history.start_date >= "2009-10-01"
query = (query) & (db.history.end_date <= "2012-09-29")
for row in db(query).select(db.history.ALL):
print row.start_date, row.end_date
\ No newline at end of file
""" Wizard controllers
"""
import traceback
from plugin_dbui import get_id
from reporting_tools import MySelector
def person():
# instenciate the selector
selector = MySelector(virtdb.person_wizard)
try:
# people section
id_people = get_id(db.people,
first_name=selector.first_name,
last_name=selector.last_name)
if id_people != None:
return T("The person exists in the database. "
"Modify the history table instead.")
id_people = db.people.insert(first_name=selector.first_name,
last_name=selector.last_name,
initials=selector.initials,
birth_date=selector.birth_date)
# history section
db.history.insert(id_people=id_people,
id_teams=selector.id_teams,
id_projects=selector.id_projects,
id_people_categories=selector.id_people_categories,
start_date=selector.start_date,
end_date=selector.end_date)
return T("Add a new person successfully")
except BaseException, e:
msg = '<br><br><hr/>'
msg += CODE(traceback.format_exc()).xml()
msg += '<hr/>'
return msg
def trainee():
# instenciate the selector
selector = MySelector(virtdb.trainee_wizard)
try:
# people section
id_people = get_id(db.people,
first_name=selector.first_name,
last_name=selector.last_name)
if id_people == None:
initials = selector.first_name[0]+selector.last_name[0]
id_people = db.people.insert(first_name=selector.first_name,
last_name=selector.last_name,
initials=initials,
birth_date=selector.birth_date)
# people category
id_people_category = get_id(db.people_categories, code=selector.trainee_level)
# history section
id = db.history.insert(id_people=id_people,
id_teams=selector.id_teams,
id_projects=selector.id_projects,
id_people_categories=id_people_category,
start_date=selector.start_date,
end_date=selector.end_date,
cdd_flag=True,
percentage=100,
trainee_title=selector.trainee_title,
trainee_university=selector.trainee_university,
trainee_category=selector.trainee_category)
return T("Add a new history line %i") % id
except BaseException, e:
msg = '<br><br><hr/>'
msg += CODE(traceback.format_exc()).xml()
msg += '<hr/>'
return msg
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