Send more data to the frontend

This commit is contained in:
Phillip Kühne 2020-03-26 02:40:44 +01:00
parent ca3d5f8a77
commit 869166f818
4 changed files with 41 additions and 2 deletions

25
backend/.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,25 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Flask",
"type": "python",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "app/main.py",
"FLASK_ENV": "development",
"FLASK_DEBUG": "0"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"jinja": true
}
]
}

3
backend/.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"python.pythonPath": "/usr/bin/python3.8"
}

View File

@ -9,6 +9,13 @@ entry_table = "entries"
index_label = "Id"
done_table = "done_songs"
def dict_factory(cursor, row):
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d
def open_db():
conn = sqlite3.connect("data/test.db")
conn.execute('PRAGMA encoding = "UTF-8";')
@ -94,12 +101,13 @@ def get_song_list():
def get_song_completions(input_string):
conn = open_db()
conn.row_factory = dict_factory
cur = conn.cursor()
# Don't look, it burns...
prepared_string = "%{0}%".format(input_string).upper() # "Test" -> "%TEST%"
print(prepared_string)
cur.execute(
"SELECT Title || \" - \" || Artist AS Song, Id FROM songs WHERE REPLACE(REPLACE(REPLACE(REPLACE(UPPER( SONG ),'ö','Ö'),'ü','Ü'),'ä','Ä'),'ß','') LIKE (?) LIMIT 20;", (prepared_string,))
"SELECT * FROM songs WHERE REPLACE(REPLACE(REPLACE(REPLACE(UPPER( Title ),'ö','Ö'),'ü','Ü'),'ä','Ä'),'ß','') LIKE (?) LIMIT 20;", (prepared_string,))
return cur.fetchall()
def add_entry(name,song_id):

View File

@ -1,4 +1,5 @@
from flask import Flask, render_template, Response, abort, request, redirect
from flask_cors import CORS
import helpers
import database
import data_adapters
@ -7,6 +8,7 @@ import json
from flask_basicauth import BasicAuth
app = Flask(__name__, static_url_path='/static')
CORS(app)
basic_auth = BasicAuth(app)
accept_entries = False
@ -65,7 +67,8 @@ def get_song_completions(input_string=""):
if input_string!="":
print(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).encode('utf-8'), mimetype='application/json')
# return Response(json.dumps(list, ensure_ascii=False).encode('utf-8'), mimetype='text/json')
else:
return 400