Commit a293be34 authored by Matthieu Boileau's avatar Matthieu Boileau
Browse files

Merge branch 'dev-calendar' into 'master'

ical: fix subpage issue

See merge request !6
parents 12eeecfd 3fa4f636
Pipeline #19404 passed with stages
in 17 seconds
......@@ -576,73 +576,13 @@ class IndexPage(Page):
use_unicode=True)
self.data.events.append(sem_event)
def _export_ical(self):
"""
Export the ical file (used only for seminar pages)
Limit to less than one-year old events
"""
def add_event(ical_events: list, sem_event):
"""Add a node to lunr json"""
dstart = sem_event['date']
try:
dend = sem_event['date_end']
except KeyError:
dend = dstart + timedelta(hours=1)
ical_event = {
'summary': sem_event['title'],
'dstart': dstart,
'dtend': dend
}
if 'url' in self.conf.site:
ical_event['url'] = \
f"{self.conf.site['url']}/{self.html_path.as_posix()}"
else:
ical_event['url'] = self.html_path.as_posix()
try:
ical_event['location'] = sem_event['place']
except KeyError:
pass
try:
ical_event['description'] = sem_event['abstract']
except KeyError:
pass
ical_events.append(ical_event)
ical_events = []
for sem_event in self.events:
if (sem_event['date'].date() >=
self.conf.site['today'] - timedelta(days=365)):
add_event(ical_events, sem_event)
prodid = (f"\
-//{self.conf.site['calendar']['organization']}//{self.seminar['type']} "
f"{self.title}//FR")
ical_content = build_calendar(prodid, ical_events)
ical_filepath = Path(self._get_filename()).with_suffix('.ics')
ical_outpath = self.conf.output_path / ical_filepath
log.debug(f"Export ical file to {ical_outpath}")
ical_outpath.write_text(ical_content)
if 'url' in self.conf.site:
self.ical_url = \
f"{self.conf.site['url']}/{ical_filepath}"
else:
self.ical_url = ical_outpath.as_posix()
def render(self):
# Export ical file for seminars only
export_ical = self.category == 'séminaire' \
and 'calendar' in self.conf.site
log.debug(f"Rendering {self.filepath}")
if self.subpages:
for subpage in self.subpages:
if export_ical:
subpage._export_ical()
subpage.render()
self.rendered += subpage.rendered # Increment counter
else:
if export_ical:
self._export_ical()
super().render()
......@@ -779,6 +719,59 @@ class SeminarPage(IndexPage):
self.seminar['html_path'] = html_path
return html_path
def _export_ical(self):
"""
Export the ical file for the seminar
Limit to less than one-year old events
"""
def add_event(ical_events: list, sem_event):
"""Add a node to lunr json"""
dstart = sem_event['date']
try:
dend = sem_event['date_end']
except KeyError:
dend = dstart + timedelta(hours=1)
ical_event = {
'summary': sem_event['title'],
'dstart': dstart,
'dtend': dend
}
if 'url' in self.conf.site:
ical_event['url'] = \
f"{self.conf.site['url']}/{self.html_path.as_posix()}"
else:
ical_event['url'] = self.html_path.as_posix()
try:
ical_event['location'] = sem_event['place']
except KeyError:
pass
try:
ical_event['description'] = sem_event['abstract']
except KeyError:
pass
ical_events.append(ical_event)
ical_events = []
for sem_event in self.events:
if (sem_event['date'].date() >=
self.conf.site['today'] - timedelta(days=365)):
add_event(ical_events, sem_event)
prodid = (f"\
-//{self.conf.site['calendar']['organization']}//{self.seminar['type']} "
f"{self.title}//FR")
ical_content = build_calendar(prodid, ical_events)
ical_filepath = Path(self._get_filename()).with_suffix('.ics')
ical_outpath = self.conf.output_path / ical_filepath
log.debug(f"Export ical file to {ical_outpath}")
ical_outpath.write_text(ical_content)
if 'url' in self.conf.site:
self.ical_url = \
f"{self.conf.site['url']}/{ical_filepath}"
else:
self.ical_url = ical_outpath.as_posix()
def get_index_node(self) -> list:
"""Overload get_index_node() for seminar pages"""
......@@ -803,6 +796,15 @@ class SeminarPage(IndexPage):
return index_nodes
def render(self):
"""Export ical file before rendering"""
if 'calendar' in self.conf.site:
self._export_ical()
if self.subpages: # Populate subpages with ical_url
for subpage in self.subpages:
subpage.ical_url = self.ical_url
return super().render()
class SeminarTopIndexPage(Page):
"""A class to build the seminars top index page (actifs/passés)"""
......
......@@ -326,7 +326,7 @@ SUMMARY:Admettre propre existence crainte mot prochain bas
DTSTART;VALUE=DATE-TIME:20180625T042207
DTEND;VALUE=DATE-TIME:20180625T052207
DTSTAMP;VALUE=DATE-TIME:20180625T042207Z
UID:b4862b21-fb97-d435-8856-1712e8e5216a
UID:e443df78-9558-867f-5ba9-1faf7a024204
DESCRIPTION:Selon empêcher problème nuage. Paysan époque voici avenir f
leur déjà. Compte avenir divers verre. Se avant plutôt mine demander. S
érieux que prison. Profond doucement descendre prouver type. Expérience
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment