diff --git a/db_schema.sql b/db_schema.sql index 921b1daa1b871a8d58f2a915e9c1dda83e234714..452a4ed1e2fa8178fc9794c7a25e14648f074918 100644 --- a/db_schema.sql +++ b/db_schema.sql @@ -183,6 +183,29 @@ CREATE TABLE IF NOT EXISTS `videos_data` ( `video_format` INTEGER NOT NULL, `hash` varchar(32) NOT NULL ); +CREATE TABLE IF NOT EXISTS `announcements` ( +`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + `text` text NOT NULL, + `internal` text NOT NULL, + `level` INTEGER NOT NULL DEFAULT 0, + `visible` INTEGER NOT NULL DEFAULT 0, + `deleted` INTEGER NOT NULL DEFAULT 0, + `time_created` datetime NOT NULL, + `time_updated` datetime NOT NULL, + `created_by` INTEGER NOT NULL +); +CREATE TABLE IF NOT EXISTS `featured` ( +`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + `title` text NOT NULL DEFAULT "Neuer Artikel", + `text` text NOT NULL DEFAULT "", + `internal` text NOT NULL DEFAULT "", + `visible` INTEGER NOT NULL DEFAULT 0, + `deleted` INTEGER NOT NULL DEFAULT 0, + `time_created` datetime NOT NULL, + `time_updated` datetime NOT NULL, + `created_by` INTEGER NOT NULL +); + CREATE VIEW IF NOT EXISTS `courses` AS select * from `courses_data` where (not(`courses_data`.`deleted`)); CREATE VIEW IF NOT EXISTS `lectures` AS select * from `lectures_data` where (not(`lectures_data`.`deleted`)); CREATE VIEW IF NOT EXISTS `videos` AS select * from `videos_data` where (not(`videos_data`.`deleted`)); diff --git a/server.py b/server.py index e0a7e2704565b133bcf504f74cdbab008ce656f1..29a44dd1a41ccfc984b72f30ddcfc4b4f58fc604 100755 --- a/server.py +++ b/server.py @@ -119,6 +119,10 @@ def human_date(d): def rfc3339(d): return d.strftime('%Y-%m-%dT%H:%M:%S+02:00') +@app.template_global() +def get_announcements(minlevel=0): + return query('SELECT * FROM announcements WHERE NOT deleted AND (? OR visible) AND level >= ? ORDER BY level DESC', ismod(), minlevel) + @app.route('/') @register_navbar('Home', icon='home') def index(): @@ -130,7 +134,6 @@ def index(): ORDER BY time ASC LIMIT 7''',datetime.today()) for i in upcomming: i['date'] = i['time'].date() - i['time'] = i['time'].time() latestvideos=query(''' SELECT lectures.*, max(videos.time_updated) AS lastvidtime, courses.short, courses.downloadable, courses.title AS coursetitle FROM lectures @@ -140,7 +143,8 @@ def index(): GROUP BY videos.lecture_id ORDER BY lastvidtime DESC LIMIT 6 ''',ismod()) - return render_template('index.html', latestvideos=latestvideos, upcomming=upcomming) + featured = query('SELECT * FROM featured WHERE NOT deleted AND (? OR visible)', ismod()) + return render_template('index.html', latestvideos=latestvideos, upcomming=upcomming, featured=featured) @app.route('/course') @register_navbar('Videos', icon='film') @@ -247,7 +251,8 @@ def edit(prefix="", ignore=[]): 'lectures': ('lectures_data', 'id', ['visible', 'title', 'comment', 'internal', 'speaker', 'place', 'time', 'duration', 'jumplist','deleted']), 'videos': ('videos_data', 'id', ['visible','deleted']), - 'chapters': ('chapters', 'id', ['time', 'text', 'visible', 'deleted']) + 'chapters': ('chapters', 'id', ['time', 'text', 'visible', 'deleted']), + 'announcements': ('announcements', 'id', ['text', 'internal', 'level', 'visible', 'deleted']) } query('BEGIN') if request.is_json: @@ -257,6 +262,7 @@ def edit(prefix="", ignore=[]): for key, val in changes: if key in ignore: continue + print('edit:', key, val) key = prefix+key print (key,val) table, id, column = key.split('.', 2) @@ -370,6 +376,24 @@ def suggest_chapter(lectureid): return redirect(request.values['ref']) return 'OK', 200 +@app.route('/newpsa', methods=['POST', 'GET']) +@mod_required +def new_announcement(): + id = query('INSERT INTO announcements (text, internal, time_created, time_updated, created_by) VALUES ("Neue Ankündigung", "", ?, ?, ?)', + datetime.now(), datetime.now(), session.get('user', {'dbid':None})['dbid']) + if 'ref' in request.values: + return redirect(request.values['ref']) + return id, 200 + +@app.route('/newfeatured', methods=['POST', 'GET']) +@mod_required +def new_featured(): + id = query('INSERT INTO featured (time_created, time_updated, created_by) VALUES (?, ?, ?)', + datetime.now(), datetime.now(), session.get('user', {'dbid':None})['dbid']) + if 'ref' in request.values: + return redirect(request.values['ref']) + return id, 200 + import feeds import importer import schedule diff --git a/templates/base.html b/templates/base.html index 25be41a15919b5880265d552721b43f339697200..004ec40b82db6367ab0ca73c264ab60bce3c7f1f 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,4 +1,7 @@ -{% set page_border = page_border|default(1) -%} +{% set page_border = page_border|default(1) %} +{% set min_announcement_level = min_announcement_level|default(1) %} +{% set announcement_levels = {0: 'info', 1: 'info', 2: 'warning', 3: 'danger'} %} +{% from 'macros.html' import valueeditor, valuecheckbox, valuedeletebtn %} <!DOCTYPE html> <html> @@ -102,6 +105,22 @@ {% for msg in get_flashed_messages() %} <div class="alert alert-danger" role="alert">{{ msg }}</div> {% endfor %} + {% for msg in get_announcements(min_announcement_level) %} + <div class="alert alert-{{announcement_levels.get(msg.level, 'info')}}" role="alert"> + {{ valueeditor(('announcements',msg.id,'text'), msg.text|safe) }} + {% if ismod() %} + <div class="pull-right"> + {{ valuecheckbox(('announcements',msg.id,'visible'),msg.visible) }} + {{ valuedeletebtn(('announcements',msg.id,'deleted')) }} + </div> + <br> + {{ valueeditor(('announcements',msg.id,'internal'), msg.internal) }} + <div class="pull-right"> + Level: {{ valueeditor(('announcements',msg.id,'level'), msg.level) }} + </div> + {% endif %} + </div> + {% endfor %} {% block content %} <h1>This is a Heading</h1> <p>This is a paragraph.</p> diff --git a/templates/index.html b/templates/index.html index 368708abaabf10bffa61dd4c022cd0bb85bd580a..6b34bdcfba6fd02db7ab4c254bf3829dd86ba2d5 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,7 +1,19 @@ {% from 'macros.html' import preview %} {% extends "base.html" %} {% set page_border = 0 %} +{% set min_announcement_level = 0 %} {% block content %} +<div class="row"> + <div class="col-xs-12"> + <ul class="list-inline pull-right"> + {% if ismod() %} + <li style="padding-right: 0px;"> + <a class="btn btn-default" href="{{ url_for('new_announcement', ref=request.url) }}">Neue Ankündigung</a> + </li> + {% endif %} + </ul> + </div> +</div> <div class="row"> <div class="col-md-6 panel-group"> <div class="panel panel-default">