diff --git a/src/calibre/gui2/dialogs/template_dialog.py b/src/calibre/gui2/dialogs/template_dialog.py index c51ead8373..fc8a528830 100644 --- a/src/calibre/gui2/dialogs/template_dialog.py +++ b/src/calibre/gui2/dialogs/template_dialog.py @@ -197,8 +197,7 @@ class TemplateHighlighter(QSyntaxHighlighter): class TemplateDialog(QDialog, Ui_TemplateDialog): - def __init__(self, parent, text, mi=None, fm=None, color_field=None, - rule_kind='color'): + def __init__(self, parent, text, mi=None, fm=None, color_field=None): QDialog.__init__(self, parent) Ui_TemplateDialog.__init__(self) self.setupUi(self) @@ -265,8 +264,7 @@ class TemplateDialog(QDialog, Ui_TemplateDialog): self.function.setCurrentIndex(0) self.function.currentIndexChanged[str].connect(self.function_changed) self.textbox_changed() - self.rule = (rule_kind, None, '') - self.rule_kind = rule_kind + self.rule = (None, '') tt = _('Template language tutorial') self.template_tutorial.setText( @@ -325,5 +323,5 @@ class TemplateDialog(QDialog, Ui_TemplateDialog): _('The template box cannot be empty'), show=True) return - self.rule = (self.rule_kind, unicode(self.colored_field.currentText()), txt) + self.rule = (unicode(self.colored_field.currentText()), txt) QDialog.accept(self) diff --git a/src/calibre/gui2/preferences/coloring.py b/src/calibre/gui2/preferences/coloring.py index b432cec70e..7dbf3ec082 100644 --- a/src/calibre/gui2/preferences/coloring.py +++ b/src/calibre/gui2/preferences/coloring.py @@ -742,7 +742,7 @@ class EditRules(QWidget): # {{{ def add_advanced(self): td = TemplateDialog(self, '', mi=self.mi, fm=self.fm, color_field='') - self._add_rule(td) + self._add_rule(('color', td[0], td[1])) def edit_rule(self, index): try: @@ -755,6 +755,8 @@ class EditRules(QWidget): # {{{ else: d = TemplateDialog(self, rule, mi=self.mi, fm=self.fm, color_field=col) if d.exec_() == d.Accepted: + if len(d.rule) == 2: # Convert template dialog rules to a triple + d.rule = ('color', d.rule[0], d.rule[1]) kind, col, r = d.rule if kind and r is not None and col: self.model.replace_rule(index, kind, col, r) diff --git a/src/calibre/library/coloring.py b/src/calibre/library/coloring.py index 807279a565..eae640174b 100644 --- a/src/calibre/library/coloring.py +++ b/src/calibre/library/coloring.py @@ -134,8 +134,8 @@ class Rule(object): # {{{ 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)) + 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)) lt, eq, gt = { 'eq': ('', '1', ''), 'lt': ('1', '', ''),