all repos — artbound-python @ cfc6f84c02ab9f22f1152b8922e117df254dd38b

A client-server reimplementation of the administration panel for ArtBound.

artbound_python/views.py (view raw)

 1import json
 2from datetime import datetime
 3from flask import request, redirect, render_template
 4from artbound_python import app
 5from artbound_python.cache import DB, clear_cache
 6
 7database = DB()
 8
 9emoji = {
10    "select_all": "",
11    "select_none": "",
12    "save": "💾",
13    "save_ig": "📷",
14    "prev": "⬅️",
15    "next": "➡️",
16    "toggle": "♻️",
17    "color": "",
18}
19
20@app.route('/', methods=['GET', 'POST'])
21def route_index():
22    if request.method == 'GET':
23        return render_template("index.html", last_updated=database.get_last_updated(), current_month=datetime.today().strftime("%Y-%m"), emoji=emoji)
24
25    if (request.headers.get('Content-Type') != 'application/json'):
26        return 'Content-Type not supported. Please use "application/json".'
27
28    month = request.json["month"]
29    fanarts = database.get_fanarts(month)
30    return json.dumps(fanarts)
31
32@app.route('/help')
33def route_help():
34    return render_template("help.html", emoji=emoji)
35
36@app.route('/update', methods=['POST'])
37def route_update():
38    new_entries = database.update_database()
39    return json.dumps({
40        "timestamp": database.get_last_updated(),
41        "new": new_entries
42    })
43
44@app.route('/clear')
45def route_clear():
46    clear_cache()
47    return redirect("/")
48