moved _make_date from Calendar.py, BirthdayReport.py, and WebCal.py into libholiday. Changed variable names in WebCal.py for improved readability.
svn: r11833
This commit is contained in:
parent
8c2269c58e
commit
a7ef5d1e43
@ -43,6 +43,7 @@ from Utils import probably_alive, ProgressMeter
|
|||||||
from FontScale import string_trim
|
from FontScale import string_trim
|
||||||
|
|
||||||
import libholiday
|
import libholiday
|
||||||
|
from libholiday import _make_date
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -58,14 +59,6 @@ def g2iso(dow):
|
|||||||
# ISO: MON = 1
|
# ISO: MON = 1
|
||||||
return (dow + 5) % 7 + 1
|
return (dow + 5) % 7 + 1
|
||||||
|
|
||||||
def make_date(year, month, day):
|
|
||||||
"""
|
|
||||||
Return a Date object of the particular year/month/day.
|
|
||||||
"""
|
|
||||||
retval = gen.lib.Date()
|
|
||||||
retval.set_yr_mon_day(year, month, day)
|
|
||||||
return retval
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Calendar
|
# Calendar
|
||||||
@ -292,7 +285,7 @@ class Calendar(Report):
|
|||||||
father_lastname = father.get_primary_name().get_surname()
|
father_lastname = father.get_primary_name().get_surname()
|
||||||
short_name = self.get_name(person, father_lastname)
|
short_name = self.get_name(person, father_lastname)
|
||||||
if age >= 0:
|
if age >= 0:
|
||||||
alive = probably_alive(person, self.database, make_date(self.year, month, day))
|
alive = probably_alive(person, self.database, _make_date(self.year, month, day))
|
||||||
if ((self.alive and alive) or not self.alive):
|
if ((self.alive and alive) or not self.alive):
|
||||||
self.add_day_item("%s, %d%s" % (short_name, age, ""), month, day)
|
self.add_day_item("%s, %d%s" % (short_name, age, ""), month, day)
|
||||||
if self.anniversaries:
|
if self.anniversaries:
|
||||||
@ -337,8 +330,8 @@ class Calendar(Report):
|
|||||||
'person' : short_name,
|
'person' : short_name,
|
||||||
'nyears' : years,
|
'nyears' : years,
|
||||||
}
|
}
|
||||||
alive1 = probably_alive(person, self.database, make_date(self.year, month, day))
|
alive1 = probably_alive(person, self.database, _make_date(self.year, month, day))
|
||||||
alive2 = probably_alive(spouse, self.database, make_date(self.year, month, day))
|
alive2 = probably_alive(spouse, self.database, _make_date(self.year, month, day))
|
||||||
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)
|
||||||
|
|
||||||
|
@ -36,12 +36,21 @@ import os
|
|||||||
#
|
#
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
from gen.plug import PluginManager, Plugin
|
from gen.plug import PluginManager, Plugin
|
||||||
|
import gen.lib
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Support functions
|
# Support functions
|
||||||
#
|
#
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
|
def _make_date(year, month, day):
|
||||||
|
"""
|
||||||
|
Return a Date object of the particular year/month/day.
|
||||||
|
"""
|
||||||
|
retval = gen.lib.Date()
|
||||||
|
retval.set_yr_mon_day(year, month, day)
|
||||||
|
return retval
|
||||||
|
|
||||||
def easter(year):
|
def easter(year):
|
||||||
"""
|
"""
|
||||||
Computes the year/month/day of easter. Based on work by
|
Computes the year/month/day of easter. Based on work by
|
||||||
|
@ -42,19 +42,7 @@ import gen.lib
|
|||||||
from Utils import probably_alive, ProgressMeter
|
from Utils import probably_alive, ProgressMeter
|
||||||
|
|
||||||
import libholiday
|
import libholiday
|
||||||
|
from libholiday import _make_date
|
||||||
#------------------------------------------------------------------------
|
|
||||||
#
|
|
||||||
# Support functions
|
|
||||||
#
|
|
||||||
#------------------------------------------------------------------------
|
|
||||||
def make_date(year, month, day):
|
|
||||||
"""
|
|
||||||
Return a Date object of the particular year/month/day.
|
|
||||||
"""
|
|
||||||
retval = gen.lib.Date()
|
|
||||||
retval.set_yr_mon_day(year, month, day)
|
|
||||||
return retval
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -239,7 +227,7 @@ class CalendarReport(Report):
|
|||||||
father_lastname = father.get_primary_name().get_surname()
|
father_lastname = father.get_primary_name().get_surname()
|
||||||
short_name = self.get_name(person, father_lastname)
|
short_name = self.get_name(person, father_lastname)
|
||||||
if age >= 0:
|
if age >= 0:
|
||||||
alive = probably_alive(person, self.database, make_date(self.year, month, day))
|
alive = probably_alive(person, self.database, _make_date(self.year, month, day))
|
||||||
if ((self.alive and alive) or not self.alive):
|
if ((self.alive and alive) or not self.alive):
|
||||||
comment = ""
|
comment = ""
|
||||||
if self.relationships:
|
if self.relationships:
|
||||||
@ -292,8 +280,8 @@ class CalendarReport(Report):
|
|||||||
'person' : short_name,
|
'person' : short_name,
|
||||||
'nyears' : years,
|
'nyears' : years,
|
||||||
}
|
}
|
||||||
alive1 = probably_alive(person, self.database, make_date(self.year, month, day))
|
alive1 = probably_alive(person, self.database, _make_date(self.year, month, day))
|
||||||
alive2 = probably_alive(spouse, self.database, make_date(self.year, month, day))
|
alive2 = probably_alive(spouse, self.database, _make_date(self.year, month, day))
|
||||||
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)
|
||||||
|
|
||||||
|
@ -78,6 +78,7 @@ from DateHandler import displayer as _dd
|
|||||||
from DateHandler import parser as _dp
|
from DateHandler import parser as _dp
|
||||||
|
|
||||||
import libholiday
|
import libholiday
|
||||||
|
from libholiday import _make_date
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -168,14 +169,6 @@ _COPY_OPTIONS = [
|
|||||||
_('No copyright notice'),
|
_('No copyright notice'),
|
||||||
]
|
]
|
||||||
|
|
||||||
def _make_date(year, month, day):
|
|
||||||
"""
|
|
||||||
Return a Date object of the particular year/month/day.
|
|
||||||
"""
|
|
||||||
retval = gen.lib.Date()
|
|
||||||
retval.set_yr_mon_day(year, month, day)
|
|
||||||
return retval
|
|
||||||
|
|
||||||
# Compute the first day to display for this month.
|
# Compute the first day to display for this month.
|
||||||
# It can also be a day in the previous month.
|
# It can also be a day in the previous month.
|
||||||
def get_first_day(year, month):
|
def get_first_day(year, month):
|
||||||
@ -463,14 +456,13 @@ class WebCalReport(Report):
|
|||||||
# each year will link to January, unless self.partyear is True,
|
# each year will link to January, unless self.partyear is True,
|
||||||
# then it will link to current month.
|
# then it will link to current month.
|
||||||
# this will always need an extension added
|
# this will always need an extension added
|
||||||
lng_month = _get_long_month_name(1)
|
full_month_name = _get_long_month_name(1)
|
||||||
if self.partyear:
|
if self.partyear and cal_year == self.today.year:
|
||||||
if cal_year == self.today.year:
|
full_month_name = _get_long_month_name(self.today.month)
|
||||||
lng_month = _get_long_month_name(self.today.month)
|
|
||||||
|
|
||||||
# Note. We use '/' here because it is a URL, not a OS dependent
|
# Note. We use '/' here because it is a URL, not a OS dependent
|
||||||
# pathname.
|
# pathname.
|
||||||
url = '/'.join(subdirs + [lng_month]) + self.ext
|
url = '/'.join(subdirs + [full_month_name]) + self.ext
|
||||||
|
|
||||||
# determine if we need to highlight???
|
# determine if we need to highlight???
|
||||||
if str(cal_year) == currentsection:
|
if str(cal_year) == currentsection:
|
||||||
@ -534,8 +526,8 @@ class WebCalReport(Report):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# define names for long and short month names
|
# define names for long and short month names
|
||||||
lng_month = _get_long_month_name(month)
|
full_month_name = _get_long_month_name(month)
|
||||||
shrt_month = _get_short_month_name(month)
|
abbr_month_name = _get_short_month_name(month)
|
||||||
|
|
||||||
# dow (day-of-week) uses Gramps numbering, sunday => 1, etc
|
# dow (day-of-week) uses Gramps numbering, sunday => 1, etc
|
||||||
start_dow = self.start_dow
|
start_dow = self.start_dow
|
||||||
@ -560,7 +552,7 @@ class WebCalReport(Report):
|
|||||||
|
|
||||||
# Begin calendar head. We'll use the capitalized name, because here it
|
# Begin calendar head. We'll use the capitalized name, because here it
|
||||||
# seems appropriate for most countries.
|
# seems appropriate for most countries.
|
||||||
month_name = lng_month.capitalize()
|
month_name = full_month_name.capitalize()
|
||||||
th_txt = month_name
|
th_txt = month_name
|
||||||
if cal == 'wc': # normal_cal()
|
if cal == 'wc': # normal_cal()
|
||||||
if not self.multiyear:
|
if not self.multiyear:
|
||||||
@ -611,7 +603,7 @@ class WebCalReport(Report):
|
|||||||
|
|
||||||
else: # normal day number in current month
|
else: # normal day number in current month
|
||||||
thisday = datetime.date.fromordinal(current_ord)
|
thisday = datetime.date.fromordinal(current_ord)
|
||||||
of.write('\t\t\t<td id="%s%02d" ' % (shrt_month, day))
|
of.write('\t\t\t<td id="%s%02d" ' % (abbr_month_name, day))
|
||||||
if thisday.month == month: # Something this month
|
if thisday.month == month: # Something this month
|
||||||
holiday_list = self.holidays.get(month, {}).get(thisday.day, [])
|
holiday_list = self.holidays.get(month, {}).get(thisday.day, [])
|
||||||
bday_anniv_list = self.calendar.get(month, {}).get(thisday.day, [])
|
bday_anniv_list = self.calendar.get(month, {}).get(thisday.day, [])
|
||||||
@ -622,8 +614,8 @@ class WebCalReport(Report):
|
|||||||
# specify day class for this day
|
# specify day class for this day
|
||||||
of.write('class="%s">\n' % hilightday)
|
of.write('class="%s">\n' % hilightday)
|
||||||
|
|
||||||
evt_dte = _make_date(thisday.year, thisday.month, thisday.day)
|
event_date = _make_date(thisday.year, thisday.month, thisday.day)
|
||||||
day_list = get_day_list(evt_dte, holiday_list, bday_anniv_list)
|
day_list = get_day_list(event_date, holiday_list, bday_anniv_list)
|
||||||
|
|
||||||
if day_list:
|
if day_list:
|
||||||
# Year at a Glance
|
# Year at a Glance
|
||||||
@ -636,10 +628,10 @@ class WebCalReport(Report):
|
|||||||
|
|
||||||
# create web link to corresponding "One Day" page...
|
# create web link to corresponding "One Day" page...
|
||||||
# The HREF is relative to the year path.
|
# The HREF is relative to the year path.
|
||||||
fname_date = '/'.join([lng_month, fname_date])
|
fname_date = '/'.join([full_month_name, fname_date])
|
||||||
fname_date += self.ext
|
fname_date += self.ext
|
||||||
of.write('\t\t\t\t<a href="%s" title="%s%d">\n'
|
of.write('\t\t\t\t<a href="%s" title="%s%d">\n'
|
||||||
% (fname_date, shrt_month, day))
|
% (fname_date, abbr_month_name, day))
|
||||||
of.write('\t\t\t\t\t<div class="date">%d</div></a>\n' % day)
|
of.write('\t\t\t\t\t<div class="date">%d</div></a>\n' % day)
|
||||||
one_day_cal = "OneDay"
|
one_day_cal = "OneDay"
|
||||||
|
|
||||||
@ -649,7 +641,7 @@ class WebCalReport(Report):
|
|||||||
of.write('\t\t\t\t<div class="date">%d</div>\n' % day)
|
of.write('\t\t\t\t<div class="date">%d</div>\n' % day)
|
||||||
|
|
||||||
# both WebCal and Year_Glance needs day_list displayed
|
# both WebCal and Year_Glance needs day_list displayed
|
||||||
self.one_day(of, evt_dte, one_day_cal, day_list)
|
self.one_day(of, event_date, one_day_cal, day_list)
|
||||||
|
|
||||||
# no holiday/ bday/ anniversary this day
|
# no holiday/ bday/ anniversary this day
|
||||||
else:
|
else:
|
||||||
@ -779,7 +771,7 @@ class WebCalReport(Report):
|
|||||||
def close_file(self, of):
|
def close_file(self, of):
|
||||||
of.close()
|
of.close()
|
||||||
|
|
||||||
def one_day(self, of, evt_dte, one_day_cal, day_list):
|
def one_day(self, of, event_date, one_day_cal, day_list):
|
||||||
"""
|
"""
|
||||||
This method creates the One Day page for "Year At A Glance"
|
This method creates the One Day page for "Year At A Glance"
|
||||||
|
|
||||||
@ -791,10 +783,10 @@ class WebCalReport(Report):
|
|||||||
# This is one_day in the year-at-a-glance calendar
|
# This is one_day in the year-at-a-glance calendar
|
||||||
if one_day_cal == "OneDay":
|
if one_day_cal == "OneDay":
|
||||||
|
|
||||||
# break up evt_dte to get year, month, day for this day
|
# break up event_date to get year, month, day for this day
|
||||||
year = evt_dte.get_year()
|
year = event_date.get_year()
|
||||||
month = evt_dte.get_month()
|
month = event_date.get_month()
|
||||||
day = evt_dte.get_day()
|
day = event_date.get_day()
|
||||||
|
|
||||||
# create fname date string for "One Day" calendar pages filename
|
# create fname date string for "One Day" calendar pages filename
|
||||||
# using yyyymmdd for filename
|
# using yyyymmdd for filename
|
||||||
@ -803,16 +795,16 @@ class WebCalReport(Report):
|
|||||||
fname_date = str(year) + str(two_digit_month) + str(two_digit_day)
|
fname_date = str(year) + str(two_digit_month) + str(two_digit_day)
|
||||||
|
|
||||||
# define names for long month
|
# define names for long month
|
||||||
lng_month = _get_long_month_name(month)
|
full_month_name = _get_long_month_name(month)
|
||||||
|
|
||||||
# Name the file, and create it (see code in calendar_build)
|
# Name the file, and create it (see code in calendar_build)
|
||||||
fpath = os.path.join(str(year), lng_month)
|
fpath = os.path.join(str(year), full_month_name)
|
||||||
of = self.create_file(fname_date, fpath)
|
of = self.create_file(fname_date, fpath)
|
||||||
|
|
||||||
nr_up = 2 # number of directory levels up to get to root
|
nr_up = 2 # number of directory levels up to get to root
|
||||||
|
|
||||||
# set date display as in user prevferences
|
# set date display as in user prevferences
|
||||||
pg_date = _dd.display(evt_dte)
|
pg_date = _dd.display(event_date)
|
||||||
|
|
||||||
# page title
|
# page title
|
||||||
title = _('One Day Within A Year')
|
title = _('One Day Within A Year')
|
||||||
@ -822,7 +814,7 @@ class WebCalReport(Report):
|
|||||||
|
|
||||||
of.write('<body id="%s">\n' % pg_date)
|
of.write('<body id="%s">\n' % pg_date)
|
||||||
|
|
||||||
self.calendar_common(of, nr_up, year, lng_month, title)
|
self.calendar_common(of, nr_up, year, full_month_name, title)
|
||||||
|
|
||||||
of.write('\t<h3 id="OneDay">%s</h3>\n' % pg_date)
|
of.write('\t<h3 id="OneDay">%s</h3>\n' % pg_date)
|
||||||
|
|
||||||
@ -1461,22 +1453,22 @@ def _gramps2iso(dow):
|
|||||||
return (dow + 5) % 7 + 1
|
return (dow + 5) % 7 + 1
|
||||||
|
|
||||||
# define names for long and short month in GrampsLocale
|
# define names for long and short month in GrampsLocale
|
||||||
_lng_month = GrampsLocale.long_months
|
_full_month_name = GrampsLocale.long_months
|
||||||
_shrt_month = GrampsLocale.short_months
|
_abbr_month_name = GrampsLocale.short_months
|
||||||
|
|
||||||
def _get_long_month_name(month):
|
def _get_long_month_name(month):
|
||||||
return _lng_month[month]
|
return _full_month_name[month]
|
||||||
|
|
||||||
def _get_short_month_name(month):
|
def _get_short_month_name(month):
|
||||||
return _shrt_month[month]
|
return _abbr_month_name[month]
|
||||||
|
|
||||||
def get_day_list(evt_dte, holiday_list, bday_anniv_list):
|
def get_day_list(event_date, holiday_list, bday_anniv_list):
|
||||||
"""
|
"""
|
||||||
Will fill day_list and return it to its caller: calendar_build()
|
Will fill day_list and return it to its caller: calendar_build()
|
||||||
|
|
||||||
holiday_list, or bday_anniv_list -- will always have something in it...
|
holiday_list, or bday_anniv_list -- will always have something in it...
|
||||||
|
|
||||||
evt_dte -- date for this day_list
|
event_date -- date for this day_list
|
||||||
|
|
||||||
'day_list' - a combination of both dictionaries to be able to create one day
|
'day_list' - a combination of both dictionaries to be able to create one day
|
||||||
nyears, date, text, event --- are necessary for figuring the age or years married
|
nyears, date, text, event --- are necessary for figuring the age or years married
|
||||||
@ -1494,7 +1486,7 @@ def get_day_list(evt_dte, holiday_list, bday_anniv_list):
|
|||||||
|
|
||||||
for p in holiday_list:
|
for p in holiday_list:
|
||||||
for line in p.splitlines():
|
for line in p.splitlines():
|
||||||
day_list.append((nyears, evt_dte, line, _('Holiday')))
|
day_list.append((nyears, event_date, line, _('Holiday')))
|
||||||
|
|
||||||
# birthday/ anniversary on this day
|
# birthday/ anniversary on this day
|
||||||
if bday_anniv_list > []:
|
if bday_anniv_list > []:
|
||||||
@ -1505,10 +1497,10 @@ def get_day_list(evt_dte, holiday_list, bday_anniv_list):
|
|||||||
if date != '...':
|
if date != '...':
|
||||||
|
|
||||||
# number of years married, ex: 10
|
# number of years married, ex: 10
|
||||||
nyears = evt_dte.get_year() - date.get_year()
|
nyears = event_date.get_year() - date.get_year()
|
||||||
|
|
||||||
# number of years for birthday, ex: 10 years
|
# number of years for birthday, ex: 10 years
|
||||||
age_str = evt_dte - date
|
age_str = event_date - date
|
||||||
age_str.format(precision=1)
|
age_str.format(precision=1)
|
||||||
|
|
||||||
# a birthday
|
# a birthday
|
||||||
|
Loading…
x
Reference in New Issue
Block a user