Merge branch 'master' of https://git.lattuga.net/boyska/sito-hackit-18
This commit is contained in:
commit
bbffdf9bb6
1 changed files with 26 additions and 15 deletions
|
@ -11,7 +11,6 @@ import logging
|
||||||
import re
|
import re
|
||||||
import datetime
|
import datetime
|
||||||
import shutil
|
import shutil
|
||||||
import time
|
|
||||||
from copy import copy
|
from copy import copy
|
||||||
import locale
|
import locale
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
@ -37,8 +36,6 @@ import dateutil
|
||||||
pelican = None # This will be set during register()
|
pelican = None # This will be set during register()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def memoize(function):
|
def memoize(function):
|
||||||
'''decorators to cache'''
|
'''decorators to cache'''
|
||||||
memo = {}
|
memo = {}
|
||||||
|
@ -111,7 +108,7 @@ def get_talk_data(talkname):
|
||||||
with io.open(fname, encoding='utf8') as buf:
|
with io.open(fname, encoding='utf8') as buf:
|
||||||
try:
|
try:
|
||||||
data = yaml.load(buf)
|
data = yaml.load(buf)
|
||||||
except:
|
except Exception:
|
||||||
logging.exception("Syntax error reading %s; skipping", fname)
|
logging.exception("Syntax error reading %s; skipping", fname)
|
||||||
return None
|
return None
|
||||||
if data is None:
|
if data is None:
|
||||||
|
@ -173,14 +170,15 @@ def get_talk_data(talkname):
|
||||||
if os.path.isdir(resdir) and os.listdir(resdir):
|
if os.path.isdir(resdir) and os.listdir(resdir):
|
||||||
data['resources'] = resdir
|
data['resources'] = resdir
|
||||||
return data
|
return data
|
||||||
except:
|
except Exception:
|
||||||
logging.exception("Error on talk %s", talkname)
|
logging.exception("Error on talk %s", talkname)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
def overlap(interval_a, interval_b):
|
def overlap(interval_a, interval_b):
|
||||||
'''how many minutes do they overlap?'''
|
'''how many minutes do they overlap?'''
|
||||||
return max(0, min(interval_a[1], interval_b[1]) - max(interval_a[0], interval_b[0]))
|
return max(0, min(interval_a[1], interval_b[1]) -
|
||||||
|
max(interval_a[0], interval_b[0]))
|
||||||
|
|
||||||
|
|
||||||
def get_talk_overlaps(name):
|
def get_talk_overlaps(name):
|
||||||
|
@ -220,7 +218,9 @@ def check_overlaps():
|
||||||
@memoize
|
@memoize
|
||||||
def jinja_env():
|
def jinja_env():
|
||||||
env = jinja2.Environment(
|
env = jinja2.Environment(
|
||||||
loader=jinja2.FileSystemLoader(os.path.join(pelican.settings['TALKS_PATH'], '_templates')),
|
loader=jinja2.FileSystemLoader(os.path.join(
|
||||||
|
pelican.settings['TALKS_PATH'],
|
||||||
|
'_templates')),
|
||||||
autoescape=True,
|
autoescape=True,
|
||||||
)
|
)
|
||||||
env.filters['markdown'] = lambda text: jinja2.Markup(markdown(text))
|
env.filters['markdown'] = lambda text: jinja2.Markup(markdown(text))
|
||||||
|
@ -311,7 +311,9 @@ class TalkGridDirective(Directive):
|
||||||
rooms.add(r)
|
rooms.add(r)
|
||||||
else:
|
else:
|
||||||
rooms.add(t['room'])
|
rooms.add(t['room'])
|
||||||
rooms = list(sorted(rooms)) # TODO: ordina in base a qualcosa nel meta.yaml globale
|
# TODO: ordina in base a qualcosa nel meta.yaml globale
|
||||||
|
rooms = list(sorted(rooms))
|
||||||
|
|
||||||
# room=* is not a real room.
|
# room=* is not a real room.
|
||||||
# Remove it unless that day only has special rooms
|
# Remove it unless that day only has special rooms
|
||||||
if '*' in rooms and len(rooms) > 1:
|
if '*' in rooms and len(rooms) > 1:
|
||||||
|
@ -376,12 +378,18 @@ def talks_to_ics():
|
||||||
|
|
||||||
|
|
||||||
def talk_to_ics(talk):
|
def talk_to_ics(talk):
|
||||||
|
def _decode(s):
|
||||||
|
if six.PY2:
|
||||||
|
return unidecode.unidecode(s)
|
||||||
|
else:
|
||||||
|
return s
|
||||||
|
|
||||||
if 'time' not in talk or 'duration' not in talk:
|
if 'time' not in talk or 'duration' not in talk:
|
||||||
return None
|
return None
|
||||||
e = ics.Event(
|
e = ics.Event(
|
||||||
uid="%s@%d.hackmeeting.org" % (talk['id'],
|
uid="%s@%d.hackmeeting.org" % (talk['id'],
|
||||||
get_global_data()['startdate'].year),
|
get_global_data()['startdate'].year),
|
||||||
name=unidecode.unidecode(talk['title']),
|
name=_decode(talk['title']),
|
||||||
begin=talk['time'],
|
begin=talk['time'],
|
||||||
duration=datetime.timedelta(minutes=talk['duration']),
|
duration=datetime.timedelta(minutes=talk['duration']),
|
||||||
transparent=True,
|
transparent=True,
|
||||||
|
@ -390,7 +398,7 @@ def talk_to_ics(talk):
|
||||||
# unidecode replaces letters with their most similar ASCII counterparts
|
# unidecode replaces letters with their most similar ASCII counterparts
|
||||||
# (ie: accents get stripped)
|
# (ie: accents get stripped)
|
||||||
if 'text' in talk:
|
if 'text' in talk:
|
||||||
e.description = unidecode.unidecode(talk['text'])
|
e.description = _decode(talk['text'])
|
||||||
e.url = pelican.settings['SCHEDULEURL'] + '#talk-' + talk['id']
|
e.url = pelican.settings['SCHEDULEURL'] + '#talk-' + talk['id']
|
||||||
if 'room' in talk:
|
if 'room' in talk:
|
||||||
e.location = talk['room']
|
e.location = talk['room']
|
||||||
|
@ -413,17 +421,19 @@ class TalksGenerator(generators.Generator):
|
||||||
if 'resources' in self.talks[talkname]:
|
if 'resources' in self.talks[talkname]:
|
||||||
outdir = os.path.join(self.output_path,
|
outdir = os.path.join(self.output_path,
|
||||||
pelican.settings['TALKS_PATH'], talkname,
|
pelican.settings['TALKS_PATH'], talkname,
|
||||||
pelican.settings['TALKS_ATTACHMENT_PATH'])
|
pelican.settings['TALKS_ATTACHMENT_PATH']
|
||||||
|
)
|
||||||
if os.path.isdir(outdir):
|
if os.path.isdir(outdir):
|
||||||
shutil.rmtree(outdir)
|
shutil.rmtree(outdir)
|
||||||
shutil.copytree(self.talks[talkname]['resources'], outdir)
|
shutil.copytree(self.talks[talkname]['resources'], outdir)
|
||||||
if ICS_ENABLED:
|
if ICS_ENABLED:
|
||||||
with io.open(os.path.join(self.output_path, pelican.settings.get('TALKS_ICS')),
|
with io.open(os.path.join(self.output_path,
|
||||||
'w',
|
pelican.settings.get('TALKS_ICS')),
|
||||||
encoding='utf8') as buf:
|
'w', encoding='utf8') as buf:
|
||||||
buf.write(talks_to_ics())
|
buf.write(talks_to_ics())
|
||||||
else:
|
else:
|
||||||
logging.warning('module `ics` not found. ICS calendar will not be generated')
|
logging.warning('module `ics` not found. '
|
||||||
|
'ICS calendar will not be generated')
|
||||||
|
|
||||||
|
|
||||||
def add_talks_option_defaults(pelican):
|
def add_talks_option_defaults(pelican):
|
||||||
|
@ -441,6 +451,7 @@ def pelican_init(pelicanobj):
|
||||||
global pelican
|
global pelican
|
||||||
pelican = pelicanobj
|
pelican = pelicanobj
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import yaml
|
import yaml
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|
Loading…
Reference in a new issue