|
# ``year`` is the current year: datetime.datetime.now().year
|
|
# ``talks`` is a list of processed form entries
|
|
|
|
from jinja2 import Template, Environment, select_autoescape, pass_eval_context
|
|
from markupsafe import Markup, escape
|
|
from IPython.core.display import HTML
|
|
import re
|
|
|
|
env = Environment(autoescape=select_autoescape(['html', 'xml']))
|
|
|
|
_paragraph_re = re.compile(r'(?:\r\n|\r(?!\n)|\n){2,}')
|
|
|
|
@pass_eval_context
|
|
def nl2br(eval_ctx, value):
|
|
result = u'\n\n'.join(u'<p>%s</p>' % p.replace('\n', Markup('<br>\n'))
|
|
for p in _paragraph_re.split(jinja2.filters.escape(value)))
|
|
result = re.sub(r'(https?[/\-.:a-zA-Z0-9_]+)',r'<a href="\1">\1</a>',result)
|
|
if eval_ctx.autoescape:
|
|
result = Markup(result)
|
|
return result
|
|
|
|
env.filters['br'] = nl2br
|
|
|
|
template = env.from_string("""
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>EAMS {{year}} talk submissions</title>
|
|
<style>
|
|
li {
|
|
margin: 0.5em 0;
|
|
}
|
|
|
|
article {
|
|
width: 40rem;
|
|
margin: 5rem auto 0 auto;
|
|
line-height: 1.5em;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>EAMS {{year}} talk submissions</h1>
|
|
<ul>
|
|
{% for talk in talks %}
|
|
<li><a href="#talk-{{loop.index}}">{{talk.title}}</a></li>
|
|
{% endfor %}
|
|
</ul>
|
|
{% for talk in talks %}
|
|
<article id="talk-{{loop.index}}">
|
|
<h1 style="font-size: 1.2em; font-weight: bold">{{talk.title|br}}</h1>
|
|
<p>{{talk.names|br}}</p>
|
|
<p><a href="mailto:{{talk.email}}">{{talk.email}}</a></p>
|
|
<p style="font-style: italic">{{talk.format}}</p>
|
|
<p>{{talk.timezone}}</p>
|
|
<p>{{talk.description|br}}</p>
|
|
{% if talk.notes %}<p><strong>Notes:</strong> {{talk.notes|br}}</p>{% endif %}
|
|
</article>
|
|
{% endfor %}
|
|
</body>
|
|
</html>""")
|
|
|
|
h = template.render(year=year, talks=sorted(talks,key=lambda t: re.sub(r'\W','',t['title'].lower())))
|
|
|
|
with open('talks.html','w') as f:
|
|
f.write(h)
|