diff --git a/database.py b/database.py index 0705792..6c8a0af 100644 --- a/database.py +++ b/database.py @@ -28,7 +28,7 @@ def create_entry_table(): def create_list_view(): conn = open_db() conn.execute("""CREATE VIEW IF NOT EXISTS [Liste] AS - SELECT Name, Title, Artist + SELECT Name, Title, Artist, entries.Id FROM entries, songs WHERE entries.Song_Id=songs.Id""") conn.close() @@ -59,3 +59,11 @@ def add_entry(name,song_id): conn.commit() conn.close() return + +def delete_entry(id): + conn = open_db() + cur = conn.cursor() + cur.execute("DELETE FROM entries WHERE id=?",(id,)) + conn.commit() + conn.close() + return True diff --git a/main.py b/main.py index fa3f7b8..2776bf1 100644 --- a/main.py +++ b/main.py @@ -1,12 +1,22 @@ -from flask import Flask, render_template, Response, abort, request +from flask import Flask, render_template, Response, abort, request, redirect import helpers import database import os, errno import json +from flask_basicauth import BasicAuth app = Flask(__name__, static_url_path='/static') + +app.config['BASIC_AUTH_USERNAME'] = 'admin' +app.config['BASIC_AUTH_PASSWORD'] = 'Karaoke2019blubb' + +basic_auth = BasicAuth(app) + @app.route("/") def home(): - return render_template('main.html', list=database.get_list()) + if basic_auth.authenticate(): + return render_template('main_admin.html', list=database.get_list(), auth=basic_auth.authenticate()) + else: + return render_template('main.html', list=database.get_list(), auth=basic_auth.authenticate()) @app.route('/api/enqueue', methods=['POST']) def enqueue(): @@ -20,7 +30,7 @@ def enqueue(): @app.route("/list") def songlist(): - return render_template('songlist.html', list=database.get_song_list()) + return render_template('songlist.html', list=database.get_song_list(), auth=basic_auth.authenticate()) @app.route("/api/songs") def songs(): @@ -33,6 +43,20 @@ def get_song_completions(input_string): list = database.get_song_completions(input_string=input_string) return Response(json.dumps(list, ensure_ascii=False).encode('utf-8'), mimetype='text/json') + +@app.route("/api/entries/delete/") +@basic_auth.required +def delete_entry(entry_id): + if database.delete_entry(entry_id): + return Response({"status": "OK"}, mimetype='text/json') + else: + return Response({"status": "FAIL"}, mimetype='text/json') + +@app.route("/login") +@basic_auth.required +def admin(): + return redirect("/") + if __name__ == "__main__": """try: os.remove("test.db") diff --git a/static/css/style.css b/static/css/style.css index 34b1305..dfbc5ee 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -1,3 +1,30 @@ body { padding-top: 5rem; +} + +html, body { + height: 100%; +} + +footer a, footer span{ + display: inline-flex; + vertical-align: middle; +} + +.site { + height: auto; + min-height: 100%; +} + +main { + padding-bottom: 60px; /* Höhe des Footers */ +} + +.footer { + margin-top: -60px; + width: 100%; + height: 60px; + /* Set the fixed height of the footer here */ + /*line-height: 60px; /* Vertically center the text there */ + background-color: #f5f5f5; } \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index d5cbf43..2ad38c0 100644 --- a/templates/base.html +++ b/templates/base.html @@ -45,11 +45,24 @@ --> - -
- {% block content %}{% endblock %} -
- +
+
+ {% block content %}{% endblock %} +
+
+ + + diff --git a/templates/main_admin.html b/templates/main_admin.html new file mode 100644 index 0000000..b8a8d50 --- /dev/null +++ b/templates/main_admin.html @@ -0,0 +1,45 @@ + + +{% extends 'base.html' %} +{% block title %}Home{% endblock %} +{% block content %} + + + + + + + + {% for entry in list: %} + + + + + + + {% endfor %} +
NameSongKünstlerLöschen
+ {{ entry[0] }} + + {{ entry[1] }} + + {{ entry[2] }} + + +
+ +{% endblock %} +{% block extrajs %} + +{% endblock %} \ No newline at end of file