-
Notifications
You must be signed in to change notification settings - Fork 0
/
bp_admin.py
executable file
·63 lines (53 loc) · 1.86 KB
/
bp_admin.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from flask import Blueprint, render_template
from sqlalchemy import select
from bp_auth import AuthActions, admin_required, auth
from configs import CONSTS
from models import Contact, Hurl, User, db
bp_admin = Blueprint("bp_admin", __name__, template_folder="templates")
@bp_admin.route("/admin_users", methods=["GET"])
@admin_required
def admin_users():
items = db.session.scalars(select(User).order_by(User.id))
attributes = ["id", "username", "created_datetime"]
header = "Showing all site users."
return render_template(
"admin_item.html",
CONSTS=CONSTS,
items=items,
attributes=attributes,
header=header,
logged_in=auth(AuthActions.is_logged_in),
is_admin=auth(AuthActions.is_admin),
)
@bp_admin.route("/admin_contacts", methods=["GET"])
@admin_required
def admin_contacts():
items = db.session.scalars(select(Contact).order_by(Contact.id)).all()
attributes = ["id", "name", "email", "message"]
header = f"Showing all site messages."
return render_template(
"admin_item.html",
CONSTS=CONSTS,
items=items,
attributes=attributes,
header=header,
logged_in=auth(AuthActions.is_logged_in),
is_admin=auth(AuthActions.is_admin),
)
@bp_admin.route("/admin_hurls", methods=["GET"])
@admin_required
def admin_hurls():
items = db.session.scalars(select(Hurl).order_by(Hurl.id)).all()
for i, h in enumerate(items):
items[i].__setattr__("read_count", len(h.visits))
attributes = ["id", "user_id", "read_count", "name", "created_datetime"]
header = "Showing all site hurls."
return render_template(
"admin_item.html",
CONSTS=CONSTS,
items=items,
attributes=attributes,
header=header,
logged_in=auth(AuthActions.is_logged_in),
is_admin=auth(AuthActions.is_admin),
)