py3 compatibility

This commit is contained in:
boyska 2018-07-01 13:07:26 +02:00
parent d889b610a4
commit d3eee582a8
2 changed files with 15 additions and 5 deletions

View file

@ -32,3 +32,12 @@ vim talks/MIOTALK/meta.yaml
Quindi rifai `make publish` come spiegato prima: l'output ti informa di eventuali errori nei campi o Quindi rifai `make publish` come spiegato prima: l'output ti informa di eventuali errori nei campi o
sovrapposizioni con altri talk, leggilo! sovrapposizioni con altri talk, leggilo!
Hacking
---------
Il sito è un'istanza di pelican, più alcuni plugin custom: langmenu, per avere un menu che punta alle versioni
localizzate della pagina; talks, per gestire i talk in modo speciale.
Il tutto richiede python 2.7, ma dal prossimo anno si potrebbe passare a python 3. Quindi cerca di tenere la
compatibilità, se metti mano al codice python.

View file

@ -20,6 +20,7 @@ from babel.dates import format_date, format_datetime, format_time
from markdown import markdown from markdown import markdown
from docutils import nodes from docutils import nodes
from docutils.parsers.rst import directives, Directive from docutils.parsers.rst import directives, Directive
import six
from pelican import signals, generators from pelican import signals, generators
import jinja2 import jinja2
@ -120,14 +121,14 @@ def get_talk_data(talkname):
data.setdefault('nooverlap', []) data.setdefault('nooverlap', [])
if 'title' not in data: if 'title' not in data:
logging.warn("Talk <{}> has no `title` field".format(talkname)) logging.warn("Talk <{}> has no `title` field".format(talkname))
data['title'] = unicode(talkname) data['title'] = six.text_type(talkname)
else: else:
data['title'] = unicode(data['title']) data['title'] = six.text_type(data['title'])
if 'text' not in data: if 'text' not in data:
logging.warn("Talk <{}> has no `text` field".format(talkname)) logging.warn("Talk <{}> has no `text` field".format(talkname))
data['text'] = '' data['text'] = ''
else: else:
data['text'] = unicode(data['text']) data['text'] = six.text_type(data['text'])
if 'duration' not in data: if 'duration' not in data:
logging.info("Talk <{}> has no `duration` field (50min used)" logging.info("Talk <{}> has no `duration` field (50min used)"
.format(talkname)) .format(talkname))
@ -371,7 +372,7 @@ def talks_to_ics():
e = talk_to_ics(t) e = talk_to_ics(t)
if e is not None: if e is not None:
c.events.add(e) c.events.add(e)
return unicode(c) return six.text_type(c)
def talk_to_ics(talk): def talk_to_ics(talk):
@ -379,7 +380,7 @@ def talk_to_ics(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=unidecode.unidecode(talk['title']),
begin=talk['time'], begin=talk['time'],
duration=datetime.timedelta(minutes=talk['duration']), duration=datetime.timedelta(minutes=talk['duration']),