From d7282a8f006d49eccc97b97cceea298f504c60cf Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 31 Oct 2017 01:58:48 +0530 Subject: [PATCH] Column coloring: Add a contains rules type. Fixes #1728464 [Enhancement - allow character match in rules](https://bugs.launchpad.net/calibre/+bug/1728464) --- src/calibre/gui2/preferences/coloring.py | 2 ++ src/calibre/library/coloring.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/calibre/gui2/preferences/coloring.py b/src/calibre/gui2/preferences/coloring.py index 6ac9d9e743..3c9aefe452 100644 --- a/src/calibre/gui2/preferences/coloring.py +++ b/src/calibre/gui2/preferences/coloring.py @@ -79,6 +79,8 @@ class ConditionEditor(QWidget): # {{{ 'single' : ( (_('is'), 'is'), (_('is not'), 'is not'), + (_('contains'), 'contains'), + (_('does not contain'), 'does not contain'), (_('matches pattern'), 'matches pattern'), (_('does not match pattern'), 'does not match pattern'), (_('is set'), 'is set'), diff --git a/src/calibre/library/coloring.py b/src/calibre/library/coloring.py index b4ffad297e..7d1df7823b 100644 --- a/src/calibre/library/coloring.py +++ b/src/calibre/library/coloring.py @@ -199,6 +199,10 @@ class Rule(object): # {{{ return "contains(field('%s'), \"%s\", '1', '')"%(col, val) if action == 'does not match pattern': return "contains(field('%s'), \"%s\", '', '1')"%(col, val) + if action == 'contains': + return "contains(field('%s'), \"%s\", '1', '')"%(col, re.escape(val)) + if action == 'does not contain': + return "contains(field('%s'), \"%s\", '', '1')"%(col, re.escape(val)) # }}}