|
|
|
@ -29,7 +29,7 @@ def get_data_from_query(query): |
|
|
|
|
|
|
|
|
|
def regen_JSON(): |
|
|
|
|
"""Gets links from DB and outputs them in JSON""" |
|
|
|
|
links_list = get_data_from_query('SELECT url, name FROM links ORDER BY position') |
|
|
|
|
links_list = get_data_from_query('SELECT url, name FROM links WHERE active=1 ORDER BY position') |
|
|
|
|
links_json = json.dumps(links_list, indent=4) |
|
|
|
|
return links_json |
|
|
|
|
|
|
|
|
@ -41,7 +41,7 @@ def verify_password(username, password): |
|
|
|
|
|
|
|
|
|
@app.route('/links', methods = ['GET']) |
|
|
|
|
def get_links(): |
|
|
|
|
links_list = get_data_from_query('SELECT name, url FROM links ORDER BY position') |
|
|
|
|
links_list = get_data_from_query('SELECT url, name FROM links WHERE active=1 ORDER BY position') |
|
|
|
|
return jsonify(links_list) |
|
|
|
|
|
|
|
|
|
@app.route('/editor/links', methods = ['POST']) |
|
|
|
@ -55,7 +55,7 @@ def update_links(): |
|
|
|
|
|
|
|
|
|
links = [] |
|
|
|
|
data = request.json['links'] |
|
|
|
|
items = 'url', 'name', 'clicks' |
|
|
|
|
items = 'url', 'name', 'clicks', 'active' |
|
|
|
|
for i in range(len(data)): |
|
|
|
|
if not(all(e in data[i] for e in items)): |
|
|
|
|
return "Bad request, some items missing from link object", 400 |
|
|
|
@ -63,12 +63,13 @@ def update_links(): |
|
|
|
|
url = data[i]['url'] |
|
|
|
|
name = data[i]['name'] |
|
|
|
|
clicks = data[i]['clicks'] |
|
|
|
|
active = data[i]['active'] |
|
|
|
|
position = i |
|
|
|
|
|
|
|
|
|
newlink = (url, name, clicks, position) |
|
|
|
|
newlink = (url, name, clicks, position, active) |
|
|
|
|
links.append(newlink) |
|
|
|
|
|
|
|
|
|
cur.executemany('INSERT INTO links VALUES (?,?,?,?)', links) |
|
|
|
|
cur.executemany('INSERT INTO links VALUES (?,?,?,?,?)', links) |
|
|
|
|
con.commit() |
|
|
|
|
con.close() |
|
|
|
|
data = regen_JSON() |
|
|
|
@ -82,14 +83,14 @@ def update_links(): |
|
|
|
|
con.close() |
|
|
|
|
raise e |
|
|
|
|
|
|
|
|
|
links_list = get_data_from_query('SELECT name, url, clicks FROM links ORDER BY position') |
|
|
|
|
links_list = get_data_from_query('SELECT name, url, clicks, active FROM links ORDER BY position') |
|
|
|
|
return jsonify(links_list) |
|
|
|
|
|
|
|
|
|
@app.route('/editor/links', methods = ['GET']) |
|
|
|
|
@auth.login_required |
|
|
|
|
def get_editor_links(): |
|
|
|
|
"""endpoint lists all URLs and clicks, returns json object for editor.""" |
|
|
|
|
links_list = get_data_from_query('SELECT name, url, clicks FROM links ORDER BY position') |
|
|
|
|
links_list = get_data_from_query('SELECT name, url, clicks, active FROM links ORDER BY position') |
|
|
|
|
return jsonify(links_list) |
|
|
|
|
|
|
|
|
|
@app.route('/clicks', methods=['POST']) |
|
|
|
|