Merge pull request #908 from SNoiraud:FR11336
New narrative web and web calendar features: * Allow urls in the user's css files * Allow alternate stylesheets in pages for narrative web and webcal * Webcal: incorrect results when divorce event. * Some pylint improvements Resolves #11336.
This commit is contained in:
commit
f5861169fe
@ -752,7 +752,6 @@ class BasePage: # pylint: disable=C1001
|
||||
if latitude and longitude:
|
||||
latitude, longitude = conv_lat_lon(latitude, longitude, "D.D8")
|
||||
if latitude is not None:
|
||||
etype = event.get_type()
|
||||
place_lat_long.append([latitude, longitude, placetitle,
|
||||
place_handle, event])
|
||||
|
||||
@ -1422,8 +1421,23 @@ class BasePage: # pylint: disable=C1001
|
||||
Html("link", type="text/css", href=url3,
|
||||
media='print', rel="stylesheet", indent=False),
|
||||
Html("link", type="text/css", href=url2,
|
||||
media="screen", rel="stylesheet", indent=False),
|
||||
media="screen", title=self._("Default"),
|
||||
rel="stylesheet", indent=False),
|
||||
)
|
||||
# create all alternate stylesheets
|
||||
# Cannot use it on local files (file://)
|
||||
for css_f in CSS:
|
||||
already_done = False
|
||||
for css_fn in ("UsEr_", "Basic", "Mainz", "Nebraska"):
|
||||
if css_fn in css_f and not already_done:
|
||||
css_f = css_f.replace("UsEr_", "")
|
||||
fname = "/".join(["css", css_f + ".css"])
|
||||
urlx = self.report.build_url_fname(fname, None,
|
||||
self.uplink)
|
||||
links += Html("link", rel="alternate stylesheet",
|
||||
title=css_f, indent=False,
|
||||
media="screen", type="text/css",
|
||||
href=urlx)
|
||||
|
||||
# Link to Navigation Menus stylesheet
|
||||
if CSS[self.report.css]["navigation"]:
|
||||
@ -2977,4 +2991,3 @@ class BasePage: # pylint: disable=C1001
|
||||
|
||||
# closes the file
|
||||
self.report.close_file(output_file, sio, date)
|
||||
|
||||
|
@ -1008,6 +1008,18 @@ class NavWebReport(Report):
|
||||
"""
|
||||
imgs = []
|
||||
|
||||
# copy all screen style sheet
|
||||
for css_f in CSS:
|
||||
already_done = False
|
||||
for css_fn in ("UsEr_", "Basic", "Mainz", "Nebraska", "Vis"):
|
||||
if css_fn in css_f and not already_done:
|
||||
already_done = True
|
||||
fname = CSS[css_f]["filename"]
|
||||
# add images for this css
|
||||
imgs += CSS[css_f]["images"]
|
||||
css_f = css_f.replace("UsEr_", "")
|
||||
self.copy_file(fname, css_f + ".css", "css")
|
||||
|
||||
# copy screen style sheet
|
||||
if CSS[self.css]["filename"]:
|
||||
fname = CSS[self.css]["filename"]
|
||||
@ -1683,13 +1695,15 @@ class NavWebOptions(MenuReportOptions):
|
||||
cright.set_help(_("The copyright to be used for the web files"))
|
||||
addopt("cright", cright)
|
||||
|
||||
self.__css = EnumeratedListOption(('StyleSheet'), CSS["default"]["id"])
|
||||
self.__css = EnumeratedListOption(('StyleSheet'),
|
||||
CSS["Basic-Ash"]["id"])
|
||||
for (dummy_fname, gid) in sorted(
|
||||
[(CSS[key]["translation"], CSS[key]["id"])
|
||||
for key in list(CSS.keys())]):
|
||||
if CSS[gid]["user"]:
|
||||
self.__css.add_item(CSS[gid]["id"], CSS[gid]["translation"])
|
||||
self.__css.set_help(_('The stylesheet to be used for the web pages'))
|
||||
self.__css.set_help(_('The default stylesheet to be used for'
|
||||
' the pages'))
|
||||
addopt("css", self.__css)
|
||||
self.__css.connect("value-changed", self.__stylesheet_changed)
|
||||
|
||||
|
@ -348,6 +348,20 @@ class WebCalReport(Report):
|
||||
"""
|
||||
Copies all the necessary stylesheets and images for these calendars
|
||||
"""
|
||||
imgs = []
|
||||
|
||||
# copy all screen style sheet
|
||||
for css_f in CSS:
|
||||
already_done = False
|
||||
for css_fn in ("UsEr_", "Basic", "Mainz", "Nebraska", "Vis"):
|
||||
if css_fn in css_f and not already_done:
|
||||
already_done = True
|
||||
fname = CSS[css_f]["filename"]
|
||||
# add images for this css
|
||||
imgs += CSS[css_f]["images"]
|
||||
css_f = css_f.replace("UsEr_", "")
|
||||
self.copy_file(fname, css_f + ".css", "css")
|
||||
|
||||
# Copy the screen stylesheet
|
||||
if self.css and self.css != 'No style sheet':
|
||||
fname = CSS[self.css]["filename"]
|
||||
@ -364,8 +378,6 @@ class WebCalReport(Report):
|
||||
fname = CSS["Print-Default"]["filename"]
|
||||
self.copy_file(fname, _CALENDARPRINT, "css")
|
||||
|
||||
imgs = []
|
||||
|
||||
# Mainz stylesheet graphics
|
||||
# will only be used if Mainz is slected as the stylesheet
|
||||
imgs += CSS[self.css]["images"]
|
||||
@ -457,7 +469,20 @@ class WebCalReport(Report):
|
||||
links = Html("link", rel='shortcut icon',
|
||||
href=fname1, type="image/x-icon") + (
|
||||
Html("link", href=fname2, type="text/css",
|
||||
title=self._("Default"),
|
||||
media="screen", rel="stylesheet", indent=False))
|
||||
# create all alternate stylesheets
|
||||
# Cannot use it on local files (file://)
|
||||
for css_f in CSS:
|
||||
already_done = False
|
||||
for css_fn in ("UsEr_", "Basic", "Mainz", "Nebraska"):
|
||||
if css_fn in css_f and not already_done:
|
||||
css_f = css_f.replace("UsEr_", "")
|
||||
fname = "/".join(subdirs + ["css", css_f + ".css"])
|
||||
links += Html("link", rel="alternate stylesheet",
|
||||
title=css_f, indent=False,
|
||||
media="screen", type="text/css",
|
||||
href=fname)
|
||||
|
||||
# add horizontal menu if css == Blue or Visually because
|
||||
# there is no menus?
|
||||
@ -1390,9 +1415,6 @@ class WebCalReport(Report):
|
||||
text = short_name
|
||||
self.add_day_item(text, year, month, day, 'Death',
|
||||
age_at_death, death_date)
|
||||
#print('Death date for %s %s/%s/%s' % (short_name, day,
|
||||
# month, year),
|
||||
# age_at_death)
|
||||
|
||||
# add anniversary if requested
|
||||
if self.anniv:
|
||||
@ -1448,6 +1470,18 @@ class WebCalReport(Report):
|
||||
wedding_age = first_died - event_date
|
||||
wedding_age = wedding_age.format(
|
||||
dlocale=self.rlocale)
|
||||
divorce_event = get_divorce_event(db, fam)
|
||||
if divorce_event:
|
||||
d_date = divorce_event.get_date_object()
|
||||
if (d_date is not Date() and
|
||||
d_date.is_valid()):
|
||||
d_date = gregorian(d_date)
|
||||
if d_date != Date():
|
||||
w_age = d_date - event_date
|
||||
w_age = w_age.format(
|
||||
dlocale=self.rlocale)
|
||||
wedding_age = w_age
|
||||
first_died = d_date
|
||||
|
||||
if self.link_to_narweb:
|
||||
prefx = self.narweb_prefix
|
||||
@ -1467,8 +1501,8 @@ class WebCalReport(Report):
|
||||
prob_alive_date)
|
||||
if first_died == Date():
|
||||
first_died = Date(0, 0, 0)
|
||||
if ((self.alive and alive1
|
||||
and alive2) or not self.alive):
|
||||
if ((self.alive and (alive1 or alive2))
|
||||
or not self.alive):
|
||||
|
||||
spse = self._('%(spouse)s and'
|
||||
' %(person)s')
|
||||
@ -1990,14 +2024,29 @@ def get_marriage_event(db, family):
|
||||
for event_ref in family.get_event_ref_list():
|
||||
|
||||
event = db.get_event_from_handle(event_ref.ref)
|
||||
if event.type.is_marriage:
|
||||
if event.type.is_marriage():
|
||||
marriage_event = event
|
||||
elif event.type.is_divorce:
|
||||
continue
|
||||
break
|
||||
|
||||
# return the marriage event or False to it caller
|
||||
return marriage_event
|
||||
|
||||
def get_divorce_event(db, family):
|
||||
"""
|
||||
divorce will either be the divorce event or False
|
||||
"""
|
||||
|
||||
divorce_event = False
|
||||
for event_ref in family.get_event_ref_list():
|
||||
|
||||
event = db.get_event_from_handle(event_ref.ref)
|
||||
if event.type.is_divorce():
|
||||
divorce_event = event
|
||||
break
|
||||
|
||||
# return the divorce event or False to it caller
|
||||
return divorce_event
|
||||
|
||||
def get_first_day_of_month(year, month):
|
||||
"""
|
||||
Compute the first day to display for this month.
|
||||
|
@ -23,6 +23,7 @@
|
||||
# python modules
|
||||
#------------------------------------------------
|
||||
import os
|
||||
import re
|
||||
from gramps.gen.const import VERSION_DIR, IMAGE_DIR, DATA_DIR, USER_CSS
|
||||
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.sgettext
|
||||
@ -57,7 +58,7 @@ def load_on_reg(dbstate, uistate, plugin):
|
||||
|
||||
# default style sheet in the options
|
||||
# Basic Ash style sheet
|
||||
["default", 1, _("Basic-Ash"),
|
||||
["Basic-Ash", 1, _("Basic-Ash"),
|
||||
path_css('Web_Basic-Ash.css'), None, [], []],
|
||||
|
||||
# Basic Blue style sheet with navigation menus
|
||||
@ -171,11 +172,34 @@ def load_on_reg(dbstate, uistate, plugin):
|
||||
if os.path.exists(USER_CSS):
|
||||
list_files = os.listdir(USER_CSS)
|
||||
for cssfile in list_files:
|
||||
CSS_FILES.append([cssfile, 1, cssfile.replace('.css', ''),
|
||||
os.path.join(USER_CSS,cssfile),
|
||||
None, [], [] ])
|
||||
if cssfile.endswith(".css"):
|
||||
css_f = cssfile.replace('.css', '')
|
||||
CSS_FILES.append(["UsEr_" + css_f, 1, css_f,
|
||||
os.path.join(USER_CSS, cssfile), None,
|
||||
looking_for_urls_in_user_css(cssfile),
|
||||
[]])
|
||||
return CSS_FILES
|
||||
|
||||
def looking_for_urls_in_user_css(css_file):
|
||||
"""
|
||||
At each time we find the tag url, we get the content and add it
|
||||
to the images list. This content must be local.
|
||||
"""
|
||||
images = []
|
||||
cssfile = os.path.join(USER_CSS, css_file)
|
||||
with open(cssfile) as css:
|
||||
data = css.readlines()
|
||||
for line in data:
|
||||
if "url" in line:
|
||||
url = re.match(r".*url\((.*)\)", line)
|
||||
if url.group(1)[0:3] != "http":
|
||||
img = url.group(1).replace("../images/", "")
|
||||
img = os.path.join(USER_CSS, img)
|
||||
if img not in images:
|
||||
images.append('%s' % img)
|
||||
return images
|
||||
|
||||
|
||||
def process_list(data):
|
||||
"""
|
||||
Gather all of the web resources together, and allow override files
|
||||
@ -185,7 +209,7 @@ def process_list(data):
|
||||
for row in data:
|
||||
file = row[3]
|
||||
if file:
|
||||
path, filename = os.path.split(file)
|
||||
dummy_path, filename = os.path.split(file)
|
||||
# is there a override file in the VERSION_DIR/webstuff?
|
||||
# eg, ~/.gramps/gramps34/webstuff/Web_Nebraska.css
|
||||
# if so, replace this one:
|
||||
|
Loading…
Reference in New Issue
Block a user