* src/DateDisplay.py (display): Display text for text-only dates.

Closes # 1036846.
* src/plugins/Merge.py (date_match,range_compare): Use new
Date API. Closes # 1036852.
* src/plugins/WebPage.py: Use new Date API. Use correct module
for gconf keys access. Closes # 1036856.
* src/Sort.py (by_date): Use new Date API.
* src/plugins/AncestorReport.py: Use new Date API. Closes # 1036858.
* src/plugins/Ancestor.py: Correct use of handles.
Use new Date API. Closes # 1036859.


svn: r3593
This commit is contained in:
Alex Roitman 2004-10-02 23:07:43 +00:00
parent 2b6bf2791f
commit 690a7e126a
7 changed files with 102 additions and 136 deletions

View File

@ -1,3 +1,15 @@
2004-10-02 Alex Roitman <shura@alex.neuro.umn.edu>
* src/DateDisplay.py (display): Display text for text-only dates.
Closes # 1036846.
* src/plugins/Merge.py (date_match,range_compare): Use new
Date API. Closes # 1036852.
* src/plugins/WebPage.py: Use new Date API. Use correct module
for gconf keys access. Closes # 1036856.
* src/Sort.py (by_date): Use new Date API.
* src/plugins/AncestorReport.py: Use new Date API. Closes # 1036858.
* src/plugins/Ancestor.py: Correct use of handles.
Use new Date API. Closes # 1036859.
2004-09-30 Don Allingham <dallingham@users.sourceforge.net> 2004-09-30 Don Allingham <dallingham@users.sourceforge.net>
* src/EditPerson.py: enhanced update/delete/add of person view * src/EditPerson.py: enhanced update/delete/add of person view
* src/PeopleModel.py: enhanced update/delete/add of person view * src/PeopleModel.py: enhanced update/delete/add of person view

View File

@ -178,9 +178,11 @@ class DateDisplay:
qual_str = self._qual_str[qual] qual_str = self._qual_str[qual]
if start == Date.EMPTY: if mod == Date.MOD_TEXTONLY:
return date.get_text()
elif start == Date.EMPTY:
return u"" return u""
if mod == Date.MOD_SPAN: elif mod == Date.MOD_SPAN:
d1 = self.display_cal[cal](start) d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date()) d2 = self.display_cal[cal](date.get_stop_date())
return "%sfrom %s to %s%s" % (qual_str,d1,d2,self.calendar[cal]) return "%sfrom %s to %s%s" % (qual_str,d1,d2,self.calendar[cal])

View File

@ -104,4 +104,4 @@ class Sort:
return 0 return 0
a = self.database.get_event_from_handle(a_id) a = self.database.get_event_from_handle(a_id)
b = self.database.get_event_from_handle(b_id) b = self.database.get_event_from_handle(b_id)
return Date.compare_dates(a.get_date_object(),b.get_date_object()) return cmp(a.get_date_object(),b.get_date_object())

View File

@ -39,9 +39,12 @@ import Report
import BaseDoc import BaseDoc
import RelLib import RelLib
import Errors import Errors
import DateHandler
from QuestionDialog import ErrorDialog from QuestionDialog import ErrorDialog
from gettext import gettext as _ from gettext import gettext as _
_dd = DateHandler.create_display()
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# AncestorReport # AncestorReport
@ -121,7 +124,8 @@ class AncestorReport(Report.Report):
birth_handle = person.get_birth_handle() birth_handle = person.get_birth_handle()
if birth_handle: if birth_handle:
birth = self.database.get_event_from_handle(birth_handle) birth = self.database.get_event_from_handle(birth_handle)
date = birth.get_date_object().get_start_date() date = birth.get_date_object()
date_text = _dd.display(date)
place_handle = birth.get_place_handle() place_handle = birth.get_place_handle()
if place_handle: if place_handle:
place = self.database.get_place_from_handle(place_handle).get_title() place = self.database.get_place_from_handle(place_handle).get_title()
@ -129,22 +133,22 @@ class AncestorReport(Report.Report):
place = u'' place = u''
if place[-1:] == '.': if place[-1:] == '.':
place = place[:-1] place = place[:-1]
if date.get_date() != "" or place_handle: if date_text != "" or place_handle:
if date.get_date() != "": if date_text != "":
if date.get_day_valid() and date.get_month_valid(): if date.get_day_valid() and date.get_month_valid():
if place != "": if place != "":
t = _("%s was born on %s in %s. ") % \ t = _("%s was born on %s in %s. ") % \
(name,date.get_date(),place) (name,date_text,place)
else: else:
t = _("%s was born on %s. ") % \ t = _("%s was born on %s. ") % \
(name,date.get_date()) (name,date_text)
else: else:
if place != "": if place != "":
t = _("%s was born in the year %s in %s. ") % \ t = _("%s was born in the year %s in %s. ") % \
(name,date.get_date(),place) (name,date_text,place)
else: else:
t = _("%s was born in the year %s. ") % \ t = _("%s was born in the year %s. ") % \
(name,date.get_date()) (name,date_text)
self.doc.write_text(t) self.doc.write_text(t)
buried = None buried = None
@ -156,7 +160,8 @@ class AncestorReport(Report.Report):
death_handle = person.get_death_handle() death_handle = person.get_death_handle()
if death_handle: if death_handle:
death = self.database.get_event_from_handle(death_handle) death = self.database.get_event_from_handle(death_handle)
date = death.get_date_object().get_start_date() date = death.get_date_object()
date_text = _dd.display(date)
place_handle = death.get_place_handle() place_handle = death.get_place_handle()
if place_handle: if place_handle:
place = self.database.get_place_from_handle(place_handle).get_title() place = self.database.get_place_from_handle(place_handle).get_title()
@ -164,44 +169,45 @@ class AncestorReport(Report.Report):
place = u'' place = u''
if place[-1:] == '.': if place[-1:] == '.':
place = place[:-1] place = place[:-1]
if date.get_date() != "" or place_handle: if date_text != "" or place_handle:
if person.get_gender() == RelLib.Person.male: if person.get_gender() == RelLib.Person.male:
male = 1 male = 1
else: else:
male = 0 male = 0
if date.get_date() != "": if date_text != "":
if date.get_day_valid() and date.get_month_valid(): if date.get_day_valid() and date.get_month_valid():
if male: if male:
if place != "": if place != "":
t = _("He died on %s in %s") % \ t = _("He died on %s in %s") % \
(date.get_date(),place) (date_text,place)
else: else:
t = _("He died on %s") % date.get_date() t = _("He died on %s") % date_text
else: else:
if place != "": if place != "":
t = _("She died on %s in %s") % \ t = _("She died on %s in %s") % \
(date.get_date(),place) (date_text,place)
else: else:
t = _("She died on %s") % date.get_date() t = _("She died on %s") % date_text
else: else:
if male: if male:
if place != "": if place != "":
t = _("He died in the year %s in %s") % \ t = _("He died in the year %s in %s") % \
(date.get_date(),place) (date_text,place)
else: else:
t = _("He died in the year %s") % date.get_date() t = _("He died in the year %s") % date_text
else: else:
if place != "": if place != "":
t = _("She died in the year %s in %s") % \ t = _("She died in the year %s in %s") % \
(date.get_date(),place) (date_text,place)
else: else:
t = _("She died in the year %s") % date.get_date() t = _("She died in the year %s") % date_text
self.doc.write_text(t) self.doc.write_text(t)
if buried: if buried:
date = buried.get_date_object().get_start_date() date = buried.get_date_object()
date_text = _dd.display(date)
place_handle = buried.get_place_handle() place_handle = buried.get_place_handle()
if place_handle: if place_handle:
place = self.database.get_place_from_handle(place_handle).get_title() place = self.database.get_place_from_handle(place_handle).get_title()
@ -209,22 +215,21 @@ class AncestorReport(Report.Report):
place = u'' place = u''
if place[-1:] == '.': if place[-1:] == '.':
place = place[:-1] place = place[:-1]
if date.get_date() != "" or place_handle: if date_text != "" or place_handle:
if date.get_date() != "": if date_text != "":
if date.get_day_valid() and date.get_month_valid(): if date.get_day_valid() and date.get_month_valid():
if place != "": if place != "":
t = _(", and was buried on %s in %s.") % \ t = _(", and was buried on %s in %s.") % \
(date.get_date(),place) (date_text,place)
else: else:
t = _(", and was buried on %s.") % \ t = _(", and was buried on %s.") % date_text
date.get_date()
else: else:
if place != "": if place != "":
t = _(", and was buried in the year %s in %s.") % \ t = _(", and was buried in the year %s in %s.") % \
(date.get_date(),place) (date_text,place)
else: else:
t = _(", and was buried in the year %s.") % \ t = _(", and was buried in the year %s.") % \
date.get_date() date_text
else: else:
t = _(" and was buried in %s.") % place t = _(" and was buried in %s.") % place
self.doc.write_text(t) self.doc.write_text(t)

View File

@ -34,10 +34,11 @@ import BaseDoc
import RelLib import RelLib
import Errors import Errors
import Plugins import Plugins
import Calendar import DateHandler
from QuestionDialog import ErrorDialog from QuestionDialog import ErrorDialog
from gettext import gettext as _ from gettext import gettext as _
_dd = DateHandler.create_display()
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# ComprehensiveAncestorsReport # ComprehensiveAncestorsReport
@ -439,20 +440,20 @@ class ComprehensiveAncestorsReport (Report.Report):
dateobj = event.get_date_object () dateobj = event.get_date_object ()
if dateobj: if dateobj:
text = dateobj.get_text() text = dateobj.get_text()
date_text = _dd.display(dateobj)
if text: if text:
info += ' ' + text[0].lower() + text[1:] info += ' ' + text[0].lower() + text[1:]
elif dateobj.get_valid (): elif dateobj.get_valid ():
if (dateobj.isRange () or if not dateobj.is_regular():
dateobj.get_start_date ().getModeVal () != Calendar.EXACT): info += ' ' + date_text
info += ' ' + dateobj.get_date ()
elif (dateobj.get_day_valid () and elif (dateobj.get_day_valid () and
dateobj.get_month_valid () and dateobj.get_month_valid () and
dateobj.get_year_valid ()): dateobj.get_year_valid ()):
info += _(' on %(specific_date)s') % \ info += _(' on %(specific_date)s') % \
{'specific_date': dateobj.get_date ()} {'specific_date': date_text}
else: else:
info += _(' in %(month_or_year)s') % \ info += _(' in %(month_or_year)s') % \
{'month_or_year': dateobj.get_date ()} {'month_or_year': date_text}
place = self.database.get_place_from_handle(event.get_place_handle()) place = self.database.get_place_from_handle(event.get_place_handle())
if place: if place:
@ -688,9 +689,9 @@ class ComprehensiveAncestorsReport (Report.Report):
family = self.database.get_family_from_handle(family_handle) family = self.database.get_family_from_handle(family_handle)
mother_handle = family.get_mother_handle () mother_handle = family.get_mother_handle ()
mother = self.database.get_person_from_handle(mother_handle) mother = self.database.get_person_from_handle(mother_handle)
for spouse_id in [family.get_father_handle (), mother_handle]: for spouse_handle in [family.get_father_handle (), mother_handle]:
spouse = self.database.get_person_from_handle(spouse_id) spouse = self.database.get_person_from_handle(spouse_handle)
if spouse_id == person.get_handle() or not spouse_id: if spouse_handle == person.get_handle() or not spouse_handle:
continue continue
children = '' children = ''
@ -731,37 +732,37 @@ class ComprehensiveAncestorsReport (Report.Report):
if not first_rel: if not first_rel:
if gender == RelLib.Person.female: if gender == RelLib.Person.female:
ret += _(' She later married %(name)s') % \ ret += _(' She later married %(name)s') % \
{'name': self.person_name (spouse)} {'name': self.person_name (spouse_handle)}
else: else:
ret += _(' He later married %(name)s') % \ ret += _(' He later married %(name)s') % \
{'name': self.person_name (spouse)} {'name': self.person_name (spouse_handle)}
elif (listing_children or elif (listing_children or
spouse == mother or spouse == mother or
family != from_family): family != from_family):
if gender == RelLib.Person.female: if gender == RelLib.Person.female:
ret += _(' She married %(name)s') % \ ret += _(' She married %(name)s') % \
{'name': self.person_name (spouse)} {'name': self.person_name (spouse_handle)}
else: else:
ret += _(' He married %(name)s') % \ ret += _(' He married %(name)s') % \
{'name': self.person_name (spouse)} {'name': self.person_name (spouse_handle)}
ret += self.event_info (marriage) ret += self.event_info (marriage)
else: # Not a marriage else: # Not a marriage
if not first_rel: if not first_rel:
if gender == RelLib.Person.female: if gender == RelLib.Person.female:
ret += _(' She later had a relationship with %(name)s') % \ ret += _(' She later had a relationship with %(name)s') % \
{'name': self.person_name (spouse)} {'name': self.person_name (spouse_handle)}
else: else:
ret += _(' He later had a relationship with %(name)s') % \ ret += _(' He later had a relationship with %(name)s') % \
{'name': self.person_name (spouse)} {'name': self.person_name (spouse_handle)}
else: else:
if gender == RelLib.Person.female: if gender == RelLib.Person.female:
ret += _(' She had a relationship with %(name)s') % \ ret += _(' She had a relationship with %(name)s') % \
{'name': self.person_name (spouse)} {'name': self.person_name (spouse_handle)}
else: else:
ret += _(' He had a relationship with %(name)s') % \ ret += _(' He had a relationship with %(name)s') % \
{'name': self.person_name (spouse)} {'name': self.person_name (spouse_handle)}
ret += children + '.' ret += children + '.'

View File

@ -362,17 +362,14 @@ class Merge:
return s1 == s2 return s1 == s2
def date_match(self,date1,date2): def date_match(self,date1,date2):
if date1.get_date() == "" or date2.get_date() == "": if date1.is_empty() == "" or date2.is_empty() == "":
return 0 return 0
if date1.get_date() == date2.get_date(): if date1.is_equal(date2):
return 1 return 1
if date1.is_range() or date2.is_range(): if date1.is_compound() or date2.is_compound():
return self.range_compare(date1,date2) return self.range_compare(date1,date2)
date1 = date1.get_start_date()
date2 = date2.get_start_date()
if date1.get_year() == date2.get_year(): if date1.get_year() == date2.get_year():
if date1.get_month() == date2.get_month(): if date1.get_month() == date2.get_month():
return 0.75 return 0.75
@ -384,27 +381,25 @@ class Merge:
return -1 return -1
def range_compare(self,date1,date2): def range_compare(self,date1,date2):
if date1.is_range() and date2.is_range(): start_date_1 = date1.get_start_date()[0:3]
if date1.get_start_date() >= date2.get_start_date() and \ start_date_2 = date2.get_start_date()[0:3]
date1.get_start_date() <= date2.get_stop_date() or \ stop_date_1 = date1.get_stop_date()[0:3]
date2.get_start_date() >= date1.get_start_date() and \ stop_date_2 = date2.get_stop_date()[0:3]
date2.get_start_date() <= date1.get_stop_date() or \ if date1.is_compound() and date2.is_compound():
date1.get_stop_date() >= date2.get_start_date() and \ if start_date_1 >= start_date_2 and start_date_1 <= stop_date_2 or \
date1.get_stop_date() <= date2.get_stop_date() or \ start_date_2 >= start_date_1 and start_date_2 <= stop_date_1 or \
date2.get_stop_date() >= date1.get_start_date() and \ stop_date_1 >= start_date_2 and stop_date_1 <= stop_date_2 or \
date2.get_stop_date() <= date1.get_stop_date(): stop_date_2 >= start_date_1 and stop_date_2 <= stop_date_1:
return 0.5 return 0.5
else: else:
return -1 return -1
elif date2.is_range(): elif date2.is_compound():
if date1.get_start_date() >= date2.get_start_date() and \ if start_date_1 >= start_date_2 and start_date_1 <= stop_date_2:
date1.get_start_date() <= date2.get_stop_date():
return 0.5 return 0.5
else: else:
return -1 return -1
else: else:
if date2.get_start_date() >= date1.get_start_date() and \ if start_date_2 >= start_date_1 and start_date_2 <= stop_date_1:
date2.get_start_date() <= date1.get_stop_date():
return 0.5 return 0.5
else: else:
return -1 return -1
@ -611,6 +606,7 @@ class Merge:
if value != -1: if value != -1:
chance = chance + value chance = chance + value
print p1.get_gramps_id(), p2.get_gramps_id(), chance
return chance return chance
#------------------------------------------------------------------------- #-------------------------------------------------------------------------

View File

@ -50,9 +50,9 @@ import RelLib
import HtmlDoc import HtmlDoc
import BaseDoc import BaseDoc
import const import const
import GrampsCfg import GrampsGconfKeys
import GenericFilter import GenericFilter
import Date import DateHandler
import Sort import Sort
import Report import Report
import Errors import Errors
@ -71,6 +71,8 @@ _month = [
_hline = " " # Everything is underlined, so use blank _hline = " " # Everything is underlined, so use blank
_BORN = _('b.') _BORN = _('b.')
_dd = DateHandler.create_display()
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# HtmlLinkDoc # HtmlLinkDoc
@ -232,7 +234,7 @@ class IndividualPage:
self.write_info(base.get_title()) self.write_info(base.get_title())
self.write_info(base.get_author()) self.write_info(base.get_author())
self.write_info(base.get_publication_info()) self.write_info(base.get_publication_info())
self.write_info(sref.get_date().get_date()) self.write_info(_dd.display(sref.get_date()))
self.write_info(sref.get_page()) self.write_info(sref.get_page())
if self.usecomments: if self.usecomments:
self.write_info(sref.get_text()) self.write_info(sref.get_text())
@ -504,7 +506,7 @@ class IndividualPage:
if event.get_privacy(): if event.get_privacy():
continue continue
name = _(event.get_name()) name = _(event.get_name())
date = event.get_date() date_text = event.get_date()
descr = event.get_description() descr = event.get_description()
place_handle = event.get_place_handle() place_handle = event.get_place_handle()
place_url = "" place_url = ""
@ -517,7 +519,7 @@ class IndividualPage:
place = "" place = ""
srcref = event.get_source_references() srcref = event.get_source_references()
if date == "" and descr == "" and place == "" and len(srcref) == 0: if date_text == "" and descr == "" and place == "" and len(srcref) == 0:
continue continue
if count == 0: if count == 0:
@ -534,13 +536,13 @@ class IndividualPage:
val = [] val = []
if date != "": if date_text != "":
if place != "": if place != "":
val.append(("%s, " % date,"")) val.append(("%s, " % date_text,""))
val.append((place,place_url)) val.append((place,place_url))
val.append((".","")) val.append((".",""))
else: else:
val.append(("%s." % date,"")) val.append(("%s." % date_text,""))
elif place != "": elif place != "":
val.append((place,place_url)) val.append((place,place_url))
val.append((".","")) val.append((".",""))
@ -569,7 +571,7 @@ class IndividualPage:
if event == None: if event == None:
return return
name = _(event.get_name()) name = _(event.get_name())
date = event.get_date() date_text = event.get_date()
place_handle = event.get_place_handle() place_handle = event.get_place_handle()
place_url = "" place_url = ""
if place_handle: if place_handle:
@ -585,11 +587,11 @@ class IndividualPage:
if place != "" and place[-1] == ".": if place != "" and place[-1] == ".":
place = place[0:-1] place = place[0:-1]
if date == "" and place == "" and descr == "": if date_text == "" and place == "" and descr == "":
return return
val = [] val = []
if date == "": if date_text == "":
if place == "": if place == "":
if descr != "": if descr != "":
val.append(("%s." % descr,"")) val.append(("%s." % descr,""))
@ -604,16 +606,16 @@ class IndividualPage:
else: else:
if place == "": if place == "":
if descr == "": if descr == "":
val.append(("%s." % date,"")) val.append(("%s." % date_text,""))
else: else:
val.append(("%s. %s." % (date,descr),"")) val.append(("%s. %s." % (date_text,descr),""))
else: else:
if descr == "": if descr == "":
val.append(("%s, " %date,"")) val.append(("%s, " % date_text,""))
val.append((place,place_url)) val.append((place,place_url))
val.append((".","")) val.append((".",""))
else: else:
val.append(("%s, " %date,"")) val.append(("%s, " % date_text,""))
val.append((place,place_url)) val.append((place,place_url))
val.append((".","")) val.append((".",""))
val.append(("%s." % descr,"")) val.append(("%s." % descr,""))
@ -769,58 +771,6 @@ class WebReport(Report.Report):
def get_progressbar_data(self): def get_progressbar_data(self):
return (_("Generate HTML reports - GRAMPS"), _("Creating Web Pages")) return (_("Generate HTML reports - GRAMPS"), _("Creating Web Pages"))
def make_date(self,date):
start = date.get_start_date()
if date.is_empty():
val = date.get_text()
elif date.isRange():
val = "FROM %s TO %s" % (self.subdate(start),
self.subdate(date.get_stop_date()))
else:
val = self.subdate(start)
return val
def subdate(self,subdate):
retval = ""
day = subdate.getDay()
mon = subdate.getMonth()
year = subdate.getYear()
mode = subdate.getModeVal()
day_valid = subdate.getDayValid()
mon_valid = subdate.getMonthValid()
year_valid = subdate.getYearValid()
if not day_valid:
try:
if not mon_valid:
retval = str(year)
elif not year_valid:
retval = _month[mon]
else:
retval = "%s %d" % (_month[mon],year)
except IndexError:
print "Month index error - %d" % mon
retval = str(year)
elif not mon_valid:
retval = str(year)
else:
try:
month = _month[mon]
if not year_valid:
retval = "%d %s ????" % (day,month)
else:
retval = "%d %s %d" % (day,month,year)
except IndexError:
print "Month index error - %d" % mon
retval = str(year)
if mode == Date.Calendar.ABOUT:
retval = "ABT %s" % retval
elif mode == Date.Calendar.BEFORE:
retval = "BEF %s" % retval
elif mode == Date.Calendar.AFTER:
retval = "AFT %s" % retval
return retval
def dump_gendex(self,person_handle_list,html_dir): def dump_gendex(self,person_handle_list,html_dir):
fname = "%s/gendex.txt" % html_dir fname = "%s/gendex.txt" % html_dir
try: try:
@ -846,7 +796,7 @@ class WebReport(Report.Report):
else: else:
continue continue
if e: if e:
f.write("%s|" % self.make_date(e.get_date_object())) f.write("%s|" % _dd.display(e.get_date_object()))
if e.get_place_handle(): if e.get_place_handle():
f.write('%s|' % self.db.get_place_from_handle(e.get_place_handle()).get_title()) f.write('%s|' % self.db.get_place_from_handle(e.get_place_handle()).get_title())
else: else:
@ -1376,7 +1326,7 @@ class WebReportDialog(Report.ReportDialog):
"""Get the name of the directory to which the target dialog """Get the name of the directory to which the target dialog
box should default. This value can be set in the preferences box should default. This value can be set in the preferences
panel.""" panel."""
return GrampsCfg.get_web_dir() return GrampsGconfKeys.get_web_dir()
def set_default_directory(self, value): def set_default_directory(self, value):
"""Save the name of the current directory, so that any future """Save the name of the current directory, so that any future
@ -1386,7 +1336,7 @@ class WebReportDialog(Report.ReportDialog):
This means that the last directory used will only be This means that the last directory used will only be
remembered for this session of gramps unless the user saves remembered for this session of gramps unless the user saves
his/her preferences.""" his/her preferences."""
GrampsCfg.save_web_dir(value) GrampsGconfKeys.save_web_dir(value)
def make_default_style(self): def make_default_style(self):
"""Make the default output style for the Web Pages Report.""" """Make the default output style for the Web Pages Report."""