Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
tev
plugin_event
Commits
37cdbc5f
Commit
37cdbc5f
authored
Oct 22, 2012
by
LE GAC Renaud
Browse files
Redesign the reporting tool class and finalise the hardware list.
parent
d2d55904
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
101 additions
and
53 deletions
+101
-53
controllers/list.py
controllers/list.py
+19
-7
languages/fr-fr.py
languages/fr-fr.py
+3
-0
modules/reporting_tools.py
modules/reporting_tools.py
+64
-38
views/list/hardware.html
views/list/hardware.html
+8
-1
views/list/people.html
views/list/people.html
+7
-7
No files found.
controllers/list.py
View file @
37cdbc5f
""" List controllers """
from
plugin_dbui
import
Selector
from
reporting_tools
import
get_header
,
set_period
,
Time_coverage
from
reporting_tools
import
(
Hardware
,
Person
,
get_header
,
set_period
)
def
hardware
():
...
...
@@ -20,15 +23,23 @@ 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
)
# 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
,
orderby
=
(
db
.
hardware
.
model
,
db
.
people
.
last_name
))
return
dict
(
footer
=
''
,
header
=
get_header
(
selector
),
rows
=
rows
,
selector
=
selector
)
return
dict
(
footer
=
''
,
header
=
get_header
(
selector
),
rows
=
rows
,
selector
=
selector
)
def
index
():
...
...
@@ -56,8 +67,9 @@ def people():
q
=
db
.
categories
.
usual
!=
'stagiaire'
query
=
(
query
)
&
(
q
)
# define virtual field to be added in the report via extra columns
db
.
history
.
time_coverage
=
Field
.
Virtual
(
Time_coverage
(
selector
).
process
)
# define virtual field to compute time data
# to be added in the report via extra columns
db
.
history
.
time_coverage
=
Field
.
Virtual
(
Person
(
selector
).
coverage
)
# select the records
rows
=
db
(
query
).
select
(
db
.
categories
.
usual
,
...
...
languages/fr-fr.py
View file @
37cdbc5f
# coding: utf8
{
'%Y-%m-%d'
:
'%Y-%m-%d'
,
'Age'
:
'Age'
,
'Agencies'
:
'Agencies'
,
'agencies'
:
'agences'
,
'Agency'
:
'Agence'
,
...
...
@@ -23,6 +24,7 @@
'Definition'
:
'Définition'
,
'Demanded'
:
'Demandé'
,
'Domain'
:
'Domaine'
,
'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'
,
'enter an integer between %(min)g and %(max)g'
:
'enter an integer between %(min)g and %(max)g'
,
...
...
@@ -91,6 +93,7 @@
'Select'
:
'Selectionnez'
,
'Select a teams and/or a project !!!'
:
'Select a teams and/or a project !!!'
,
'select...'
:
'selectionner...'
,
'Start'
:
'Start'
,
'Start Date'
:
'Date de début'
,
'startswith'
:
'startswith'
,
'Store'
:
'Store'
,
...
...
modules/reporting_tools.py
View file @
37cdbc5f
...
...
@@ -4,6 +4,68 @@
from
datetime
import
date
,
datetime
class
Base
(
object
):
"""Base class for reporting tool.
The base class translate selector period fields in python date.
"""
def
__init__
(
self
,
selector
):
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
)
class
Hardware
(
Base
):
"""Tool associate to a hardware item.
"""
def
age
(
self
,
row
):
"""Compute the age of an hardware item.
"""
start
=
row
.
hardware
.
start_date
end
=
row
.
hardware
.
end_date
now
=
datetime
.
now
()
now
=
date
(
now
.
year
,
now
.
month
,
now
.
day
)
if
start
and
end
and
start
<=
now
<=
end
:
return
(
now
-
start
).
days
/
365.
elif
start
and
end
==
None
and
start
<=
now
:
return
(
now
-
start
).
days
/
365.
elif
start
and
end
and
end
<
now
:
return
(
end
-
start
).
days
/
365.
return
None
class
Person
(
Base
):
"""Tool associated to a person
"""
def
coverage
(
self
,
row
):
"""The fraction of time for which the person was presented
during the selected period.
"""
start
=
max
(
self
.
period_start
,
row
.
history
.
start_date
)
end
=
self
.
period_end
if
row
.
history
.
end_date
:
end
=
min
(
self
.
period_end
,
row
.
history
.
end_date
)
x
=
(
end
-
start
).
days
y
=
(
self
.
period_end
-
self
.
period_start
).
days
z
=
round
(
float
(
x
)
/
float
(
y
),
2
)
return
z
def
get_header
(
selector
,
prefix
=
""
,
suffix
=
""
):
"""Helper function returning the header for the report.
The return string contains the team, the project and some
...
...
@@ -38,7 +100,7 @@ def get_header(selector, prefix="", suffix=""):
return
"%s%s%s"
%
(
prefix
,
header
,
suffix
)
def
set_period
(
selector
):
"""Helper function to setup the time period fields
from the different options available in the selector.
...
...
@@ -52,40 +114,4 @@ def set_period(selector):
for
field
in
(
'period_start'
,
'period_end'
):
s
=
selector
[
field
]
selector
[
field
]
=
s
[:
s
.
find
(
'T'
)]
class
Time_coverage
(
object
):
"""Tool to compute the fraction of time covers by a person
during the selected time period. The fractio is equal to one
for a full coverage.
The start and end date of the period is defined via a selector.
"""
def
__init__
(
self
,
selector
):
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
)
def
process
(
self
,
row
):
"""The fraction of time for which the person was active
during the selected period.
"""
start
=
max
(
self
.
period_start
,
row
.
history
.
start_date
)
end
=
self
.
period_end
if
row
.
history
.
end_date
:
end
=
min
(
self
.
period_end
,
row
.
history
.
end_date
)
x
=
(
end
-
start
).
days
y
=
(
self
.
period_end
-
self
.
period_start
).
days
z
=
round
(
float
(
x
)
/
float
(
y
),
2
)
return
z
\ No newline at end of file
views/list/hardware.html
View file @
37cdbc5f
...
...
@@ -2,13 +2,20 @@
<br>
<br>
{{
# column with the hardware age
age = {'label': T('Age'),
'class': '',
'content': lambda row, rc: round(row.hardware.age, 1),
'selected': False,
'width': ''}
# render the table
table = SQLTABLE(rows,
columns=['hardware.model',
'people.last_name'],
headers={'hardware.model': T('Model'),
'people.last_name': T('Name')},
extracolumns=[],
extracolumns=[
age
],
renderstyle=True)
response.write(CENTER(table))
...
...
views/list/people.html
View file @
37cdbc5f
...
...
@@ -10,12 +10,12 @@
'selected': False,
'width': ''}
#
add a
column
s
with the
virtual field time_weight
time_
weight
= {'label': T('Coverage'),
'class': '',
'content': lambda row, rc: row.history.time_coverage,
'selected': False,
'width': ''}
# column with the
period coverage
time_
coverage
= {'label': T('Coverage'),
'class': '',
'content': lambda row, rc: row.history.time_coverage,
'selected': False,
'width': ''}
# render the table
table = SQLTABLE(rows,
...
...
@@ -25,7 +25,7 @@
headers={'categories.usual': T('Category'),
'people.last_name': T('Name'),
'categories.code': T('Level')},
extracolumns=[cdd, time_
weight
],
extracolumns=[cdd, time_
coverage
],
renderstyle=True)
response.write(CENTER(table))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment