diff --git a/src/DateEdit.py b/src/DateEdit.py index b63709971..b2b9dd39a 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 7e8471139..cdc05dc74 100644 --- a/src/gen/lib/date.py +++ b/src/gen/lib/date.py @@ -1742,6 +1742,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 5521f3553..d20ec7a55 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(): @@ -89,12 +89,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 10 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() @@ -105,12 +111,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 10 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()