Column coloring/icons: Add a 'days ago' condition, useable with clumns that store dates to set colors based on the number of days before today

This commit is contained in:
Kovid Goyal 2013-02-02 11:32:15 +05:30
commit e0e1bafbca
4 changed files with 21 additions and 7 deletions

View File

@ -133,7 +133,7 @@ class TagListEditor(QDialog, Ui_TagListEditor):
select_item = item select_item = item
item = CountTableWidgetItem(self.counts[tag]) item = CountTableWidgetItem(self.counts[tag])
# only the name column can be selected # only the name column can be selected
item.setFlags (item.flags() & ~Qt.ItemIsSelectable) item.setFlags (item.flags() & ~(Qt.ItemIsSelectable|Qt.ItemIsEditable))
self.table.setItem(row, 1, item) self.table.setItem(row, 1, item)
item = QTableWidgetItem('') item = QTableWidgetItem('')
item.setFlags (item.flags() & ~(Qt.ItemIsSelectable|Qt.ItemIsEditable)) item.setFlags (item.flags() & ~(Qt.ItemIsSelectable|Qt.ItemIsEditable))

View File

@ -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,6 +238,10 @@ 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':
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') self.value_box.setInputMask('9999-99-99')
tt = _('Enter a date in the format YYYY-MM-DD') tt = _('Enter a date in the format YYYY-MM-DD')
else: else:

View File

@ -549,7 +549,8 @@ class TagsView(QTreeView): # {{{
# Offer specific editors for tags/series/publishers/saved searches # Offer specific editors for tags/series/publishers/saved searches
self.context_menu.addSeparator() self.context_menu.addSeparator()
if key in ['tags', 'publisher', 'series'] or \ if key in ['tags', 'publisher', 'series'] or \
self.db.field_metadata[key]['is_custom']: (self.db.field_metadata[key]['is_custom'] and
self.db.field_metadata[key]['datatype'] != 'composite'):
self.context_menu.addAction(_('Manage %s')%category, self.context_menu.addAction(_('Manage %s')%category,
partial(self.context_menu_handler, action='open_editor', partial(self.context_menu_handler, action='open_editor',
category=tag.original_name if tag else None, category=tag.original_name if tag else None,

View File

@ -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 == '|':