summaryrefslogtreecommitdiff
path: root/jimbrella/web.py
blob: 42370554d1ef0f3556feb644b2d6a4c44806d7e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from flask import Flask, request, render_template
from user_agents import parse as user_agent
from .database import Database
from .config import *

db = Database(DATABASE_PATH)

app = Flask("jimbrella")


@app.route("/admin")
def admin_index():
    umbrellas = db.read()
    statuses = Database.group_by_status(umbrellas)
    return render_template(
        "admin/index.html",
        umbrellas=umbrellas,
        available=statuses["available"],
        lent=statuses["lent"],
        overdue=statuses["overdue"],
        mobile=user_agent(request.user_agent.string).is_mobile,
    )


@app.route("/admin/umbrellas")
def admin_umbrellas():
    umbrellas = db.read()
    return render_template(
        "admin/umbrellas.html",
        umbrellas=umbrellas,
        mobile=user_agent(request.user_agent.string).is_mobile,
    )


if __name__ == "__main__":
    app.run()