Polish the admin interface a bit
This commit is contained in:
parent
aa1cd97773
commit
f6753172ec
4 changed files with 34 additions and 16 deletions
37
app/admin.py
37
app/admin.py
|
@ -1,5 +1,3 @@
|
|||
"Haldis admin related views and models"
|
||||
|
||||
import flask_login as login
|
||||
from flask import Flask
|
||||
from flask_admin import Admin
|
||||
|
@ -10,27 +8,40 @@ from models import Order, OrderItem, OrderItemChoice, User
|
|||
|
||||
|
||||
class ModelBaseView(ModelView):
|
||||
"Base model for admin related things"
|
||||
# pylint: disable=R0201, R0903
|
||||
# pylint: disable=too-few-public-methods, no-self-use
|
||||
def is_accessible(self) -> bool:
|
||||
"Check if the user has admin permission"
|
||||
if login.current_user.is_anonymous():
|
||||
return False
|
||||
return login.current_user.is_admin()
|
||||
|
||||
|
||||
class UserAdminModel(ModelBaseView):
|
||||
"Model for user admin"
|
||||
# pylint: disable=R0903
|
||||
# pylint: disable=too-few-public-methods
|
||||
column_searchable_list = ("username",)
|
||||
column_editable_list = ("username",)
|
||||
column_default_sort = "username"
|
||||
inline_models = None
|
||||
|
||||
|
||||
class OrderAdminModel(ModelBaseView):
|
||||
# pylint: disable=too-few-public-methods
|
||||
column_list = ["starttime", "stoptime", "location_name", "location_id", "courier"]
|
||||
column_labels = {
|
||||
"starttime": "Start time", "stoptime": "Closing time",
|
||||
"location_name": "Location name", "location_id": "HLDS location ID",
|
||||
"courier": "Courier"}
|
||||
form_excluded_columns = ["items", "courier_id"]
|
||||
column_default_sort = ("starttime", True)
|
||||
can_delete = False
|
||||
|
||||
|
||||
class OrderItemAdminModel(ModelBaseView):
|
||||
# pylint: disable=too-few-public-methods
|
||||
column_default_sort = ("order_id", True)
|
||||
|
||||
|
||||
def init_admin(app: Flask, database: SQLAlchemy) -> None:
|
||||
"Initialize the admin related things in the app."
|
||||
"Register admin views with Flask app."
|
||||
admin = Admin(app, name="Haldis", url="/admin", template_mode="bootstrap3")
|
||||
|
||||
admin.add_view(UserAdminModel(User, database.session))
|
||||
admin.add_view(ModelBaseView(Order, database.session))
|
||||
admin.add_view(ModelBaseView(OrderItem, database.session))
|
||||
admin.add_view(ModelBaseView(OrderItemChoice, database.session))
|
||||
admin.add_view(OrderAdminModel(Order, database.session))
|
||||
admin.add_view(OrderItemAdminModel(OrderItem, database.session))
|
||||
|
|
|
@ -69,7 +69,6 @@ def register_plugins(app: Flask) -> Manager:
|
|||
app_manager = Manager(app)
|
||||
app_manager.add_command("db", MigrateCommand)
|
||||
app_manager.add_command("runserver", Server(port=8000))
|
||||
# Add admin interface
|
||||
init_admin(app, db)
|
||||
|
||||
# Init login manager
|
||||
|
|
8
app/templates/admin/index.html
Normal file
8
app/templates/admin/index.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
{% extends 'admin/master.html' %}
|
||||
|
||||
{% block body %}
|
||||
<p>To edit the <strong>metadata of an order</strong>, go to <a href="{{ url_for("order.index_view") }}">Order</a>. There is
|
||||
no link from an order to the ordered items, so…</p>
|
||||
<p>To edit or delete <strong>items from orders</strong>, go straight to <a href="{{ url_for("orderitem.index_view") }}">Order Item</a>.</p>
|
||||
<p>To edit locations and their <strong>menus</strong>, edit the HLDS data files in the repository and submit a pull/merge request.</p>
|
||||
{% endblock %}
|
|
@ -9,8 +9,8 @@
|
|||
('general_bp.about', 'About'),
|
||||
('stats_blueprint.stats', 'Stats'),
|
||||
] -%}
|
||||
{% if not current_user.is_anonymous() and current_user.is_admin() -%}
|
||||
{% set navbar = navbar + [('admin.index', 'Admin')] -%}
|
||||
{% if current_user.is_admin() -%}
|
||||
{% set navbar = navbar + [('admin.index', 'Admin')] -%}
|
||||
{% endif -%}
|
||||
{% set active_page = active_page|default('index') -%}
|
||||
|
||||
|
|
Loading…
Reference in a new issue