all repos — artbound-python @ bb331c5170916a5958ae4d3054d7bec96df5d84b

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    "favicon": "✏️",
11    "select_all": "",
12    "select_none": "",
13    "save": "💾",
14    "save_ig": "📷",
15    "prev": "⬅️",
16    "next": "➡️",
17    "get_first": "🔽",
18    "get": "",
19    "toggle": "♻️",
20    "color": "",
21    "color_black": "",
22    "help": "",
23    "home": "🏠",
24    "rotate": "🔁",
25}
26
27@app.route('/', methods=['GET', 'POST'])
28def route_index():
29    if request.method == 'GET':
30        return render_template("index.html", last_updated=database.get_last_updated(), current_month=datetime.today().strftime("%Y-%m"), emoji=emoji)
31
32    if (request.headers.get('Content-Type') != 'application/json'):
33        return 'Content-Type not supported. Please use "application/json".'
34
35    month = request.json["month"]
36    fanarts = database.get_fanarts(month)
37    return json.dumps(fanarts)
38
39@app.route('/help')
40def route_help():
41    return render_template("help.html", emoji=emoji)
42
43@app.route('/update', methods=['POST'])
44def route_update():
45    new_entries = database.update_database()
46    return json.dumps({
47        "timestamp": database.get_last_updated(),
48        "new": new_entries
49    })
50
51@app.route('/clear')
52def route_clear():
53    clear_cache()
54    return redirect("/")
55