all repos — artbound-python @ 59880ee3e9ba90fe6f77fc0463a617aec3f8907d

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}
25
26@app.route('/', methods=['GET', 'POST'])
27def route_index():
28    if request.method == 'GET':
29        return render_template("index.html", last_updated=database.get_last_updated(), current_month=datetime.today().strftime("%Y-%m"), emoji=emoji)
30
31    if (request.headers.get('Content-Type') != 'application/json'):
32        return 'Content-Type not supported. Please use "application/json".'
33
34    month = request.json["month"]
35    fanarts = database.get_fanarts(month)
36    return json.dumps(fanarts)
37
38@app.route('/help')
39def route_help():
40    return render_template("help.html", emoji=emoji)
41
42@app.route('/update', methods=['POST'])
43def route_update():
44    new_entries = database.update_database()
45    return json.dumps({
46        "timestamp": database.get_last_updated(),
47        "new": new_entries
48    })
49
50@app.route('/clear')
51def route_clear():
52    clear_cache()
53    return redirect("/")
54