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

Limit period selector to year.

parent 30cda435
......@@ -3,8 +3,8 @@
"""
virtdb.define_table('graph_selector',
Field('period_start', 'date', default='2012-01-01'),
Field('period_end', 'date', default='%s-12-31' % year),
Field('year_start', 'integer', default=year),
Field('year_end', 'integer'),
Field('id_teams', 'reference teams', label=T('Team')),
Field('category', 'string'),
Field('id_people_categories', 'reference people_categories', label= T("Quality")),
......@@ -25,9 +25,9 @@ virtdb.graph_selector.metric.requires = IS_IN_SET(('count', 'sum_fte'))
#
#-------------------------------------------------------------------------------
fieldsModifier = dbui.FieldsModifier('graph_selector')
fieldsModifier.configure_field('period_start', flex=1)
fieldsModifier.configure_field('period_end', flex=1)
fieldsModifier.merge_fields('period_start', 'period_end', fieldLabel=T('Period'))
fieldsModifier.configure_field('year_start', flex=1)
fieldsModifier.configure_field('year_end', flex=1)
fieldsModifier.merge_fields('year_start', 'year_end', fieldLabel=T('Period'))
mytype = 'xcomboboxuserreset'
text = T('select...')
......
......@@ -3,12 +3,11 @@
"""
virtdb.define_table('list_selector',
Field('year', 'integer', default=year),
Field('year_start', 'integer', default=year),
Field('year_end', 'integer'),
Field('id_teams', 'reference teams', label=T('Team')),
Field('category', 'string'),
Field('id_people_categories', 'reference people_categories', label= T("Quality")),
Field('period_start', 'date'),
Field('period_end', 'date'),
Field('id_people', 'reference people', label=T('Person')),
Field('id_projects', 'reference projects', label=T('Project')),
Field('id_fundings', 'reference fundinds', label=T('Agency')),
......@@ -29,9 +28,9 @@ virtdb.list_selector.id_teams.requires = IS_IN_DB(db, 'teams.team')
#
#-------------------------------------------------------------------------------
fieldsModifier = dbui.FieldsModifier('list_selector')
fieldsModifier.configure_field('period_start', flex=1)
fieldsModifier.configure_field('period_end', flex=1)
fieldsModifier.merge_fields('period_start', 'period_end', fieldLabel=T('Period'))
fieldsModifier.configure_field('year_start', flex=1)
fieldsModifier.configure_field('year_end', flex=1)
fieldsModifier.merge_fields('year_start', 'year_end', fieldLabel=T('Period'))
mytype = 'xcomboboxuserreset'
text = T('select...')
......
......@@ -3,12 +3,11 @@
"""
virtdb.define_table('metric_selector_1D',
Field('year', 'integer', default=year),
Field('year_start', 'integer', default=year),
Field('year_end', 'integer'),
Field('id_teams', 'reference teams', label=T('Team')),
Field('category', 'string'),
Field('id_people_categories', 'reference people_categories', label= T("Quality")),
Field('period_start', 'date'),
Field('period_end', 'date'),
Field('id_projects', 'reference projects', label=T('Project')))
virtdb.metric_selector_1D.category.requires = IS_IN_SET(PEOPLE_CATEGORIES)
......@@ -23,9 +22,9 @@ virtdb.metric_selector_1D.id_teams.requires = IS_IN_DB(db, 'teams.team')
#
#-------------------------------------------------------------------------------
fieldsModifier = dbui.FieldsModifier('metric_selector_1D')
fieldsModifier.configure_field('period_start', flex=1)
fieldsModifier.configure_field('period_end', flex=1)
fieldsModifier.merge_fields('period_start', 'period_end', fieldLabel=T('Period'))
fieldsModifier.configure_field('year_start', flex=1)
fieldsModifier.configure_field('year_end', flex=1)
fieldsModifier.merge_fields('year_start', 'year_end', fieldLabel=T('Period'))
mytype = 'xcomboboxuserreset'
text = T('select...')
......
......@@ -3,9 +3,8 @@
"""
virtdb.define_table('metric_selector_2D',
Field('year', 'integer'),
Field('period_start', 'date'),
Field('period_end', 'date'),
Field('year_start', 'integer', default=year),
Field('year_end', 'integer'),
Field('id_teams', 'reference teams', label=T('Team')),
Field('category', 'string'),
Field('id_people_categories', 'reference people_categories', label= T("Quality")),
......@@ -26,9 +25,9 @@ virtdb.metric_selector_2D.metric.requires = IS_IN_SET(('count', 'sum_fte'))
#
#-------------------------------------------------------------------------------
fieldsModifier = dbui.FieldsModifier('metric_selector_2D')
fieldsModifier.configure_field('period_start', flex=1)
fieldsModifier.configure_field('period_end', flex=1)
fieldsModifier.merge_fields('period_start', 'period_end', fieldLabel=T('Period'))
fieldsModifier.configure_field('year_start', flex=1)
fieldsModifier.configure_field('year_end', flex=1)
fieldsModifier.merge_fields('year_start', 'year_end', fieldLabel=T('Period'))
mytype = 'xcomboboxuserreset'
text = T('select...')
......
......@@ -7,6 +7,9 @@ from gluon.dal import Field
from plugin_dbui import Selector
class SelectorActiveItemsException(BaseException): pass
class SelectorActiveItems(Selector):
"""Selector to get records active during a given period of time.
......@@ -14,11 +17,7 @@ class SelectorActiveItems(Selector):
C{_period_start} and C{_period_end} as well as C{_year}.
"""
def __init__(self,
table,
exclude_fields=('period_end',
'period_start',
'year')):
def __init__(self, table, exclude_fields=('year_end', 'year_start')):
"""
@type table: gluon.dal.Table
@param table: the virtual table defining the selector.
......@@ -30,17 +29,21 @@ class SelectorActiveItems(Selector):
"""
self._cache_period = None
self.periode_end = None
self.period_start = None
self.year = None
self._period_end = None
self._period_start = None
Selector.__init__(self,
table,
exclude_fields=exclude_fields)
Selector.__init__(self, table, exclude_fields=exclude_fields)
if self.year:
self.period_start = date(self.year, 1, 1)
self.period_end = date(self.year, 12, 31)
if self.year_start and not self.year_end:
self._period_start = date(self.year_start, 1, 1)
self._period_end = date(self.year_start, 12, 31)
elif self.year_start and self.year_end:
self._period_start = date(self.year_start, 1, 1)
self._period_end = date(self.year_end, 12, 31)
else:
raise SelectorActiveItemsException("Period is not defined.")
def get_years(self):
......@@ -53,8 +56,8 @@ class SelectorActiveItems(Selector):
start, end = self._cache_period
else:
start = self.period_start.year
end = self.period_end.year
start = self._period_start.year
end = self._period_end.year
return range(start, end + 1)
......@@ -76,9 +79,9 @@ class SelectorActiveItems(Selector):
"""
query = Selector.query(self, table)
if self.period_start and self.period_end:
q = table.start_date <= self.period_end
q = (q) & ((table.end_date == None) | (table.end_date >= self.period_start))
if self._period_start and self._period_end:
q = table.start_date <= self._period_end
q = (q) & ((table.end_date == None) | (table.end_date >= self._period_start))
query = (query) & (q)
return query
......@@ -88,8 +91,8 @@ class SelectorActiveItems(Selector):
"""Reset the period to the initial values.
"""
if self._cahche_period:
self.period_start, self.period_end = self._cahche_period
if self._cache_period:
self._period_start, self._period_end = self._cache_period
self._cache_period = None
......@@ -103,10 +106,10 @@ class SelectorActiveItems(Selector):
"""
# keep original period
if self._cache_period == None:
self._cache_period = (self.period_start, self.period_end)
self._cache_period = (self._period_start, self._period_end)
self.period_start = date(year, 1, 1)
self.period_end = date(year, 12, 31)
self._period_start = date(year, 1, 1)
self._period_end = date(year, 12, 31)
class MySelector(SelectorActiveItems):
......@@ -131,7 +134,7 @@ class MySelector(SelectorActiveItems):
and year are systematically excluded.
"""
li = ['category', 'period_end', 'period_start', 'year']
li = ['category', 'year_end', 'year_start']
li.extend(exclude_fields)
SelectorActiveItems.__init__(self, table, exclude_fields=li)
......
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