From 1ec90e2622fe61dddf76fd8995d37b2b003601fb Mon Sep 17 00:00:00 2001 From: Julian Rother <julianr@fsmpi.rwth-aachen.de> Date: Wed, 3 Jan 2018 02:49:08 +0100 Subject: [PATCH] Added timestamp formatting filter "time_offset" and increased rss feed compatability --- template_helper.py | 4 ++++ templates/feed.rss | 6 +++--- templates/lecture.html | 2 +- templates/macros.html | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/template_helper.py b/template_helper.py index 1fee370..cfe252b 100644 --- a/template_helper.py +++ b/template_helper.py @@ -156,6 +156,10 @@ def human_time(d): def rfc3339(d): return d.strftime('%Y-%m-%dT%H:%M:%S+02:00') +@app.template_filter() +def time_offset(s): + return '%02d:%02d:%02d'%(s//3600, (s//60)%60, s%60) + @app.template_filter() def rfc822(d): return formatdate(mktime(d.timetuple())) diff --git a/templates/feed.rss b/templates/feed.rss index 4dd5193..25d078a 100644 --- a/templates/feed.rss +++ b/templates/feed.rss @@ -12,7 +12,7 @@ {%- if chapters|selectattr('lecture_id','equalto',item.id)|list %} <ul> {% for chapter in chapters|selectattr('lecture_id','equalto',item.id) %} -<li>{{ '%02d:%02d:%02d'|format( chapter.time//3600, (chapter.time//60)%60, chapter.time%60) }}: {{ chapter.text }}</li> +<li>{{ chapter.time|time_offset }}: {{ chapter.text }}</li> {% endfor %} </ul> {% endif %} @@ -49,11 +49,11 @@ <dc:creator>{{ item.speaker|e }}</dc:creator> {% endif %} {% if item.video.duration > 0 %} - <itunes:duration>{{ item.video.duration }}</itunes:duration> + <itunes:duration>{{ item.video.duration|time_offset }}</itunes:duration> {% endif %} <psc:chapters xmlns:psc="http://podlove.org/simple-chapters" version="1.2"> {% for chapter in chapters|selectattr('lecture_id','equalto',item.id) %} - <psc:chapter start="{{ chapter.time }}" title="{{ chapter.text }}"/> + <psc:chapter start="{{ chapter.time|time_offset }}" title="{{ chapter.text }}"/> {% endfor %} </psc:chapters> <enclosure url="{{ url_for('files', filename=item.video.path, _external=True) }}" length="{{ item.video.file_size }}" type="{{ format.mimetype }}"/> diff --git a/templates/lecture.html b/templates/lecture.html index f5c780c..e3b8eb6 100644 --- a/templates/lecture.html +++ b/templates/lecture.html @@ -55,7 +55,7 @@ {% for c in chapters|sort(attribute='time') %} <tr> <td> - <a class="chapterlink" href="{{url_for('lecture', course=course.handle, id=lecture.id, t=c['time'])}}" data-seek-time="{{c['time']}}">{{ '%02d:%02d:%02d'|format( c['time']//3600, (c['time']//60)%60, c['time']%60) }}</a> + <a class="chapterlink" href="{{url_for('lecture', course=course.handle, id=lecture.id, t=c['time'])}}" data-seek-time="{{c['time']}}">{{ c.time|time_offset }}</a> <br> {% if ismod() %} {{ moderator_editor(['chapters',c.id,'time'],c['time'],true) }} diff --git a/templates/macros.html b/templates/macros.html index ea67c2a..70fed19 100644 --- a/templates/macros.html +++ b/templates/macros.html @@ -358,7 +358,7 @@ $('#embedcodebtn').popover( {% endmacro %} -{% macro vtttime(time) %}{{ '%02d:%02d:%02d.000'|format( time//3600, (time//60)%60, time%60) }}{% endmacro %} +{% macro vtttime(time) %}{{ time|time_offset }}.000{% endmacro %} {% macro stats_viewsperday(id, req, title, type="scatter", param=None, maxtraces=7) %} <script> -- GitLab