Catch loops in filters

svn: r1583
This commit is contained in:
Don Allingham 2003-05-23 04:08:03 +00:00
parent 11faa9beda
commit 8e21af4a49
16 changed files with 105 additions and 10 deletions

View File

@ -18,6 +18,19 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
class FilterError(Exception):
"""Error used to report Filter errors"""
def __init__(self,value,value2=""):
Exception.__init__(self)
self.value = value
self.value2 = value2
def __str__(self):
return self.value
def messages(self):
return (self.value,self.value2)
class DateError(Exception):
"""Error used to report Date errors"""
def __init__(self,value=""):

View File

@ -51,6 +51,7 @@ import const
import RelLib
import Date
import Calendar
import Errors
from intl import gettext as _
from Utils import for_each_ancestor
@ -170,9 +171,19 @@ class IsDescendantOf(Rule):
return 'Is a descendant of'
def apply(self,db,p):
self.map = {}
self.orig = p
return self.search(p)
def search(self,p):
if self.map.has_key(p.getId()) == 1:
raise Errors.FilterError(_("Loop detected while applying filter"),
_("A relationship loop was detected between %s [%s]"
"and %s [%s]. This is probably due to an error in the "
"database.") % (self.orig.getPrimaryName().getName(),
self.orig.getId(),
p.getPrimaryName().getName(),p.getId()))
self.map[p.getId()] = 1
if p.getId() == self.list[0]:
return 1
for (f,r1,r2) in p.getParentList():
@ -197,10 +208,20 @@ class IsDescendantFamilyOf(Rule):
return "Is a descendant family member of"
def apply(self,db,p):
self.map = {}
self.orig = p
return self.search(p,1)
def search(self,p,val):
if self.map.has_key(p.getId()):
Errors.FilterError(_("Loop detected while applying filter"),
_("A relationship loop was detected between %s [%s]"
"and %s [%s]. This is probably due to an error in the "
"database.") % (self.orig.getPrimaryName().getName(),
self.orig.getId(),
p.getPrimaryName().getName(),p.getId()))
if p.getId() == self.list[0]:
self.map[p.getId()] = 1
return 1
for (f,r1,r2) in p.getParentList():
for p1 in [f.getMother(),f.getFather()]:
@ -228,14 +249,28 @@ class IsAncestorOf(Rule):
"""Rule that checks for a person that is an ancestor of a specified person"""
labels = [ _('ID:') ]
def __init__(self,list):
Rule.__init__(self,list)
self.map = {}
def name(self):
return 'Is an ancestor of'
def apply(self,db,p):
self.orig = p
return self.search(p)
def search(self,p):
if self.map.has_key(p.getId()) == 1:
raise Errors.FilterError(_("Loop detected while applying filter"),
_("A relationship loop was detected between %s [%s]"
"and %s [%s]. This is probably due to an error in the "
"database.") % (self.orig.getPrimaryName().getName(),
self.orig.getId(),
p.getPrimaryName().getName(),p.getId()))
self.map[p.getId()] = 1
if p.getId() == self.list[0]:
return 1

View File

@ -956,6 +956,7 @@ class Gramps:
else:
GrampsCfg.save_last_file("")
self.topWindow.set_resizable(gtk.TRUE)
self.goto_active_person(1)
def cl_import(self,filename,format):
if format == 'gedcom':
@ -1368,9 +1369,12 @@ class Gramps:
def alpha_event(self,obj):
self.load_person(self.active_person)
def goto_active_person(self):
def goto_active_person(self,first=0):
if not self.active_person:
page = self.ptabs.get_current_page()
if first:
page = 0
else:
page = self.ptabs.get_current_page()
self.person_tree = self.pl_page[page]
self.person_list = self.pl_page[page].tree
self.person_model = self.pl_page[page].model

View File

@ -257,6 +257,9 @@ class AncestorChartDialog(Report.DrawReportDialog):
except Errors.ReportError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
except Errors.FilterError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
except:
import DisplayTrace
DisplayTrace.DisplayTrace()

View File

@ -273,6 +273,9 @@ class AncestorReportDialog(Report.TextReportDialog):
except Errors.ReportError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
except Errors.FilterError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
except:
import DisplayTrace
DisplayTrace.DisplayTrace()

View File

@ -346,6 +346,9 @@ class DescendantReportDialog(Report.DrawReportDialog):
except Errors.ReportError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
except Errors.FilterError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
except:
import DisplayTrace
DisplayTrace.DisplayTrace()

View File

@ -169,6 +169,9 @@ class DescendantReportDialog(Report.TextReportDialog):
except Errors.ReportError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
except Errors.FilterError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
except:
import DisplayTrace
DisplayTrace.DisplayTrace()

View File

@ -762,6 +762,9 @@ class DetAncestorReportDialog(TextReportDialog):
except Errors.ReportError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
except Errors.FilterError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
except:
import DisplayTrace
DisplayTrace.DisplayTrace()

View File

@ -451,6 +451,9 @@ class FamilyGroupDialog(Report.TextReportDialog):
except Errors.ReportError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
except Errors.FilterError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
except:
import DisplayTrace
DisplayTrace.DisplayTrace()

View File

@ -761,6 +761,9 @@ class FtmAncestorReportDialog(Report.TextReportDialog):
except Errors.ReportError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
except Errors.FilterError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
except:
import DisplayTrace
DisplayTrace.DisplayTrace()

View File

@ -1155,6 +1155,9 @@ class FtmDescendantReportDialog(Report.TextReportDialog):
except Errors.ReportError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
except Errors.FilterError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
except:
import DisplayTrace
DisplayTrace.DisplayTrace()

View File

@ -268,7 +268,11 @@ class GraphVizDialog(Report.ReportDialog):
file = open(self.target_path,"w")
ind_list = self.filter.apply(self.db, self.db.getPersonMap().values())
try:
ind_list = self.filter.apply(self.db, self.db.getPersonMap().values())
except Errors.FilterError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
write_dot(file, ind_list, self.orien, width, height,
self.tb_margin, self.lr_margin, self.hpages,

View File

@ -543,6 +543,9 @@ class IndivSummaryDialog(Report.TextReportDialog):
self.doc, self.filter, act)
MyReport.setup()
MyReport.write_report()
except Errors.FilterError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
except Errors.ReportError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)

View File

@ -383,6 +383,9 @@ class IndivSummaryDialog(Report.TextReportDialog):
MyReport = IndivSummary(self.db, self.person, self.target_path, self.doc)
MyReport.setup()
MyReport.write_report()
except Errors.FilterError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
except Errors.ReportError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)

View File

@ -409,6 +409,9 @@ class TimeLineDialog(Report.DrawReportDialog):
self.doc, self.filter, title, sort_func)
MyReport.setup()
MyReport.write_report()
except Errors.FilterError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
except Errors.ReportError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)

View File

@ -1145,13 +1145,19 @@ class WebReportDialog(Report.ReportDialog):
#------------------------------------------------------------------------
def make_report(self):
"""Create the object that will produce the web pages."""
MyReport = WebReport(self.db, self.person, self.target_path,
self.max_gen, self.photos, self.filter,
self.restrict, self.private, self.srccomments,
self.include_link, self.selected_style,
self.img_dir_text,self.template_name,
self.use_id,self.id_link,self.use_gendex,
self.html_ext)
try:
MyReport = WebReport(self.db, self.person, self.target_path,
self.max_gen, self.photos, self.filter,
self.restrict, self.private, self.srccomments,
self.include_link, self.selected_style,
self.img_dir_text,self.template_name,
self.use_id,self.id_link,self.use_gendex,
self.html_ext)
except Errors.FilterError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
MyReport.write_report()
#------------------------------------------------------------------------