Commit b1e6c34e authored by Roland Denis's avatar Roland Denis
Browse files

Merge branch 'master' into dev-page-meso

parents f1e087c0 3db0b5ca
Pipeline #9821 passed with stages
in 57 seconds
......@@ -6,3 +6,4 @@ __pycache__
.vscode/
venv/
*.pyc
.env/
import locale
from docutils.parsers.rst import directives, Directive
from docutils.parsers.rst.directives.parts import Contents
from docutils.transforms import frontmatter
......@@ -9,6 +10,9 @@ from pelican.readers import PelicanHTMLTranslator
import re
from jinja2 import Environment, FileSystemLoader
import os
import logging
logger = logging.getLogger(__name__)
from . import indico
......@@ -18,7 +22,6 @@ num_day = 0
num_event = 0
# set locale in order to have french date for output string
import locale
locale.setlocale(locale.LC_TIME, "fr_FR.UTF-8")
# define new nodes
......@@ -26,18 +29,23 @@ locale.setlocale(locale.LC_TIME, "fr_FR.UTF-8")
class schedule(nodes.General, nodes.Element):
""" schedule node """
class day(nodes.General, nodes.Element):
""" day node """
class event(nodes.General, nodes.Element):
""" event node """
class event_content(nodes.General, nodes.Element):
""" event content node """
class break_event(nodes.General, nodes.Element):
""" break event node """
class button(nodes.General, nodes.Element):
""" button node """
......@@ -71,16 +79,19 @@ class Schedule(Directive):
source = self.options['indico_url']
event = self.options['indico_event']
content = indico.indico_event_to_rst(source, event)
if content != None: #we are online
if content: # we are online
content = content.split('\n')
self.state.nested_parse(StringList(content), len(content), sche)
else: # we are offline and nothing is fetched from indico
self.state.nested_parse(self.content, self.content_offset, sche)
self.state.nested_parse(
StringList(content), len(content), sche)
else: # we are offline and nothing is fetched from indico
self.state.nested_parse(
self.content, self.content_offset, sche)
else:
self.assert_has_content()
return [sche]
class Day(Directive):
required_arguments = 1
optional_arguments = 0
......@@ -92,7 +103,7 @@ class Day(Directive):
global num_day
# Raise an error if the directive does not have contents.
self.assert_has_content()
d = day(classes=['day-color2' if num_day&1 else 'day-color1'])
d = day(classes=['day-color2' if num_day & 1 else 'day-color1'])
d['num_day'] = num_day
d['day'] = dateutil.parser.parse(self.arguments[0], dayfirst=True)
d['show'] = True
......@@ -100,18 +111,21 @@ class Day(Directive):
num_day += 1
return [d]
def support_converter(s):
pattern = re.compile("\[(.*?)\]\((.*?)\)")
supports = list()
for line in s.splitlines():
matches = pattern.match(line)
if matches:
supports.append( {'name': matches.group(1), 'url': directives.uri(matches.group(2))} )
supports.append({'name': matches.group(
1), 'url': directives.uri(matches.group(2))})
else:
supports.append( {'name': None, 'url': directives.uri(line)} )
supports.append({'name': None, 'url': directives.uri(line)})
return supports
class Event(Directive):
required_arguments = 1
optional_arguments = 0
......@@ -150,6 +164,7 @@ class Event(Directive):
num_event += 1
return [node]
class Break(Directive):
required_arguments = 1
optional_arguments = 0
......@@ -171,6 +186,7 @@ class Break(Directive):
num_event += 1
return [node]
class Button(Directive):
required_arguments = 1
optional_arguments = 0
......@@ -213,13 +229,14 @@ class myHTMLTranslator(PelicanHTMLTranslator):
self.body.append('</div>\n')
def visit_day(self, node):
self.body.append('<div class="day %s">\n'%' '.join(node['classes']))
self.body.append('<div class="day %s">\n' % ' '.join(node['classes']))
def depart_break_event(self, node):
pass
def visit_break_event(self, node):
self.body.extend(self.template.render(node=node, node_type='break').splitlines(True))
self.body.extend(self.template.render(
node=node, node_type='break').splitlines(True))
if (isinstance(node.parent, day) and node.parent['show']):
node.parent['show'] = False
......@@ -228,14 +245,16 @@ class myHTMLTranslator(PelicanHTMLTranslator):
self.body.append('</div>\n')
def visit_event_content(self, node):
self.body.append('<div id="collapseDetails%d" class="row collapse in pb-3">\n'%node['id'])
self.body.append(
'<div id="collapseDetails%d" class="row collapse in pb-3">\n' % node['id'])
self.body.append('<div class="offset-md-3 col-md-9 event-content">\n')
def depart_event(self, node):
pass
def visit_event(self, node):
self.body.extend(self.template.render(node=node, node_type='speaker').splitlines(True))
self.body.extend(self.template.render(
node=node, node_type='speaker').splitlines(True))
if (isinstance(node.parent, day) and node.parent['show']):
node.parent['show'] = False
......@@ -243,7 +262,8 @@ class myHTMLTranslator(PelicanHTMLTranslator):
self.body.append('<div class="savoirplus">\n')
if node['blank']:
self.body.append('<a href={} target="_blank" rel="noopener noreferrer">\n'.format(node['target']))
self.body.append(
'<a href={} target="_blank" rel="noopener noreferrer">\n'.format(node['target']))
else:
self.body.append('<a href={}>\n'.format(node['target']))
......@@ -265,3 +285,4 @@ def register():
directives.register_directive('break_event', Break)
directives.register_directive('day', Day)
directives.register_directive('button', Button)
......@@ -29,12 +29,16 @@ def indico_event_to_rst(url, event):
import collections
from urllib.request import urlopen
import json
import ssl
context = ssl.SSLContext()
try:
print(url + '/export/timetable/' + str(event) + ".json")
response = urlopen(url + '/export/timetable/' + str(event) + ".json").read()
except:
print("WARNING: indico content could not be fetched, no programme will be built. Offline ?")
response = urlopen(url + '/export/timetable/' + str(event) + ".json",
context=context).read()
except Exception as e:
logger.warning(
"indico content could not be fetched because of : {}".format(e))
return None
data = json.loads(response.decode('utf-8'))
......@@ -45,10 +49,14 @@ def indico_event_to_rst(url, event):
day = schedule.get(date, {})
for k, v in day_v.items():
start_time_str = v['startDate']['date'] + 'T' + v['startDate']['time'] + 'Z'
end_time_str = v['endDate']['date'] + 'T' + v['endDate']['time'] + 'Z'
start_time = maya.parse(start_time_str).datetime(to_timezone='Europe/Paris', naive=False)
end_time = maya.parse(end_time_str).datetime(to_timezone='Europe/Paris', naive=False)
start_time_str = v['startDate']['date'] + \
'T' + v['startDate']['time'] + 'Z'
end_time_str = v['endDate']['date'] + \
'T' + v['endDate']['time'] + 'Z'
start_time = maya.parse(start_time_str).datetime(
to_timezone='Europe/Paris', naive=False)
end_time = maya.parse(end_time_str).datetime(
to_timezone='Europe/Paris', naive=False)
day[start_time] = {
'start': start_time.strftime("%H:%M"),
......@@ -63,7 +71,8 @@ def indico_event_to_rst(url, event):
speakers.append("Orateur à confirmer")
elif v['presenters'] != []:
for person in v['presenters']:
speakers.append(person['firstName'].capitalize() + ' ' + person['familyName'].capitalize())
speakers.append(person['firstName'].capitalize(
) + ' ' + person['familyName'].capitalize())
else:
speakers.append("Orateur à confirmer")
......
......@@ -44,7 +44,8 @@ class Section(Directive):
[('[^\\w\\s-]', ''), ('(?u)\\A\\s*', ''), ('(?u)\\s*\\Z', ''), ('[-\\s]+', '-')])])
section['class'] = self.options.get('class', [])
section += nodes.title(self.arguments[0], self.arguments[0], classes=['toc'], refid=section['ids'][0])
section += nodes.title(self.arguments[0], self.arguments[0],
classes=['toc'], refid=section['ids'][0])
blockquote = nodes.block_quote(classes=['content'])
section += blockquote
self.state.nested_parse(self.content, self.content_offset, blockquote)
......@@ -75,7 +76,8 @@ class myHTMLTranslator(PelicanHTMLTranslator):
def visit_section(self, node):
super(myHTMLTranslator, self).visit_section(node)
if node.hasattr('class') and self.section_level == 1:
self.body.append('<div class="container-fluid part {}">\n'.format(' '.join(node['class'])))
self.body.append(
'<div class="container-fluid part {}">\n'.format(' '.join(node['class'])))
self.body.append('<div class="block">\n')
......
Markdown is supported
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