all repos — artbound-python @ 0edae2b70652990a729ba21b58d5eb12a11f7496

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
 9@app.route('/', methods=['GET', 'POST'])
10def route_index():
11    if request.method == 'GET':
12        return render_template("index.html", last_updated=database.get_last_updated(), current_month=datetime.today().strftime("%Y-%m"))
13
14    if (request.headers.get('Content-Type') != 'application/json'):
15        return 'Content-Type not supported. Please use "application/json".'
16
17    month = request.json["month"]
18    fanarts = database.get_fanarts(month)
19    return json.dumps(fanarts)
20
21@app.route('/update', methods=['POST'])
22def route_update():
23    new_entries = database.update_database()
24    return json.dumps({
25        "timestamp": database.get_last_updated(),
26        "new": new_entries
27    })
28
29@app.route('/clear')
30def route_clear():
31    clear_cache()
32    return redirect("/")
33