mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add a "days ago" condition to datetime columns when coloring
This commit is contained in:
parent
47b6b49ecc
commit
c8aebf3ca0
@ -52,6 +52,12 @@ class ConditionEditor(QWidget): # {{{
|
|||||||
(_('is less than'), 'lt'),
|
(_('is less than'), 'lt'),
|
||||||
(_('is greater than'), 'gt')
|
(_('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' : (
|
'multiple' : (
|
||||||
(_('has'), 'has'),
|
(_('has'), 'has'),
|
||||||
(_('does not have'), 'does not have'),
|
(_('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']
|
ACTION_MAP[x] = ACTION_MAP['int']
|
||||||
|
|
||||||
|
|
||||||
@ -232,8 +238,12 @@ class ConditionEditor(QWidget): # {{{
|
|||||||
v = QIntValidator if dt == 'int' else QDoubleValidator
|
v = QIntValidator if dt == 'int' else QDoubleValidator
|
||||||
self.value_box.setValidator(v(self.value_box))
|
self.value_box.setValidator(v(self.value_box))
|
||||||
elif dt == 'datetime':
|
elif dt == 'datetime':
|
||||||
self.value_box.setInputMask('9999-99-99')
|
if action == 'count_days':
|
||||||
tt = _('Enter a date in the format YYYY-MM-DD')
|
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:
|
else:
|
||||||
tt = _('Enter a string.')
|
tt = _('Enter a string.')
|
||||||
if 'pattern' in action:
|
if 'pattern' in action:
|
||||||
|
@ -133,13 +133,16 @@ class Rule(object): # {{{
|
|||||||
return "cmp(field('%s'), %s, '%s', '%s', '%s')" % (col, val, lt, eq, gt)
|
return "cmp(field('%s'), %s, '%s', '%s', '%s')" % (col, val, lt, eq, gt)
|
||||||
|
|
||||||
def date_condition(self, col, action, val):
|
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 = {
|
lt, eq, gt = {
|
||||||
'eq': ('', '1', ''),
|
'eq': ('', '1', ''),
|
||||||
'lt': ('1', '', ''),
|
'lt': ('1', '', ''),
|
||||||
'gt': ('', '', '1')
|
'gt': ('', '', '1')
|
||||||
}[action]
|
}[action]
|
||||||
return "strcmp(format_date(raw_field('%s'), 'yyyy-MM-dd'), '%s', '%s', '%s', '%s')" % (col,
|
return ("strcmp(format_date(raw_field('%s'), 'yyyy-MM-dd'), '%s', '%s', '%s', '%s')" %
|
||||||
val, lt, eq, gt)
|
(col, val, lt, eq, gt))
|
||||||
|
|
||||||
def multiple_condition(self, col, action, val, sep):
|
def multiple_condition(self, col, action, val, sep):
|
||||||
if not sep or sep == '|':
|
if not sep or sep == '|':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user