Skip to content
Snippets Groups Projects
Commit 9d97872c authored by Julian Rother's avatar Julian Rother
Browse files

Simplify many queries with new column grouping feature

parent 6a6047c0
No related branches found
No related tags found
No related merge requests found
......@@ -20,25 +20,22 @@ def feed(handle=None):
course['atomid'] = gen_atomid('Video AG, courses['+str(course['id'])+']: '+course['handle'])
id = course['id']
entries = query('''
SELECT lectures.*, videos.file_size, videos.path, videos.id AS video_id, videos.hash,
videos.time_created AS video_created, videos.time_updated AS video_updated,
courses.title AS course_title, courses.handle AS course_handle, courses.semester, courses.organizer AS course_organizer, courses.short as course_short,
formats.description AS format_description, formats.prio
SELECT lectures.*, "video" AS sep, videos.*, formats.description AS format_description, formats.prio, "course" AS sep, courses.*
FROM lectures
JOIN courses ON (courses.id = lectures.course_id)
JOIN videos ON (lectures.id = videos.lecture_id)
JOIN formats ON (formats.id = videos.video_format)
WHERE ((? IS NULL AND courses.listed) OR course_id = ?) AND courses.visible AND lectures.visible AND videos.visible
ORDER BY video_created DESC, prio ASC
ORDER BY videos.time_created DESC, prio ASC
LIMIT 100''',
course['id'], course['id'])
updated = max(course['time_updated'], course['time_created'], key=fixdate)
for entry in entries:
entry['updated'] = max(entry['video_created'], entry['video_updated'], entry['time_created'], entry['time_updated'], key=fixdate)
if len(entry['hash']) != 32:
entry['updated'] = max(entry['video']['time_created'], entry['video']['time_updated'], entry['time_created'], entry['time_updated'], key=fixdate)
if len(entry['video']['hash']) != 32:
entry['atomid'] = gen_atomid('Video AG, videos['+str(entry['video_id'])+']')
else:
entry['atomid'] = 'urn:md5:'+(entry['hash'].upper())
entry['atomid'] = 'urn:md5:'+(entry['video']['hash'].upper())
updated = max(updated, entry['updated'], key=fixdate)
course['updated'] = updated
return Response(render_template('feed.atom', course=course, entries=entries), 200, {'Content-Type': 'application/atom+xml'})
......
......@@ -130,7 +130,7 @@ def index():
start = date.today() - timedelta(days=1)
end = start + timedelta(days=7)
upcomming = query('''
SELECT lectures.*,courses.short, courses.title AS course_title
SELECT lectures.*, "course" AS sep, courses.*
FROM lectures
JOIN courses ON (lectures.course_id = courses.id)
WHERE (time > ?) AND (time < ?) and lectures.visible and courses.visible and courses.listed
......@@ -138,13 +138,13 @@ def index():
for i in upcomming:
i['date'] = i['time'].date()
latestvideos=query('''
SELECT lectures.*, max(videos.time_updated) AS lastvidtime, courses.short, courses.downloadable, courses.title AS coursetitle
SELECT lectures.*, "course" AS sep, courses.*
FROM lectures
LEFT JOIN videos ON (videos.lecture_id = lectures.id)
LEFT JOIN courses on (courses.id = lectures.course_id)
WHERE (? OR (courses.visible AND courses.listed AND lectures.visible AND videos.visible))
GROUP BY videos.lecture_id
ORDER BY lastvidtime DESC
ORDER BY MAX(videos.time_updated) DESC
LIMIT 6 ''',ismod())
featured = query('SELECT * FROM featured WHERE NOT deleted AND (? OR visible)', ismod())
return render_template('index.html', latestvideos=latestvideos, upcomming=upcomming, featured=featured)
......
{% macro summary(entry) %}
{% if not course.handle %}
Veranstaltung: <a href="{{ url_for('course', handle=entry.course_handle) }}">{{entry.course_title}}</a><br>
{% if entry.course_organizer %}
Veranstalter: {{ entry.course_organizer }}<br>
Veranstaltung: <a href="{{ url_for('course', handle=entry.course.handle) }}">{{entry.course.title}}</a><br>
{% if entry.course.organizer %}
Veranstalter: {{ entry.course.organizer }}<br>
{% endif %}
{% endif %}
{% if entry.speaker %}
......@@ -42,10 +42,10 @@ Veranstalter: {{ course.organizer }}<br>
{% for entry in entries %}
<entry>
<title>{% if not course.handle %}{{ entry.course_short }} {% if entry.semester %}({{ entry.semester|semester }}){% endif %}, {% endif %}{{ entry.time|date }}: {{ entry.title }}</title>
{% if not course.handle and entry.course_organizer %}
<title>{% if not course.handle %}{{ entry.course.short }} {% if entry.course.semester %}({{ entry.course.semester|semester }}){% endif %}, {% endif %}{{ entry.time|date }}: {{ entry.title }}</title>
{% if not course.handle and entry.course.organizer %}
<author>
<name>{{ entry.course_organizer }}</name>
<name>{{ entry.course.organizer }}</name>
</author>
{% endif %}
{% if entry.speaker %}
......@@ -54,7 +54,7 @@ Veranstalter: {{ course.organizer }}<br>
</author>
{% endif %}
<link rel="alternate" href="{{ url_for('lecture', id=entry.id, _external=True) }}"/>
<link rel="enclosure" href="{{ url_for('files', filename=entry.path, _external=True)}}" length="{{ entry.file_size }}"/>
<link rel="enclosure" href="{{ url_for('files', filename=entry.video.path, _external=True)}}" length="{{ entry.video.file_size }}"/>
<id>{{ entry.atomid }}</id>
<updated>{{ entry.updated|rfc3339 }}</updated>
<summary type="html">{{ summary(entry)|e }}</summary>
......
......@@ -77,7 +77,7 @@
<strong>{{ g.grouper|date }}</strong>
{% for i in g.list %}
<li class="list-group-item list-group-item-condensed">
{{i.time|time}} {{i.place}} <a href="{{url_for('course', id=i.course_id)}}">{{i.course_title}}</a>: <a href="{{url_for('course', id=i.course_id)}}#lecture-{{i.id}}">{{i.title}}</a>
{{i.time|time}} {{i.place}} <a href="{{url_for('course', id=i.course_id)}}">{{i.course.title}}</a>: <a href="{{url_for('course', id=i.course_id)}}#lecture-{{i.id}}">{{i.title}}</a>
</li>
{% endfor %}
......
{% macro preview(lecture) %}
<li class="list-group-item">
<a class="hidden-xs" href="{{url_for('lecture', id=lecture['id'])}}" title="{{ lecture['coursetitle'] }}" style="color: #000">
<a class="hidden-xs" href="{{url_for('lecture', id=lecture['id'])}}" title="{{ lecture.course.title }}" style="color: #000">
<div class="row">
<img class="col-xs-4" style="max-height: 100px; width: auto;" src="{{ config.VIDEOPREFIX }}/{{ lecture['titlefile'] }}" alt="Vorschaubild" onerror="this.src='{{url_for('static',filename='no-thumbnail.png')}}'; this.onerror=''; ">
<div class="col-xs-4">
<span><strong>{{ lecture['short'] }}</strong></span><br>
<span><strong>{{ lecture.course.short }}</strong></span><br>
<span>{{ lecture['time'] }}</span>
{% if lecture['speaker'] %}
<div class="small">Gehalten von {{ lecture['speaker'] }} </div>
......@@ -16,13 +16,13 @@
</div>
</div>
</a>
<a class="visible-xs" href="{{url_for('lecture', id=lecture['id'])}}" title="{{ lecture['coursetitle'] }}" style="color: #000">
<a class="visible-xs" href="{{url_for('lecture', id=lecture['id'])}}" title="{{ lecture.course.title }}" style="color: #000">
<ul class="list-unstyled">
<li>
<img style="width: 100%;" src="{{ config.VIDEOPREFIX }}/{{ lecture['titlefile'] }}" alt="Vorschaubild" onerror="this.src='{{url_for('static',filename='no-thumbnail.png')}}'; this.onerror=''; ">
</li>
<li>
<strong>{{ lecture['short'] }}</strong> {{ lecture['time'] }}
<strong>{{ lecture.course.short }}</strong> {{ lecture['time'] }}
</li>
{% if lecture['speaker'] %}
<li>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment