From b147cb2ca329fb2eda24d0f929d9cf4700e20b92 Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Tue, 25 Jan 2011 12:43:09 +0000 Subject: [PATCH] 4383: Error while attempt to edit family 2521: Problem with erroneous birth date in using the family editor. We show validation error on date > next year, and don't crash on large year anymore svn: r16467 --- src/DateEdit.py | 5 ++++- src/gen/lib/date.py | 10 ++++++++++ src/gui/editors/displaytabs/childmodel.py | 22 +++++++++++++++++----- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/DateEdit.py b/src/DateEdit.py index 07d3fc6f9..d964530e4 100644 --- a/src/DateEdit.py +++ b/src/DateEdit.py @@ -62,7 +62,7 @@ import gtk # #------------------------------------------------------------------------- from gen.ggettext import sgettext as _ -from gen.lib import Date +from gen.lib.date import Date, NextYear import DateHandler import const import GrampsDisplay @@ -150,6 +150,9 @@ class DateEdit(object): # if text could not be parsed it is assumed invalid if self.date_obj.get_modifier() == Date.MOD_TEXTONLY: return ValidationError(_('Bad Date')) + elif (self.date_obj.to_calendar(calendar_name=Date.CAL_GREGORIAN) > + NextYear()): + return ValidationError(_('Date more than one year in the future')) def invoke_date_editor(self, obj): """ diff --git a/src/gen/lib/date.py b/src/gen/lib/date.py index f310c7999..f04d22585 100644 --- a/src/gen/lib/date.py +++ b/src/gen/lib/date.py @@ -1702,6 +1702,16 @@ def Today(): current_date.set_yr_mon_day(*time.localtime(time.time())[0:3]) return current_date +def NextYear(): + """ + Returns a Date object set to next year + """ + import time + next_year = Date() + thisyear = time.localtime(time.time()) + next_year.set_yr_mon_day(thisyear[0]+1, thisyear[1], thisyear[3]) + return next_year + #------------------------------------------------------------------------- # # Date Functions diff --git a/src/gui/editors/displaytabs/childmodel.py b/src/gui/editors/displaytabs/childmodel.py index 0731eb5f0..162f999fb 100644 --- a/src/gui/editors/displaytabs/childmodel.py +++ b/src/gui/editors/displaytabs/childmodel.py @@ -51,7 +51,7 @@ class ChildModel(gtk.ListStore): def __init__(self, family, db): self.family = family gtk.ListStore.__init__(self, int, str, str, str, str, str, - str, str, str, str, str, str, int, int) + str, str, str, str, str, str, str, str) self.db = db index = 1 for child_ref in self.get_data(): @@ -88,12 +88,18 @@ class ChildModel(gtk.ListStore): return u"" def column_birth_sort(self, data): + """ + Return a sort key to use for the birth column. + As python int can be larger than C int, we cast int + to a string of 12 long prepended with 0 as needed. + This gives correct string sort for years in the millenia around today + """ event_ref = data.get_birth_ref() if event_ref and event_ref.ref: event = self.db.get_event_from_handle(event_ref.ref) - return event.get_date_object().get_sort_value() + return '%012d' % event.get_date_object().get_sort_value() else: - return 0 + return '%012d' % 0 def column_death_day(self, data): event_ref = data.get_death_ref() @@ -104,12 +110,18 @@ class ChildModel(gtk.ListStore): return u"" def column_death_sort(self, data): + """ + Return a sort key to use for the death column. + As python int can be larger than C int, we cast int + to a string of 12 long prepended with 0 as needed. + This gives correct string sort for years in the millenia around today + """ event_ref = data.get_death_ref() if event_ref and event_ref.ref: event = self.db.get_event_from_handle(event_ref.ref) - return event.get_date_object().get_sort_value() + return '%012d' % event.get_date_object().get_sort_value() else: - return 0 + return '%012d' % 0 def column_birth_place(self, data): event_ref = data.get_birth_ref()