Column coloring: Add a contains rules type. Fixes #1728464 [Enhancement - allow character match in rules](https://bugs.launchpad.net/calibre/+bug/1728464)

This commit is contained in:
Kovid Goyal 2017-10-31 01:58:48 +05:30
parent e0128dd60d
commit d7282a8f00
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 6 additions and 0 deletions

View File

@ -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'),

View File

@ -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))
# }}}