Commit 046db0a5 authored by Julian Rother's avatar Julian Rother
Browse files

Replaced ordering number generation with sql trigger

parent 0b7f0e00
......@@ -223,7 +223,7 @@ CREATE TABLE IF NOT EXISTS `featured` (
`type` varchar(32) NOT NULL DEFAULT '',
`param` text NOT NULL DEFAULT '',
`param2` text NOT NULL DEFAULT '',
`order` INTEGER NOT NULL,
`order` INTEGER DEFAULT NULL,
`visible` INTEGER NOT NULL DEFAULT 0,
`deleted` INTEGER NOT NULL DEFAULT 0,
`time_created` datetime NOT NULL,
......@@ -272,4 +272,5 @@ CREATE VIEW IF NOT EXISTS `courses` AS select * from `courses_data` where (not(`
CREATE VIEW IF NOT EXISTS `lectures` AS select `lectures_data`.* from `lectures_data` join `courses_data` on (`courses_data`.`id` = `course_id`) where (not(`lectures_data`.`deleted` or `courses_data`.`deleted`));
CREATE VIEW IF NOT EXISTS `videos` AS select `videos_data`.* from `videos_data` join `lectures_data` on (`lectures_data`.`id` = `lecture_id`) join `courses_data` on (`courses_data`.`id` = `course_id`) where (not(`videos_data`.`deleted` or `lectures_data`.`deleted` or `courses_data`.`deleted`));
CREATE VIEW IF NOT EXISTS `sorterrorlog` AS select * from `sorterrorlog_data` where (not(`sorterrorlog_data`.`deleted`));
CREATE TRIGGER IF NOT EXISTS featured_unique_order AFTER INSERT ON featured FOR EACH ROW BEGIN UPDATE featured SET `order` = (SELECT MAX(`order`) FROM featured)+1 WHERE id = NEW.id; END;
COMMIT;
......@@ -327,16 +327,13 @@ def index():
WHERE streams.active AND (? OR (streams.visible AND courses.visible AND courses.listed AND lectures.visible))
''', ismod())
featured = query('SELECT * FROM featured WHERE (? OR visible) ORDER BY `order`', ismod())
newfeatured = 0
if featured:
newfeatured = featured[-1]['order'] + 1
featured = list(filter(lambda x: not x['deleted'], featured))
for item in featured:
if item['type'] == 'courses':
if item['param'] not in ['title', 'semester', 'organizer', 'subject']:
continue
item['courses'] = query('SELECT * FROM courses WHERE (visible AND listed) AND `%s` = ? ORDER BY `%s`'%(item['param'], item['param']), item['param2'])
return render_template('index.html', latestvideos=livestreams+latestvideos, upcomming=upcomming, featured=featured, newfeatured=newfeatured)
return render_template('index.html', latestvideos=livestreams+latestvideos, upcomming=upcomming, featured=featured)
@app.route('/course')
@register_navbar('Videos', icon='film')
......@@ -505,7 +502,7 @@ tabs = {
'deleted', 'time_publish', 'time_expire'],
['created_by', 'time_created', 'time_updated']),
'featured': ('featured', 'id', ['title', 'text', 'internal', 'visible', 'deleted', 'param', 'param2', 'order'],
['created_by', 'time_created', 'time_updated', 'type', 'order']),
['created_by', 'time_created', 'time_updated', 'type']),
'perm': ('perm', 'id', ['type', 'param1', 'param2', 'deleted'],
['course_id', 'lecture_id', 'video_id', 'created_by', 'time_created', 'time_updated']),
'sorterrorlog': ('sorterrorlog_data', 'id', ['deleted'],
......
......@@ -57,9 +57,9 @@
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Neues Panel <span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="{{ url_for('create', table='featured', title='Neues Panel', type='plain', ref=request.url, order=newfeatured) }}">Nur Text</a></li>
<li><a href="{{ url_for('create', table='featured', title='Neues Panel', type='image', ref=request.url, order=newfeatured) }}">Text mit Bild</a></li>
<li><a href="{{ url_for('create', table='featured', title='Neues Panel', type='courses', param='semester', param2='', ref=request.url, order=newfeatured) }}">Veranstaltungsliste</a></li>
<li><a href="{{ url_for('create', table='featured', title='Neues Panel', type='plain', ref=request.url) }}">Nur Text</a></li>
<li><a href="{{ url_for('create', table='featured', title='Neues Panel', type='image', ref=request.url) }}">Text mit Bild</a></li>
<li><a href="{{ url_for('create', table='featured', title='Neues Panel', type='courses', param='semester', param2='', ref=request.url) }}">Veranstaltungsliste</a></li>
</ul>
</div>
</li>
......@@ -79,19 +79,15 @@
{{ moderator_editor(('featured',item.id,'title'), item.title) }} {{ moderator_checkbox(('featured',item.id,'visible'), item.visible) }}
{% if ismod() %}
<div class="btn-group pull-right" role="group">
{% if (loop.first or featured[loop.index0-1].order != item.order) and (loop.last or featured[loop.index0+1].order != item.order) %}
{% if not loop.first %}
<a class="btn btn-default" href="{{ url_for('edit', **{'featured.'+item.id|string+'.order': featured[loop.index0-1].order, 'featured.'+featured[loop.index0-1].id|string+'.order': item.order, 'ref': request.url})}}"><span class="glyphicon glyphicon-arrow-up"></span></a>
{% else %}
<button class="btn btn-default disabled"><span class="glyphicon glyphicon-arrow-up"></span></button>
{% endif %}
{% if not loop.last %}
<a class="btn btn-default" href="{{ url_for('edit', **{'featured.'+item.id|string+'.order': featured[loop.index0+1].order, 'featured.'+featured[loop.index0+1].id|string+'.order': item.order, 'ref': request.url})}}"><span class="glyphicon glyphicon-arrow-down"></span></a>
{% else %}
<button class="btn btn-default disabled"><span class="glyphicon glyphicon-arrow-down"></span></button>
{% endif %}
{% if not loop.first %}
<a class="btn btn-default" href="{{ url_for('edit', **{'featured.'+item.id|string+'.order': featured[loop.index0-1].order, 'featured.'+featured[loop.index0-1].id|string+'.order': item.order, 'ref': request.url})}}"><span class="glyphicon glyphicon-arrow-up"></span></a>
{% else %}
<a class="btn btn-default" data-toggle="tooltip" title="Sortierung reparieren" href="{{ url_for('edit', **{'featured.'+item.id|string+'.order': newfeatured, 'ref': request.url})}}"><span class="glyphicon glyphicon-sort-by-attributes"></span></a>
<button class="btn btn-default disabled"><span class="glyphicon glyphicon-arrow-up"></span></button>
{% endif %}
{% if not loop.last %}
<a class="btn btn-default" href="{{ url_for('edit', **{'featured.'+item.id|string+'.order': featured[loop.index0+1].order, 'featured.'+featured[loop.index0+1].id|string+'.order': item.order, 'ref': request.url})}}"><span class="glyphicon glyphicon-arrow-down"></span></a>
{% else %}
<button class="btn btn-default disabled"><span class="glyphicon glyphicon-arrow-down"></span></button>
{% endif %}
{{ moderator_delete(['featured',item.id,'deleted']) }}
</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