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

First implementation of an history view

parent 3f028844
......@@ -23,17 +23,13 @@ def hardware():
q = (q) & ((db.hardware.end_date == None) | (db.hardware.end_date >= selector.period_start))
query = (query) & (q)
# define virtual field to compute time data
# to be added in the report via extra columns
db.hardware.age = Field.Virtual(Hardware(selector).age)
db.hardware.duration = Field.Virtual(Hardware(selector).duration)
# select the records
rows = db(query).select(db.people.last_name,
db.hardware.model,
db.hardware.start_date,
db.hardware.end_date,
db.hardware.cost,
rows = db(query).select(db.hardware.ALL,
db.people.ALL,
orderby=(db.hardware.model, db.people.last_name))
header = get_header(selector, prefix='List of hardware ')
......@@ -44,6 +40,36 @@ def hardware():
selector=selector)
def history():
"""History for a person.
"""
selector = Selector(db)
if not selector.id_people:
return 'Select a person. !!!'
# build the query
query = selector.query('history')
# define virtual field to compute time data
# to be added in the report via extra columns
db.history.duration = Field.Virtual(Person(selector).duration)
# retrieve the records
rows = db(query).select(db.categories.ALL,
db.history.ALL,
db.people.ALL,
db.projects.ALL,
db.teams.ALL,
orderby=db.history.start_date)
header = get_header(selector, prefix='History ')
return dict(footer='',
header=header,
rows=rows,
selector=selector)
def index():
return 'List section'
......@@ -75,14 +101,10 @@ def people():
db.history.time_coverage = Field.Virtual(tool.coverage)
db.people.age = Field.Virtual(tool.age)
# select the records
rows = db(query).select(db.categories.usual,
db.people.last_name,
db.categories.code,
db.history.cdd_flag,
db.history.start_date,
db.history.end_date,
db.people.birth_date,
# retrieve the records
rows = db(query).select(db.categories.ALL,
db.history.ALL,
db.people.ALL,
orderby=(db.categories.usual, db.people.last_name))
header = get_header(selector, prefix='List of people ')
......
......@@ -24,6 +24,7 @@
'Definition': 'Définition',
'Demanded': 'Demandé',
'Domain': 'Domaine',
'Duration': 'Duration',
'End': 'End',
'End Date': 'Date de fin',
'enter a number between %(min)g and %(max)g': 'enter a number between %(min)g and %(max)g',
......@@ -52,6 +53,7 @@
'Hdr': 'Hdr',
'Hdr Date': 'Hdr Date',
'Hdr defense date': "Date de soutenace de l'hdr",
'History': 'History',
'history': 'historique',
'Id': 'Id',
'Initials': 'Initiales',
......
......@@ -31,6 +31,26 @@ IS_IN_DB(db, 'teams.id', 'teams.team')
virtdb.hardware_selector.format.requires = IS_IN_SET(['html'])
#
# history selector
#
virtdb.define_table('history_selector',
Field('id_people', db.people, label='Person'),
Field('id_teams', db.teams, label='Team'),
Field('id_projects', db.projects, label='Project'),
Field('format', 'string', default='html'))
virtdb.history_selector.id_people.requires = \
IS_IN_DB(db, 'people.id', 'people.last_name')
virtdb.history_selector.id_projects.requires = \
IS_IN_DB(db, 'projects.id', 'projects.project')
virtdb.history_selector.id_teams.requires = \
IS_IN_DB(db, 'teams.id', 'teams.team')
virtdb.history_selector.format.requires = IS_IN_SET(['html'])
#
# people selector
#
......
......@@ -32,7 +32,18 @@ hardwareNode = dbui.PanelWithUrlSelector(baseUrl=url,
selectorCfg=selector,
selectorCollapsible=False)
fields = dbui.to_fields(virtdb.history_selector)
selector = dbui.FieldSet(items=fields,
plugins=['pFormToolTip'],
title=T('Select'))
url = '/'+request.application+'/list/history'
historyNode = dbui.PanelWithUrlSelector(baseUrl=url,
panelCfg=dbui.Panel(),
selectorCfg=selector,
selectorCollapsible=False)
reportNode = dbui.Node(T('Reports'))
reportNode.add_child(T('History'), historyNode)
reportNode.add_child(T('List of hardware'), hardwareNode)
reportNode.add_child(T('List of people'), peopleNode)
reportNode.sort_children()
......
......@@ -13,20 +13,24 @@ class Base(object):
now = datetime.now()
self.now = date(now.year, now.month, now.day)
self.period_start = None
self.period_end = None
if 'period_start' in selector:
ds = datetime.strptime(selector.period_start, '%Y-%m-%d')
self.period_start = date(ds.year, ds.month, ds.day)
ds = datetime.strptime(selector.period_start, '%Y-%m-%d')
self.period_start = date(ds.year, ds.month, ds.day)
de = datetime.strptime(selector.period_end, '%Y-%m-%d')
self.period_end = date(de.year, de.month, de.day)
if 'period_end' in selector:
de = datetime.strptime(selector.period_end, '%Y-%m-%d')
self.period_end = date(de.year, de.month, de.day)
class Hardware(Base):
"""Tool associate to a hardware item.
"""
def age(self, row):
"""Compute the age of an hardware item.
def duration(self, row):
"""Compute the duration of an hardware item.
"""
start = row.hardware.start_date
......@@ -35,15 +39,27 @@ class Hardware(Base):
now = self.now
if start and end and start <= now <= end:
return (now - start).days / 365.
dt = now - start
elif start and end == None and start <= now:
return (now - start).days / 365.
dt = now - start
elif start and end and end < now:
return (end - start).days / 365.
dt = end - start
else:
return ''
ny = dt.days / 365
nm = int((dt.days - ny*365) / (365./12.))
if ny and nm:
return '%i years %i months' % (ny, nm)
elif ny and not nm:
return '%i years' % ny
elif nm:
return '%i months' % nm
else:
return '%i days' % dt.days
return None
class Person(Base):
......@@ -58,7 +74,7 @@ class Person(Base):
x = ((self.now - row.people.birth_date).days / 365)
return x
return None
return ''
def coverage(self, row):
......@@ -79,6 +95,24 @@ class Person(Base):
return z
def duration(self, row):
"""The time spent in one history step.
"""
start = row.history.start_date
end = row.history.end_date
now = self.now
if start and end:
dt = end - start
elif start and now >= start:
dt = now - start
else:
return ''
return dt.days / 365.
def get_header(selector, prefix="", suffix=""):
"""Helper function returning the header for the report.
The return string contains the team, the project and some
......
......@@ -3,9 +3,9 @@
<br>
{{
# column with the hardware age
age = {'label': T('Age'),
age = {'label': T('Duration'),
'class': '',
'content': lambda row, rc: round(row.hardware.age, 1),
'content': lambda row, rc: row.hardware.duration,
'selected': False,
'width': ''}
......
{{=H1(header)}}
<br>
<br>
{{
# column with the duration spent in each step
duration = {'label': T('Duration'),
'class': '',
'content': lambda row, rc: row.history.duration,
'selected': False,
'width': ''}
# render the table
table = SQLTABLE(rows,
columns=['teams.team',
'projects.project',
'categories.code',
'history.start_date'],
headers={'teams.team': T('Team'),
'projects.project': T('Project'),
'categories.code': T('Level'),
'history.start_date': T('Start')},
extracolumns=[duration],
renderstyle=True)
response.write(CENTER(table))
}}
{{=footer}}
\ 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