2007-06-19 Alex Roitman <shura@phy.ucsf.edu>

* src/FilterEditor/_FilterEditor.py (_find_dependent_filters):
	Add method to first find all filters fo deletion.



svn: r8603
This commit is contained in:
Alex Roitman 2007-06-20 01:44:26 +00:00
parent 8278778e65
commit 542bbd9404
2 changed files with 23 additions and 11 deletions

View File

@ -1,3 +1,7 @@
2007-06-19 Alex Roitman <shura@phy.ucsf.edu>
* src/FilterEditor/_FilterEditor.py (_find_dependent_filters):
Add method to first find all filters fo deletion.
2007-06-19 Alex Roitman <shura@gramps-project.org> 2007-06-19 Alex Roitman <shura@gramps-project.org>
* src/FilterEditor/_FilterEditor.py (_do_delete_filter): Use a * src/FilterEditor/_FilterEditor.py (_do_delete_filter): Use a
copy for iteration over the filters. copy for iteration over the filters.

View File

@ -206,26 +206,34 @@ class FilterEditor(ManagedWindow.ManagedWindow):
self.draw_filters() self.draw_filters()
def _do_delete_filter(self,space,gfilter): def _do_delete_filter(self,space,gfilter):
""" # Find everything we need to remove
This method recursively calls itself to delete all dependent filters filter_set = set()
before removing this filter. Otherwise when A is 'matches B' self._find_dependent_filters(space,gfilter,filter_set)
and C is 'matches D' the removal of D leads to two broken filter
being left behind.
"""
# Use the copy of the filter list to iterate over, so that
# the removal of filters does not screw up the iteration
filters = self.filterdb.get_filters(space)[:]
# Remove what we found
filters = self.filterdb.get_filters(space)
for the_filter in filter_set:
filters.remove(the_filter)
def _find_dependent_filters(self,space,gfilter,filter_set):
"""
This method recursively calls itself to find all filters that
depend on the given filter, either directly through one of the rules,
or through the chain of dependencies.
The filter_set is amended with the found filters.
"""
filters = self.filterdb.get_filters(space)
name = gfilter.get_name() name = gfilter.get_name()
for the_filter in filters: for the_filter in filters:
for rule in the_filter.get_rules(): for rule in the_filter.get_rules():
values = rule.values() values = rule.values()
if issubclass(rule.__class__,MatchesFilterBase) \ if issubclass(rule.__class__,MatchesFilterBase) \
and (name in values): and (name in values):
self._do_delete_filter(space,the_filter) self._find_dependent_filters(space,the_filter,filter_set)
break break
# The actual removal is from the real filter list, not a copy. # Add itself to the filter_set
self.filterdb.get_filters(space).remove(gfilter) filter_set.add(gfilter)
def get_all_handles(self): def get_all_handles(self):
if self.space == 'Person': if self.space == 'Person':