From 542bbd940452d69d7290dc76dfbd9532563d9282 Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Wed, 20 Jun 2007 01:44:26 +0000 Subject: [PATCH] 2007-06-19 Alex Roitman * src/FilterEditor/_FilterEditor.py (_find_dependent_filters): Add method to first find all filters fo deletion. svn: r8603 --- ChangeLog | 4 ++++ src/FilterEditor/_FilterEditor.py | 30 +++++++++++++++++++----------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5dc10fac7..7393559cf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2007-06-19 Alex Roitman + * src/FilterEditor/_FilterEditor.py (_find_dependent_filters): + Add method to first find all filters fo deletion. + 2007-06-19 Alex Roitman * src/FilterEditor/_FilterEditor.py (_do_delete_filter): Use a copy for iteration over the filters. diff --git a/src/FilterEditor/_FilterEditor.py b/src/FilterEditor/_FilterEditor.py index 4e40e69f6..e653eefe1 100644 --- a/src/FilterEditor/_FilterEditor.py +++ b/src/FilterEditor/_FilterEditor.py @@ -206,26 +206,34 @@ class FilterEditor(ManagedWindow.ManagedWindow): self.draw_filters() def _do_delete_filter(self,space,gfilter): + # Find everything we need to remove + filter_set = set() + self._find_dependent_filters(space,gfilter,filter_set) + + # 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 delete all dependent filters - before removing this filter. Otherwise when A is 'matches B' - and C is 'matches D' the removal of D leads to two broken filter - being left behind. + 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. """ - # 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)[:] - + filters = self.filterdb.get_filters(space) name = gfilter.get_name() for the_filter in filters: for rule in the_filter.get_rules(): values = rule.values() if issubclass(rule.__class__,MatchesFilterBase) \ and (name in values): - self._do_delete_filter(space,the_filter) + self._find_dependent_filters(space,the_filter,filter_set) break - # The actual removal is from the real filter list, not a copy. - self.filterdb.get_filters(space).remove(gfilter) + # Add itself to the filter_set + filter_set.add(gfilter) def get_all_handles(self): if self.space == 'Person':