-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbp_admin.py
56 lines (48 loc) · 1.78 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
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 Comment, Contact, Log, db
bp_admin = Blueprint("bp_admin", __name__, template_folder="templates")
@bp_admin.route("/admin_contacts", methods=["GET"])
@admin_required
def admin_contacts():
items = db.session.scalars(select(Contact).order_by(Contact.created_datetime.desc()).limit(30)).all()
attributes = ["name", "email", "message"]
header = "Showing all site messages."
return render_template(
"admin_item.html",
CONSTS=CONSTS,
items=items,
attributes=attributes,
header=header,
is_admin=auth(AuthActions.is_admin),
)
@bp_admin.route("/admin_comments", methods=["GET"])
@admin_required
def admin_comments():
items = db.session.scalars(select(Comment).order_by(Comment.published_date.desc()).limit(30)).all()
attributes = ["title", "text", "post_id"]
header = "Showing all site comments."
return render_template(
"admin_item.html",
CONSTS=CONSTS,
items=items,
attributes=attributes,
header=header,
is_admin=auth(AuthActions.is_admin),
)
@bp_admin.route("/admin_logs", methods=["GET"])
@admin_required
def admin_logs():
items = db.session.scalars(select(Log).where(Log.path.not_like("/static%")).order_by(Log.id.desc()).limit(30)).all()
attributes = ["id", "start_datetime_utc", "duration", "method", "x_forwarded_for", "referrer", "path", "user_agent"]
header = "Showing all site logs."
return render_template(
"admin_item.html",
CONSTS=CONSTS,
items=items,
attributes=attributes,
header=header,
is_admin=auth(AuthActions.is_admin),
)