mirror of
https://github.com/PhoenixTwoFive/karaoqueue.git
synced 2025-05-20 11:31:49 +02:00
Add entry deletion, footer
This commit is contained in:
parent
0f7144dbc9
commit
5818eb1150
10
database.py
10
database.py
@ -28,7 +28,7 @@ def create_entry_table():
|
|||||||
def create_list_view():
|
def create_list_view():
|
||||||
conn = open_db()
|
conn = open_db()
|
||||||
conn.execute("""CREATE VIEW IF NOT EXISTS [Liste] AS
|
conn.execute("""CREATE VIEW IF NOT EXISTS [Liste] AS
|
||||||
SELECT Name, Title, Artist
|
SELECT Name, Title, Artist, entries.Id
|
||||||
FROM entries, songs
|
FROM entries, songs
|
||||||
WHERE entries.Song_Id=songs.Id""")
|
WHERE entries.Song_Id=songs.Id""")
|
||||||
conn.close()
|
conn.close()
|
||||||
@ -59,3 +59,11 @@ def add_entry(name,song_id):
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
return
|
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
|
||||||
|
30
main.py
30
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 helpers
|
||||||
import database
|
import database
|
||||||
import os, errno
|
import os, errno
|
||||||
import json
|
import json
|
||||||
|
from flask_basicauth import BasicAuth
|
||||||
app = Flask(__name__, static_url_path='/static')
|
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("/")
|
@app.route("/")
|
||||||
def home():
|
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'])
|
@app.route('/api/enqueue', methods=['POST'])
|
||||||
def enqueue():
|
def enqueue():
|
||||||
@ -20,7 +30,7 @@ def enqueue():
|
|||||||
|
|
||||||
@app.route("/list")
|
@app.route("/list")
|
||||||
def songlist():
|
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")
|
@app.route("/api/songs")
|
||||||
def songs():
|
def songs():
|
||||||
@ -33,6 +43,20 @@ def get_song_completions(input_string):
|
|||||||
list = database.get_song_completions(input_string=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')
|
return Response(json.dumps(list, ensure_ascii=False).encode('utf-8'), mimetype='text/json')
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/api/entries/delete/<entry_id>")
|
||||||
|
@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__":
|
if __name__ == "__main__":
|
||||||
"""try:
|
"""try:
|
||||||
os.remove("test.db")
|
os.remove("test.db")
|
||||||
|
@ -1,3 +1,30 @@
|
|||||||
body {
|
body {
|
||||||
padding-top: 5rem;
|
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;
|
||||||
|
}
|
@ -45,11 +45,24 @@
|
|||||||
</form>-->
|
</form>-->
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
<div class="site">
|
||||||
<main role="main" class="container">
|
<main role="main" class="container">
|
||||||
{% block content %}{% endblock %}
|
{% block content %}{% endblock %}
|
||||||
</main><!-- /.container -->
|
</main><!-- /.container -->
|
||||||
|
</div>
|
||||||
|
<!-- Footer -->
|
||||||
|
<footer class="footer">
|
||||||
|
<div class="container text-center py-3">
|
||||||
|
{% if not auth %}
|
||||||
|
<a href="/login"><i class='material-icons'>launch</i> Login</a>
|
||||||
|
{% endif %}
|
||||||
|
<a href="https://github.com/PhoenixTwoFive/karaoqueue"><i class='material-icons'>code</i> Github</a>
|
||||||
|
<span class="text-muted">KaraoQueue - <span
|
||||||
|
style="display:inline-block;transform: rotate(180deg);">©</span> 2019 - Phillip
|
||||||
|
Kühne</span>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
<!-- Footer -->
|
||||||
<!-- Bootstrap core JavaScript
|
<!-- Bootstrap core JavaScript
|
||||||
================================================== -->
|
================================================== -->
|
||||||
<!-- Placed at the end of the document so the pages load faster -->
|
<!-- Placed at the end of the document so the pages load faster -->
|
||||||
|
45
templates/main_admin.html
Normal file
45
templates/main_admin.html
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
|
||||||
|
|
||||||
|
{% extends 'base.html' %}
|
||||||
|
{% block title %}Home{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<table class="table">
|
||||||
|
<tr>
|
||||||
|
<th scope="col">Name</th>
|
||||||
|
<th scope="col">Song</th>
|
||||||
|
<th scope="col">Künstler</th>
|
||||||
|
<th scope="col">Löschen</th>
|
||||||
|
</tr>
|
||||||
|
{% for entry in list: %}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
{{ entry[0] }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ entry[1] }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ entry[2] }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<button type='button' class='btn btn-danger' onclick='deleteEntry({{ entry[3] }})'><i
|
||||||
|
class='material-icons'>delete</i></button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
<a name="end"></a>
|
||||||
|
{% endblock %}
|
||||||
|
{% block extrajs %}
|
||||||
|
<script>
|
||||||
|
function deleteEntry(entry_id) {
|
||||||
|
$.ajax({
|
||||||
|
type: 'GET',
|
||||||
|
url: '/api/entries/delete/'+entry_id,
|
||||||
|
contentType: "application/json",
|
||||||
|
dataType: 'json'
|
||||||
|
});
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
Loading…
x
Reference in New Issue
Block a user