Add a "days ago" condition to datetime columns when coloring

This commit is contained in:
Charles Haley 2013-02-01 21:17:11 +01:00
parent 47b6b49ecc
commit c8aebf3ca0
2 changed files with 18 additions and 5 deletions

View File

@ -52,6 +52,12 @@ class ConditionEditor(QWidget): # {{{
(_('is less than'), 'lt'),
(_('is greater than'), 'gt')
),
'datetime' : (
(_('is equal to'), 'eq'),
(_('is less than'), 'lt'),
(_('is greater than'), 'gt'),
(_('is not more days ago than'), 'count_days')
),
'multiple' : (
(_('has'), 'has'),
(_('does not have'), 'does not have'),
@ -70,7 +76,7 @@ class ConditionEditor(QWidget): # {{{
),
}
for x in ('float', 'rating', 'datetime'):
for x in ('float', 'rating'):
ACTION_MAP[x] = ACTION_MAP['int']
@ -232,6 +238,10 @@ class ConditionEditor(QWidget): # {{{
v = QIntValidator if dt == 'int' else QDoubleValidator
self.value_box.setValidator(v(self.value_box))
elif dt == 'datetime':
if action == 'count_days':
self.value_box.setValidator(QIntValidator(self.value_box))
tt = _('Enter the number of days old the item can be')
else:
self.value_box.setInputMask('9999-99-99')
tt = _('Enter a date in the format YYYY-MM-DD')
else:

View File

@ -133,13 +133,16 @@ class Rule(object): # {{{
return "cmp(field('%s'), %s, '%s', '%s', '%s')" % (col, val, lt, eq, gt)
def date_condition(self, col, action, val):
if action == 'count_days':
return (("cmp(add(%s, 1), days_between(today(), format_date(raw_field('%s'), 'yyyy-MM-dd')), '', '1', '1')")
%(val, col))
lt, eq, gt = {
'eq': ('', '1', ''),
'lt': ('1', '', ''),
'gt': ('', '', '1')
}[action]
return "strcmp(format_date(raw_field('%s'), 'yyyy-MM-dd'), '%s', '%s', '%s', '%s')" % (col,
val, lt, eq, gt)
return ("strcmp(format_date(raw_field('%s'), 'yyyy-MM-dd'), '%s', '%s', '%s', '%s')" %
(col, val, lt, eq, gt))
def multiple_condition(self, col, action, val, sep):
if not sep or sep == '|':