From 167641654ce1859528cf9a3c2eb7948a7f0afa2d Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Wed, 20 Jun 2007 01:12:50 +0000 Subject: [PATCH] Update svn: r8598 --- ChangeLog | 4 ++++ src/FilterEditor/_FilterEditor.py | 30 +++++++++++++++++++----------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 915002758..02eedb186 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 3626ef494..56143b997 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 = self._find_dependen_filters(space,gfilter) + + # Get the list of current filters + filters = self.filterdb.get_filters(space) + + # Leave only those that are not in the removal set + filters = [the_filter in filters if the_filter not in filter_set] + + def _find_dependent_filters(self,space,gfilter,filter_set=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':