|
@@ -12,6 +12,9 @@ import datetime
|
|
|
import shutil
|
|
|
import time
|
|
|
from copy import copy
|
|
|
+import locale
|
|
|
+from contextlib import contextmanager
|
|
|
+from babel.dates import format_date, format_datetime, format_time
|
|
|
|
|
|
import markdown
|
|
|
from docutils import nodes
|
|
@@ -42,6 +45,15 @@ def memoize(function):
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
+@contextmanager
|
|
|
+def setlocale(name):
|
|
|
+ saved = locale.setlocale(locale.LC_ALL)
|
|
|
+ try:
|
|
|
+ yield locale.setlocale(locale.LC_ALL, name)
|
|
|
+ finally:
|
|
|
+ locale.setlocale(locale.LC_ALL, saved)
|
|
|
+
|
|
|
+
|
|
|
@memoize
|
|
|
def get_talk_names():
|
|
|
return [name for name in os.listdir(TALKS_PATH)
|
|
@@ -140,18 +152,23 @@ jinja_env = jinja2.Environment(
|
|
|
jinja_env.filters['markdown'] = lambda text: \
|
|
|
jinja2.Markup(markdown.Markdown(extensions=['meta']).
|
|
|
convert(text))
|
|
|
+jinja_env.filters['dateformat'] = format_date
|
|
|
+jinja_env.filters['datetimeformat'] = format_datetime
|
|
|
+jinja_env.filters['timeformat'] = format_time
|
|
|
|
|
|
|
|
|
class TalkListDirective(Directive):
|
|
|
- required_arguments = 0
|
|
|
- optional_arguments = 0
|
|
|
final_argument_whitespace = True
|
|
|
has_content = True
|
|
|
+ option_spec = {
|
|
|
+ 'lang': directives.unchanged
|
|
|
+ }
|
|
|
|
|
|
def run(self):
|
|
|
+ lang = self.options.get('lang', 'C')
|
|
|
tmpl = jinja_env.get_template('talk.html')
|
|
|
return [
|
|
|
- nodes.raw('', tmpl.render(**get_talk_data(n)),
|
|
|
+ nodes.raw('', tmpl.render(lang=lang, **get_talk_data(n)),
|
|
|
format='html')
|
|
|
for n in get_talk_names()
|
|
|
]
|
|
@@ -159,30 +176,34 @@ class TalkListDirective(Directive):
|
|
|
|
|
|
class TalkDirective(Directive):
|
|
|
required_arguments = 1
|
|
|
- optional_arguments = 0
|
|
|
final_argument_whitespace = True
|
|
|
has_content = True
|
|
|
+ option_spec = {
|
|
|
+ 'lang': directives.unchanged
|
|
|
+ }
|
|
|
|
|
|
def run(self):
|
|
|
+ lang = self.options.get('lang', 'C')
|
|
|
tmpl = jinja_env.get_template('talk.html')
|
|
|
data = get_talk_data(self.arguments[0])
|
|
|
if data is None:
|
|
|
return []
|
|
|
return [
|
|
|
- nodes.raw('', tmpl.render(**data),
|
|
|
+ nodes.raw('', tmpl.render(lang=lang, **data),
|
|
|
format='html')
|
|
|
]
|
|
|
|
|
|
|
|
|
class TalkGridDirective(Directive):
|
|
|
'''A complete grid'''
|
|
|
- required_arguments = 0
|
|
|
-
|
|
|
- optional_arguments = 0
|
|
|
final_argument_whitespace = True
|
|
|
has_content = True
|
|
|
+ option_spec = {
|
|
|
+ 'lang': directives.unchanged
|
|
|
+ }
|
|
|
|
|
|
def run(self):
|
|
|
+ lang = self.options.get('lang', 'C')
|
|
|
tmpl = jinja_env.get_template('grid.html')
|
|
|
output = []
|
|
|
days = unique_attr(all_talks(), 'day')
|
|
@@ -222,13 +243,15 @@ class TalkGridDirective(Directive):
|
|
|
times[position + i*GRID_STEP][roomnum] = copy(talk)
|
|
|
times[position + i*GRID_STEP][roomnum]['skip'] = True
|
|
|
|
|
|
+ #with setlocale(locale.normalize(lang)):
|
|
|
render = tmpl.render(times=times,
|
|
|
rooms=rooms,
|
|
|
mintime=mintime, maxtime=maxtime,
|
|
|
timestep=GRID_STEP,
|
|
|
+ lang=lang,
|
|
|
)
|
|
|
output.append(nodes.raw('', u'<h4>%s</h4>' %
|
|
|
- day.strftime('%A %d').decode('utf8').title(),
|
|
|
+ format_date(day, format='full', locale=lang),
|
|
|
format='html'))
|
|
|
output.append(nodes.raw('', render, format='html'))
|
|
|
return output
|