Fix regular expressions in sidebar filters

svn: r22968
This commit is contained in:
Nick Hall 2013-08-30 20:34:20 +00:00
parent 4ad659b083
commit b4d924f996
9 changed files with 44 additions and 115 deletions

View File

@ -47,9 +47,8 @@ from .. import build_filter_model
from . import SidebarFilter from . import SidebarFilter
from gramps.gen.constfunc import cuni from gramps.gen.constfunc import cuni
from gramps.gen.filters import GenericFilterFactory, rules from gramps.gen.filters import GenericFilterFactory, rules
from gramps.gen.filters.rules.citation import (RegExpIdOf, HasIdOf, HasCitation, from gramps.gen.filters.rules.citation import (RegExpIdOf, HasCitation, HasTag,
HasNoteMatchingSubstringOf, HasNoteRegexp, MatchesFilter)
HasNoteRegexp, MatchesFilter, HasTag)
from gramps.gen.utils.string import confidence from gramps.gen.utils.string import confidence
GenericCitationFilter = GenericFilterFactory('Citation') GenericCitationFilter = GenericFilterFactory('Citation')
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -143,20 +142,14 @@ class CitationSidebarFilter(SidebarFilter):
else: else:
generic_filter = GenericCitationFilter() generic_filter = GenericCitationFilter()
if gid: if gid:
if regex: rule = RegExpIdOf([gid], use_regex=regex)
rule = RegExpIdOf([gid])
else:
rule = HasIdOf([gid])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
rule = HasCitation([page, date, conf], use_regex=regex) rule = HasCitation([page, date, conf], use_regex=regex)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if note: if note:
if regex: rule = HasNoteRegexp([note], use_regex=regex)
rule = HasNoteRegexp([note])
else:
rule = HasNoteMatchingSubstringOf([note])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
# check the Tag # check the Tag

View File

@ -46,9 +46,8 @@ from .. import build_filter_model
from . import SidebarFilter from . import SidebarFilter
from gramps.gen.constfunc import cuni from gramps.gen.constfunc import cuni
from gramps.gen.filters import GenericFilterFactory, rules from gramps.gen.filters import GenericFilterFactory, rules
from gramps.gen.filters.rules.event import (RegExpIdOf, HasIdOf, HasNoteRegexp, from gramps.gen.filters.rules.event import (RegExpIdOf, HasNoteRegexp,
HasNoteMatchingSubstringOf, MatchesFilter, MatchesFilter, HasEvent, HasTag)
HasEvent, HasTag)
GenericEventFilter = GenericFilterFactory('Event') GenericEventFilter = GenericFilterFactory('Event')
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -140,10 +139,7 @@ class EventSidebarFilter(SidebarFilter):
else: else:
generic_filter = GenericEventFilter() generic_filter = GenericEventFilter()
if gid: if gid:
if regex: rule = RegExpIdOf([gid], use_regex=regex)
rule = RegExpIdOf([gid])
else:
rule = HasIdOf([gid])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
rule = HasEvent([etype, date, place, desc, mainparts], rule = HasEvent([etype, date, place, desc, mainparts],
@ -151,10 +147,7 @@ class EventSidebarFilter(SidebarFilter):
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if note: if note:
if regex: rule = HasNoteRegexp([note], use_regex=regex)
rule = HasNoteRegexp([note])
else:
rule = HasNoteMatchingSubstringOf([note])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
# check the Tag # check the Tag

View File

@ -47,12 +47,10 @@ from .. import build_filter_model
from . import SidebarFilter from . import SidebarFilter
from gramps.gen.constfunc import cuni from gramps.gen.constfunc import cuni
from gramps.gen.filters import GenericFilterFactory, rules from gramps.gen.filters import GenericFilterFactory, rules
from gramps.gen.filters.rules.family import (RegExpIdOf, HasIdOf, RegExpFatherName, from gramps.gen.filters.rules.family import (RegExpIdOf, RegExpFatherName,
SearchFatherName, RegExpMotherName, RegExpMotherName, RegExpChildName,
SearchMotherName, RegExpChildName, HasEvent, HasRelType, HasTag,
SearchChildName, HasEvent, HasRelType, HasNoteRegexp, MatchesFilter)
HasTag, HasNoteRegexp,
HasNoteMatchingSubstringOf, MatchesFilter)
GenericFamilyFilter = GenericFilterFactory('Family') GenericFamilyFilter = GenericFilterFactory('Family')
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -154,31 +152,19 @@ class FamilySidebarFilter(SidebarFilter):
else: else:
generic_filter = GenericFamilyFilter() generic_filter = GenericFamilyFilter()
if gid: if gid:
if regex: rule = RegExpIdOf([gid], use_regex=regex)
rule = RegExpIdOf([gid])
else:
rule = HasIdOf([gid])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if father: if father:
if regex: rule = RegExpFatherName([father], use_regex=regex)
rule = RegExpFatherName([father])
else:
rule = SearchFatherName([father])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if mother: if mother:
if regex: rule = RegExpMotherName([mother], use_regex=regex)
rule = RegExpMotherName([mother])
else:
rule = SearchMotherName([mother])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if child: if child:
if regex: rule = RegExpChildName([child], use_regex=regex)
rule = RegExpChildName([child])
else:
rule = SearchChildName([child])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if etype: if etype:
@ -190,10 +176,7 @@ class FamilySidebarFilter(SidebarFilter):
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if note: if note:
if regex: rule = HasNoteRegexp([note], use_regex=regex)
rule = HasNoteRegexp([note])
else:
rule = HasNoteMatchingSubstringOf([note])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
# check the Tag # check the Tag

View File

@ -46,9 +46,8 @@ from .. import build_filter_model
from . import SidebarFilter from . import SidebarFilter
from gramps.gen.constfunc import cuni from gramps.gen.constfunc import cuni
from gramps.gen.filters import GenericFilterFactory, rules from gramps.gen.filters import GenericFilterFactory, rules
from gramps.gen.filters.rules.media import (RegExpIdOf, HasIdOf, HasMedia, HasTag, from gramps.gen.filters.rules.media import (RegExpIdOf, HasMedia, HasTag,
HasNoteRegexp, MatchesFilter, HasNoteRegexp, MatchesFilter)
HasNoteMatchingSubstringOf)
GenericMediaFilter = GenericFilterFactory('Media') GenericMediaFilter = GenericFilterFactory('Media')
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -126,20 +125,14 @@ class MediaSidebarFilter(SidebarFilter):
else: else:
generic_filter = GenericMediaFilter() generic_filter = GenericMediaFilter()
if gid: if gid:
if regex: rule = RegExpIdOf([gid], use_regex=regex)
rule = RegExpIdOf([gid])
else:
rule = HasIdOf([gid])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
rule = HasMedia([title, mime, path, date], use_regex=regex) rule = HasMedia([title, mime, path, date], use_regex=regex)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if note: if note:
if regex: rule = HasNoteRegexp([note], use_regex=regex)
rule = HasNoteRegexp([note])
else:
rule = HasNoteMatchingSubstringOf([note])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
# check the Tag # check the Tag

View File

@ -47,8 +47,8 @@ from .. import build_filter_model
from . import SidebarFilter from . import SidebarFilter
from gramps.gen.constfunc import cuni from gramps.gen.constfunc import cuni
from gramps.gen.filters import GenericFilterFactory, rules from gramps.gen.filters import GenericFilterFactory, rules
from gramps.gen.filters.rules.note import (RegExpIdOf, HasIdOf, HasNote, from gramps.gen.filters.rules.note import (RegExpIdOf, HasNote, MatchesFilter,
MatchesFilter, HasTag) HasTag)
GenericNoteFilter = GenericFilterFactory('Note') GenericNoteFilter = GenericFilterFactory('Note')
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -122,10 +122,7 @@ class NoteSidebarFilter(SidebarFilter):
else: else:
generic_filter = GenericNoteFilter() generic_filter = GenericNoteFilter()
if gid: if gid:
if regex: rule = RegExpIdOf([gid], use_regex=regex)
rule = RegExpIdOf([gid])
else:
rule = HasIdOf([gid])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
rule = HasNote([text, ntype], use_regex=regex) rule = HasNote([text, ntype], use_regex=regex)

View File

@ -48,11 +48,11 @@ from .. import build_filter_model
from . import SidebarFilter from . import SidebarFilter
from gramps.gen.constfunc import cuni from gramps.gen.constfunc import cuni
from gramps.gen.filters import GenericFilter, rules from gramps.gen.filters import GenericFilter, rules
from gramps.gen.filters.rules.person import (RegExpName, SearchName, RegExpIdOf, from gramps.gen.filters.rules.person import (RegExpName, RegExpIdOf, IsMale,
MatchIdOf, IsMale, IsFemale, IsFemale, HasUnknownGender,
HasUnknownGender, HasEvent, HasTag, HasEvent, HasTag, HasBirth,
HasBirth, HasDeath, HasNoteRegexp, HasDeath, HasNoteRegexp,
HasNoteMatchingSubstringOf, MatchesFilter) MatchesFilter)
def extract_text(entry_widget): def extract_text(entry_widget):
""" """
@ -184,19 +184,13 @@ class PersonSidebarFilter(SidebarFilter):
# if the name is not empty, choose either the regular expression # if the name is not empty, choose either the regular expression
# version or the normal text match # version or the normal text match
if name: if name:
if regex: rule = RegExpName([name], use_regex=regex)
rule = RegExpName([name])
else:
rule = SearchName([name])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
# if the id is not empty, choose either the regular expression # if the id is not empty, choose either the regular expression
# version or the normal text match # version or the normal text match
if gid: if gid:
if regex: rule = RegExpIdOf([gid], use_regex=regex)
rule = RegExpIdOf([gid])
else:
rule = MatchIdOf([gid])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
# check the gender, and select the right rule based on gender # check the gender, and select the right rule based on gender
@ -228,10 +222,7 @@ class PersonSidebarFilter(SidebarFilter):
# Build note filter if needed # Build note filter if needed
if note: if note:
if regex: rule = HasNoteRegexp([note], use_regex=regex)
rule = HasNoteRegexp([note])
else:
rule = HasNoteMatchingSubstringOf([note])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
# check the Tag # check the Tag

View File

@ -47,9 +47,8 @@ from .. import build_filter_model
from . import SidebarFilter from . import SidebarFilter
from gramps.gen.constfunc import cuni from gramps.gen.constfunc import cuni
from gramps.gen.filters import GenericFilterFactory, rules from gramps.gen.filters import GenericFilterFactory, rules
from gramps.gen.filters.rules.place import (RegExpIdOf, HasIdOf, HasPlace, from gramps.gen.filters.rules.place import (RegExpIdOf, HasPlace, HasTag,
HasNoteRegexp, HasNoteMatchingSubstringOf, HasNoteRegexp, MatchesFilter)
MatchesFilter, HasTag)
GenericPlaceFilter = GenericFilterFactory('Place') GenericPlaceFilter = GenericFilterFactory('Place')
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -148,10 +147,7 @@ class PlaceSidebarFilter(SidebarFilter):
else: else:
generic_filter = GenericPlaceFilter() generic_filter = GenericPlaceFilter()
if gid: if gid:
if regex: rule = RegExpIdOf([gid], use_regex=regex)
rule = RegExpIdOf([gid])
else:
rule = HasIdOf([gid])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
rule = HasPlace([title, street, locality, city, county, state, rule = HasPlace([title, street, locality, city, county, state,
@ -159,10 +155,7 @@ class PlaceSidebarFilter(SidebarFilter):
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if note: if note:
if regex: rule = HasNoteRegexp([note], use_regex=regex)
rule = HasNoteRegexp([note])
else:
rule = HasNoteMatchingSubstringOf([note])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
# check the Tag # check the Tag

View File

@ -46,9 +46,8 @@ from .. import build_filter_model
from . import SidebarFilter from . import SidebarFilter
from gramps.gen.constfunc import cuni from gramps.gen.constfunc import cuni
from gramps.gen.filters import GenericFilterFactory, rules from gramps.gen.filters import GenericFilterFactory, rules
from gramps.gen.filters.rules.repository import (RegExpIdOf, HasIdOf, HasRepo, from gramps.gen.filters.rules.repository import (RegExpIdOf, HasRepo, HasTag,
HasNoteRegexp, MatchesFilter, HasNoteRegexp, MatchesFilter)
HasNoteMatchingSubstringOf, HasTag)
GenericRepoFilter = GenericFilterFactory('Repository') GenericRepoFilter = GenericFilterFactory('Repository')
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -136,20 +135,14 @@ class RepoSidebarFilter(SidebarFilter):
else: else:
generic_filter = GenericRepoFilter() generic_filter = GenericRepoFilter()
if gid: if gid:
if regex: rule = RegExpIdOf([gid], use_regex=regex)
rule = RegExpIdOf([gid])
else:
rule = HasIdOf([gid])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
rule = HasRepo([title, rtype, address, url], use_regex=regex) rule = HasRepo([title, rtype, address, url], use_regex=regex)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if note: if note:
if regex: rule = HasNoteRegexp([note], use_regex=regex)
rule = HasNoteRegexp([note])
else:
rule = HasNoteMatchingSubstringOf([note])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
# check the Tag # check the Tag

View File

@ -45,9 +45,8 @@ from .. import build_filter_model
from . import SidebarFilter from . import SidebarFilter
from gramps.gen.constfunc import cuni from gramps.gen.constfunc import cuni
from gramps.gen.filters import GenericFilterFactory, rules from gramps.gen.filters import GenericFilterFactory, rules
from gramps.gen.filters.rules.source import (RegExpIdOf, HasIdOf, HasSource, from gramps.gen.filters.rules.source import (RegExpIdOf, HasSource, HasTag,
HasNoteMatchingSubstringOf, HasNoteRegexp, MatchesFilter)
HasNoteRegexp, MatchesFilter, HasTag)
GenericSourceFilter = GenericFilterFactory('Source') GenericSourceFilter = GenericFilterFactory('Source')
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -125,20 +124,14 @@ class SourceSidebarFilter(SidebarFilter):
else: else:
generic_filter = GenericSourceFilter() generic_filter = GenericSourceFilter()
if gid: if gid:
if regex: rule = RegExpIdOf([gid], use_regex=regex)
rule = RegExpIdOf([gid])
else:
rule = HasIdOf([gid])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
rule = HasSource([title, author, abbr, pub], use_regex=regex) rule = HasSource([title, author, abbr, pub], use_regex=regex)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if note: if note:
if regex: rule = HasNoteRegexp([note], use_regex=regex)
rule = HasNoteRegexp([note])
else:
rule = HasNoteMatchingSubstringOf([note])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
# check the Tag # check the Tag