mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Column coloring/icons: Add more conditions when using date based columns with reference to 'today'.
This commit is contained in:
commit
3a675d9e42
@ -56,7 +56,12 @@ class ConditionEditor(QWidget): # {{{
|
||||
(_('is equal to'), 'eq'),
|
||||
(_('is less than'), 'lt'),
|
||||
(_('is greater than'), 'gt'),
|
||||
(_('is not more days ago than'), 'count_days')
|
||||
(_('is set'), 'is set'),
|
||||
(_('is not set'), 'is not set'),
|
||||
(_('is more days ago than'), 'older count days'),
|
||||
(_('is fewer days ago than'), 'count_days'),
|
||||
(_('is more days from now than'), 'newer future days'),
|
||||
(_('is fewer days from now than'), 'older future days')
|
||||
),
|
||||
'multiple' : (
|
||||
(_('has'), 'has'),
|
||||
@ -127,7 +132,7 @@ class ConditionEditor(QWidget): # {{{
|
||||
|
||||
for b in (self.column_box, self.action_box):
|
||||
b.setSizeAdjustPolicy(b.AdjustToMinimumContentsLengthWithIcon)
|
||||
b.setMinimumContentsLength(15)
|
||||
b.setMinimumContentsLength(20)
|
||||
|
||||
@dynamic_property
|
||||
def current_col(self):
|
||||
@ -240,7 +245,20 @@ class ConditionEditor(QWidget): # {{{
|
||||
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. Zero is today')
|
||||
tt = _('Enter the maximum days old the item can be. Zero is today. '
|
||||
'Dates in the future always match')
|
||||
elif action == 'older count days':
|
||||
self.value_box.setValidator(QIntValidator(self.value_box))
|
||||
tt = _('Enter the minimum days old the item can be. Zero is today. '
|
||||
'Dates in the future never match')
|
||||
elif action == 'older future days':
|
||||
self.value_box.setValidator(QIntValidator(self.value_box))
|
||||
tt = _('Enter the maximum days in the future the item can be. '
|
||||
'Zero is today. Dates in the past always match')
|
||||
elif action == 'newer future days':
|
||||
self.value_box.setValidator(QIntValidator(self.value_box))
|
||||
tt = _('Enter the mimimum days in the future the item can be. '
|
||||
'Zero is today. Dates in the past never match')
|
||||
else:
|
||||
self.value_box.setInputMask('9999-99-99')
|
||||
tt = _('Enter a date in the format YYYY-MM-DD')
|
||||
@ -640,14 +658,32 @@ class RulesModel(QAbstractListModel): # {{{
|
||||
''') % dict(kind=trans_kind, col=col, color=rule.color, rule=''.join(conditions))
|
||||
|
||||
def condition_to_html(self, condition):
|
||||
c, a, v = condition
|
||||
c = self.fm[c]['name']
|
||||
col, a, v = condition
|
||||
dt = self.fm[col]['datatype']
|
||||
c = self.fm[col]['name']
|
||||
action_name = a
|
||||
for actions in ConditionEditor.ACTION_MAP.itervalues():
|
||||
for trans, ac in actions:
|
||||
if col in ConditionEditor.ACTION_MAP:
|
||||
# look for a column-name-specific label
|
||||
for trans, ac in ConditionEditor.ACTION_MAP[col]:
|
||||
if ac == a:
|
||||
action_name = trans
|
||||
|
||||
break
|
||||
elif dt in ConditionEditor.ACTION_MAP:
|
||||
# Look for a type-specific label
|
||||
for trans, ac in ConditionEditor.ACTION_MAP[dt]:
|
||||
if ac == a:
|
||||
action_name = trans
|
||||
break
|
||||
else:
|
||||
# Wasn't a type-specific or column-specific label. Look for a text-type
|
||||
for dt in ['single', 'multiple']:
|
||||
for trans, ac in ConditionEditor.ACTION_MAP[dt]:
|
||||
if ac == a:
|
||||
action_name = trans
|
||||
break
|
||||
else:
|
||||
continue
|
||||
break
|
||||
return (
|
||||
_('<li>If the <b>%(col)s</b> column <b>%(action)s</b> value: <b>%(val)s</b>') %
|
||||
dict(col=c, action=action_name, val=prepare_string_for_xml(v)))
|
||||
|
@ -134,8 +134,29 @@ class Rule(object): # {{{
|
||||
|
||||
def date_condition(self, col, action, val):
|
||||
if action == 'count_days':
|
||||
return (("test(field('%s'), cmp(%s, days_between(today(), format_date(raw_field('%s'), 'yyyy-MM-dd')), '', '1', '1'), '')")
|
||||
%(col, str(int(val)+1), col))
|
||||
return (("test(field('%s'), cmp(%s, "
|
||||
"days_between(format_date(today(), 'yyyy-MM-dd'),"
|
||||
"format_date(raw_field('%s'), 'yyyy-MM-dd')), '', '1', '1'), '')")
|
||||
%(col, val, col))
|
||||
if action == 'older count days':
|
||||
return (("test(field('%s'), cmp(%s, "
|
||||
"days_between(format_date(today(), 'yyyy-MM-dd'),"
|
||||
"format_date(raw_field('%s'), 'yyyy-MM-dd')), '1', '', ''), '')")
|
||||
%(col, val, col))
|
||||
if action == 'older future days':
|
||||
return (("test(field('%s'), cmp(%s, "
|
||||
"days_between(format_date(raw_field('%s'), 'yyyy-MM-dd'), "
|
||||
"format_date(today(), 'yyyy-MM-dd')), '', '1', '1'), '')")
|
||||
%(col, val, col))
|
||||
if action == 'newer future days':
|
||||
return (("test(field('%s'), cmp(%s, "
|
||||
"days_between(format_date(raw_field('%s'), 'yyyy-MM-dd'), "
|
||||
"format_date(today(), 'yyyy-MM-dd')), '1', '', ''), '')")
|
||||
%(col, val, col))
|
||||
if action == 'is set':
|
||||
return (("test(field('%s'), '1', '')"%(col)))
|
||||
if action == 'is not set':
|
||||
return (("test(field('%s'), '', '1')"%(col)))
|
||||
lt, eq, gt = {
|
||||
'eq': ('', '1', ''),
|
||||
'lt': ('1', '', ''),
|
||||
|
Loading…
x
Reference in New Issue
Block a user