Added date validation to these three reports in collect_data().

svn: r11983
This commit is contained in:
Rob G. Healey
2009-02-14 00:57:34 +00:00
parent 4f3c754392
commit 7b85d8e4af
3 changed files with 79 additions and 84 deletions

View File

@ -256,7 +256,7 @@ class Calendar(Report):
birth_event = self.database.get_event_from_handle(birth_ref.ref) birth_event = self.database.get_event_from_handle(birth_ref.ref)
birth_date = birth_event.get_date_object() birth_date = birth_event.get_date_object()
if self.birthdays and birth_date is not None: if (self.birthdays and birth_date is not None and birth_date.is_valid()):
year = birth_date.get_year() year = birth_date.get_year()
month = birth_date.get_month() month = birth_date.get_month()
day = birth_date.get_day() day = birth_date.get_day()
@ -329,31 +329,33 @@ class Calendar(Report):
for event_ref in fam.get_event_ref_list(): for event_ref in fam.get_event_ref_list():
event = self.database.get_event_from_handle(event_ref.ref) event = self.database.get_event_from_handle(event_ref.ref)
event_obj = event.get_date_object() event_obj = event.get_date_object()
year = event_obj.get_year()
month = event_obj.get_month()
day = event_obj.get_day()
prob_alive_date = gen.lib.Date(self.year, month, day) if event_obj.is_valid():
year = event_obj.get_year()
month = event_obj.get_month()
day = event_obj.get_day()
nyears = self.year - year prob_alive_date = gen.lib.Date(self.year, month, day)
if nyears == 0:
text = _("%(spouse)s and\n %(person)s, wedding") % { nyears = self.year - year
'spouse' : spouse_name, if nyears == 0:
'person' : short_name, text = _('%(spouse)s and\n %(person)s, wedding') % {
} 'spouse' : spouse_name,
else: 'person' : short_name,
text = (ngettext("%(spouse)s and\n %(person)s, %(nyears)d", }
"%(spouse)s and\n %(person)s, %(nyears)d", nyears) else:
% {'spouse' : spouse_name, text = (ngettext("%(spouse)s and\n %(person)s, %(nyears)d",
'person' : short_name, "%(spouse)s and\n %(person)s, %(nyears)d", nyears)
'nyears' : nyears}) % {'spouse' : spouse_name,
'person' : short_name,
'nyears' : nyears})
alive1 = probably_alive(person, self.database, \ alive1 = probably_alive(person, self.database, \
prob_alive_date) prob_alive_date)
alive2 = probably_alive(spouse, self.database, \ alive2 = probably_alive(spouse, self.database, \
prob_alive_date) prob_alive_date)
if ((self.alive and alive1 and alive2) or not self.alive): if ((self.alive and alive1 and alive2) or not self.alive):
self.add_day_item(text, month, day) self.add_day_item(text, month, day)
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #

View File

@ -203,7 +203,7 @@ class CalendarReport(Report):
birth_event = self.database.get_event_from_handle(birth_ref.ref) birth_event = self.database.get_event_from_handle(birth_ref.ref)
birth_date = birth_event.get_date_object() birth_date = birth_event.get_date_object()
if self.birthdays and birth_date is not None: if (self.birthdays and birth_date is not None and birth_date.is_valid()):
year = birth_date.get_year() year = birth_date.get_year()
month = birth_date.get_month() month = birth_date.get_month()
day = birth_date.get_day() day = birth_date.get_day()
@ -290,24 +290,26 @@ class CalendarReport(Report):
month = event_obj.get_month() month = event_obj.get_month()
day = event_obj.get_day() day = event_obj.get_day()
nyears = self.year - year nyears = self.year - year
if nyears == 0:
text = _("%(spouse)s and\n %(person)s, wedding") % { if event_obj.is_valid():
'spouse' : spouse_name, if nyears == 0:
'person' : short_name} text = _("%(spouse)s and\n %(person)s, wedding") % {
else: 'spouse' : spouse_name,
text = (ngettext("%(spouse)s and\n %(person)s, %(nyears)d", 'person' : short_name}
"%(spouse)s and\n %(person)s, %(nyears)d", nyears) else:
% {'spouse' : spouse_name, text = (ngettext("%(spouse)s and\n %(person)s, %(nyears)d",
'person' : short_name, "%(spouse)s and\n %(person)s, %(nyears)d", nyears)
'nyears' : nyears}) % {'spouse' : spouse_name,
'person' : short_name,
'nyears' : nyears})
prob_alive_date = gen.lib.Date(self.year, month, day) prob_alive_date = gen.lib.Date(self.year, month, day)
alive1 = probably_alive(person, self.database, \ alive1 = probably_alive(person, self.database, \
prob_alive_date) prob_alive_date)
alive2 = probably_alive(spouse, self.database, \ alive2 = probably_alive(spouse, self.database, \
prob_alive_date) prob_alive_date)
if (self.alive and alive1 and alive2) or not self.alive: if (self.alive and alive1 and alive2) or not self.alive:
self.add_day_item(text, month, day) self.add_day_item(text, month, day)
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #

View File

@ -402,7 +402,6 @@ class WebCalReport(Report):
nav_text = get_short_month_name(nav_text) nav_text = get_short_month_name(nav_text)
# Figure out if we need <li id="CurrentSection"> or just plain <li> # Figure out if we need <li id="CurrentSection"> or just plain <li>
print url_fname, currentsection
if url_fname == currentsection: if url_fname == currentsection:
cs = True cs = True
@ -1027,46 +1026,40 @@ class WebCalReport(Report):
birth_date = birth_event.get_date_object() birth_date = birth_event.get_date_object()
# determine birthday information??? # determine birthday information???
if self.birthday and birth_date is not None: if (self.birthday and birth_date is not None and birth_date.is_valid()):
# determine if birthdadate is a valid date??? year = birth_date.get_year()
complete_date = False month = birth_date.get_month()
if birth_date.is_valid(): day = birth_date.get_day()
complete_date = True
if complete_date:
year = birth_date.get_year() prob_alive_date = gen.lib.Date(this_year, month, day)
month = birth_date.get_month()
day = birth_date.get_day()
prob_alive_date = gen.lib.Date(this_year, month, day) # add some things to handle maiden name:
father_surname = None # husband, actually
sex = person.gender
if sex == gen.lib.Person.FEMALE:
# add some things to handle maiden name: # get husband's last name:
father_surname = None # husband, actually if self.maiden_name in ['spouse_first', 'spouse_last']:
sex = person.gender if len(family_list) > 0:
if sex == gen.lib.Person.FEMALE: if self.maiden_name == 'spouse_first':
fhandle = family_list[0]
# get husband's last name: else:
if self.maiden_name in ['spouse_first', 'spouse_last']: fhandle = family_list[-1]
if len(family_list) > 0: fam = self.database.get_family_from_handle(fhandle)
if self.maiden_name == 'spouse_first': father_handle = fam.get_father_handle()
fhandle = family_list[0] mother_handle = fam.get_mother_handle()
else: if mother_handle == person_handle:
fhandle = family_list[-1] if father_handle:
fam = self.database.get_family_from_handle(fhandle) father = self.database.get_person_from_handle(father_handle)
father_handle = fam.get_father_handle() if father != None:
mother_handle = fam.get_mother_handle() father_name = father.primary_name
if mother_handle == person_handle: father_surname = _get_regular_surname(sex, father_name)
if father_handle: short_name = _get_short_name(person, father_surname)
father = self.database.get_person_from_handle(father_handle) alive = probably_alive(person, self.database, prob_alive_date)
if father != None: if (self.alive and alive) or not self.alive:
father_name = father.primary_name
father_surname = _get_regular_surname(sex, father_name)
short_name = _get_short_name(person, father_surname)
alive = probably_alive(person, self.database, prob_alive_date)
text = _('%(short_name)s') % {'short_name' : short_name} text = _('%(short_name)s') % {'short_name' : short_name}
if (self.alive and alive) or not self.alive: self.add_day_item(text, year, month, day, 'Birthday')
self.add_day_item(text, year, month, day, 'Birthday')
# add anniversary if requested # add anniversary if requested
if self.anniv: if self.anniv:
@ -1095,12 +1088,7 @@ class WebCalReport(Report):
prob_alive_date = gen.lib.Date(this_year, month, day) prob_alive_date = gen.lib.Date(this_year, month, day)
# determine if anniversary date is a valid date???
complete_date = False
if event_obj.is_valid(): if event_obj.is_valid():
complete_date = True
if complete_date:
text = _('%(spouse)s and %(person)s') % { text = _('%(spouse)s and %(person)s') % {
'spouse' : spouse_name, 'spouse' : spouse_name,
'person' : short_name} 'person' : short_name}
@ -1523,7 +1511,8 @@ def get_marrital_status(db, family):
""" """
Returns the marital status of two people, a couple Returns the marital status of two people, a couple
are_married will either be the marriage event or None if not married anymore are_married will either be the marriage event
or None if not married anymore
""" """
are_married = None are_married = None
@ -1544,7 +1533,8 @@ def get_first_day_of_month(year, month):
It can also be a day in the previous month. It can also be a day in the previous month.
""" """
current_date = datetime.date(year, month, 1) # first day of the month # first day of the month
current_date = datetime.date(year, month, 1)
# monthinfo is filled using standard Python library # monthinfo is filled using standard Python library
# calendar.monthcalendar. It fills a list of 7-day-lists. The first day # calendar.monthcalendar. It fills a list of 7-day-lists. The first day
@ -1586,6 +1576,7 @@ def _has_webpage_extension(url, ext):
determine if a filename has an extension or not... determine if a filename has an extension or not...
url = filename to be checked url = filename to be checked
ext -- extension to process if there is one or not
""" """
if url.endswith(ext): if url.endswith(ext):