Commit b0cd3e89 authored by Julian Rother's avatar Julian Rother
Browse files

Add simple DB connection and adopt templates to use it

parent 2ffe2814
#!/bin/python
from flask import Flask, render_template
from flask import Flask, render_template, g
import mysql.connector
import config
app = Flask(__name__)
def query(operation, *params):
if 'db' not in g or not g.db.is_connected():
g.db = mysql.connector.connect(user=config.db_user, password=config.db_passwd, host=config.db_host, database=config.db_db)
cur = g.db.cursor(dictionary=True)
cur.execute(operation, params)
return cur.fetchall()
@app.route('/')
def index():
return render_template('index.html', latestvideos=[{'talk':{'title':'talktitle','thumbnail':'https://videoag.fsmpi.rwth-aachen.de/pub/thumbnails/16ss-hyp-160802-Geophysical_models_IV.jpg','id':123,'comment':'comment','date':'date'},'event':{'title':'eventtitle'}},{'talk':{'title':'talktitle','thumbnail':'https://videoag.fsmpi.rwth-aachen.de/pub/thumbnails/16ss-hyp-160802-Geophysical_models_IV.jpg','id':123,'comment':'comment','date':'date'},'event':{'title':'eventtitle'}},{'talk':{'title':'talktitle','thumbnail':'https://videoag.fsmpi.rwth-aachen.de/pub/thumbnails/16ss-hyp-160802-Geophysical_models_IV.jpg','id':123,'comment':'comment','date':'date'},'event':{'title':'eventtitle'}},{'talk':{'title':'talktitle','thumbnail':'https://videoag.fsmpi.rwth-aachen.de/pub/thumbnails/16ss-hyp-160802-Geophysical_models_IV.jpg','id':123,'comment':'comment','date':'date'},'event':{'title':'eventtitle'}}])
return render_template('index.html', latestvideos=query('''
SELECT lectures.*, max(videos.time_updated) AS lastvidtime, courses.downloadable, courses.title AS coursetitle
FROM lectures
LEFT JOIN videos ON (videos.lecture_id = lectures.id)
LEFT JOIN courses on (courses.id = lectures.course_id)
WHERE (videos.time_updated >= SUBDATE(NOW(), 14))
AND (%s OR (courses.visible AND courses.listed AND lectures.visible AND videos.visible))
GROUP BY videos.lecture_id
ORDER BY lastvidtime DESC
LIMIT 5
''', False))
@app.route('/videos')
def videos():
......
......@@ -36,7 +36,7 @@
<div class="panel-body">
<ul class="list-group videopreview">
{% for i in latestvideos %}
{{ preview(i['talk'],i['event']) }}
{{ preview(i) }}
{% endfor %}
</ul>
</div>
......
{% macro preview(talk,event) %}
{% macro preview(lecture) %}
<li class="list-group-item">
<div class="row">
<a href="?view=player&amp;lectureid={{ talk['id'] }}#content" title="{{ event['title'] }}">
<img class="col-xs-4" src="{{ talk['thumbnail'] }}" alt="Vorschaubild">
<a href="?view=player&amp;lectureid={{ lecture['id'] }}#content" title="{{ lecture['coursetitle'] }}">
<img class="col-xs-4" src="https://videoag.fsmpi.rwth-aachen.de/{{ lecture['titlefile'] }}" alt="Vorschaubild">
<div class="col-xs-4">
<span>{{ event['title'] }}</span>
<span>{{ talk['date'] }}</span>
<p>{{ talk['title'] }}</p>
<span>{{ lecture['coursetitle'] }}</span>
<span>{{ lecture['time'] }}</span>
<p>{{ lecture['title'] }}</p>
</div>
<div class="col-xs-4">
<div class="comment">{{ talk['comment'] }}</div>
<div class="comment">Gehalten von {{ talk['speaker']|default('unbekannt') }} </div>
<div class="comment">{{ lecture['comment'] }}</div>
{% if lecture['speaker'] %}
<div class="comment">Gehalten von {{ lecture['speaker'] }} </div>
{% endif %}
</div>
</a>
</div>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment