Commit 1f26a988 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

list of people is almost finish.

parent 7bc3a6ab
......@@ -17,37 +17,60 @@ def people():
"""Active people for a given period of time, team, ...
"""
periods = ('period_start', 'period_end')
time_fields = ('year', 'period_start', 'period_end')
selector = Selector(db)
query = selector.query('history', exclude_fields=periods)
# team / project header
if not selector.id_projects and selector.id_teams:
header = db.teams[selector.id_teams].team
elif selector.id_projects and not selector.id_teams:
header = db.projects[selector.id_projects].project
# strip the period string to YYYY-MM-DD
for field in periods:
if field in selector:
elif selector.id_projects and selector.id_teams:
header = "%s/%s" % (db.teams[selector.id_teams].team,
db.projects[selector.id_projects].project)
else:
header = ""
# time period
if selector.year:
header = "%s in %s" % (header, selector.year)
selector.period_start = "%s-01-01" % selector.year
selector.period_end = "%s-12-31" % selector.year
elif selector.period_start and selector.period_end:
for field in ('period_start', 'period_end'):
s = selector[field]
selector[field] = s[:s.find('T')]
header = "%s between %s and %s" % (header,
selector.period_start,
selector.period_end)
else:
return T('Defined a year or a time period !!!')
# period constraints
# build the query
query = selector.query('history', exclude_fields=time_fields)
if 'period_start' in selector and 'period_end' in selector:
q = db.history.start_date <= selector.period_end
q = (q) & ((db.history.end_date == None) | (db.history.end_date >= selector.period_start))
query = (query) & (q)
else:
return 'Defined a time period !!!'
# avoid stage
# avoid the category "stage"
q = db.categories.usual != 'stagiaire'
query = (query) & (q)
# select the record
# select the records
rows = db(query).select(db.categories.usual,
db.people.last_name,
db.categories.code,
db.history.cdd_flag,
groupby=db.people.last_name,
db.history.start_date,
db.history.end_date,
orderby=(db.categories.usual, db.people.last_name))
return dict(header='', rows=rows, footer='')
\ No newline at end of file
return dict( footer='', header=header, rows=rows, selector=selector)
\ No newline at end of file
......@@ -12,6 +12,7 @@
'Collections': 'Collections',
'Controller': 'Controller',
'Cost': 'Coût',
'Defined a year or a time period !!!': 'Defined a year or a time period !!!',
'Definition': 'Définition',
'Demanded': 'Demandé',
'Domain': 'Domaine',
......@@ -66,12 +67,14 @@
'Ratio': 'Ratio',
'Responsibility': 'Responsabilité',
'Select': 'Selectionnez',
'Select a teams and/or a project !!!': 'Select a teams and/or a project !!!',
'Start Date': 'Date de début',
'Store': 'Store',
'Tables': 'Tables',
'Team': 'Équipe',
'Tools': 'Outils',
'Usual': 'Habituel',
'Weight': 'Poid',
'Year': 'Année',
'Year End': 'Year End',
'Year Start': 'Year Start',
......
......@@ -34,6 +34,7 @@ virtdb.hardware_selector.format.requires = IS_IN_SET(['html'])
# people selector
#
virtdb.define_table('people_selector',
Field('year', 'integer'),
Field('period_start', 'date'),
Field('period_end', 'date'),
Field('id_teams', db.teams, label='Team'),
......
<h1>List of people</h1>
{{=H1(header)}}
<br>
<br>
{{=CENTER(SQLTABLE(rows,
headers="labels",
renderstyle=True,
truncate=32))
}}
\ No newline at end of file
{{
from datetime import date, datetime
ds = datetime.strptime(selector.period_start, '%Y-%m-%d')
period_start = date(ds.year, ds.month, ds.day)
de = datetime.strptime(selector.period_end, '%Y-%m-%d')
period_end = date(de.year, de.month, de.day)
def compute_weight(row, rc):
start = max(period_start, row.history.start_date)
end = period_end
if row.history.end_date:
end = min(period_end, row.history.end_date)
pass
x = (end - start).days
y = (period_end - period_start).days
z = round(float(x) / float(y), 2)
return z
cdd = {'label': 'CDD',
'class': '',
'content': lambda row, rc: (CENTER('x') if row.history.cdd_flag else ''),
'selected': False,
'width': ''}
weight = {'label': T('Weight'),
'class': '',
'content': compute_weight,
'selected': False,
'width': ''}
table = SQLTABLE(rows,
columns=['categories.usual',
'people.last_name',
'categories.code'],
headers={'categories.usual': T('Category'),
'people.last_name': T('Name'),
'categories.code': T('Level')},
extracolumns=[cdd, weight],
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