Remove admin view
This commit is contained in:
parent
d911cb573b
commit
a62e2bd9f7
3 changed files with 0 additions and 42 deletions
36
app/admin.py
36
app/admin.py
|
@ -1,36 +0,0 @@
|
||||||
"Haldis admin related views and models"
|
|
||||||
|
|
||||||
import flask_login as login
|
|
||||||
from flask import Flask
|
|
||||||
from flask_admin import Admin
|
|
||||||
from flask_admin.contrib.sqla import ModelView
|
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
|
||||||
|
|
||||||
from models import Order, OrderItem, OrderItemChoice, User
|
|
||||||
|
|
||||||
|
|
||||||
class ModelBaseView(ModelView):
|
|
||||||
"Base model for admin related things"
|
|
||||||
# pylint: disable=R0201, R0903
|
|
||||||
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
|
|
||||||
column_searchable_list = ("username",)
|
|
||||||
inline_models = None
|
|
||||||
|
|
||||||
|
|
||||||
def init_admin(app: Flask, database: SQLAlchemy) -> None:
|
|
||||||
"Initialize the admin related things in the 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))
|
|
|
@ -15,7 +15,6 @@ from flask_migrate import Migrate, MigrateCommand
|
||||||
from flask_oauthlib.client import OAuth, OAuthException
|
from flask_oauthlib.client import OAuth, OAuthException
|
||||||
from flask_script import Manager, Server
|
from flask_script import Manager, Server
|
||||||
|
|
||||||
from admin import init_admin
|
|
||||||
from login import init_login
|
from login import init_login
|
||||||
from models import db
|
from models import db
|
||||||
from models.anonymous_user import AnonymouseUser
|
from models.anonymous_user import AnonymouseUser
|
||||||
|
@ -75,8 +74,6 @@ def register_plugins(app: Flask) -> Manager:
|
||||||
app_manager = Manager(app)
|
app_manager = Manager(app)
|
||||||
app_manager.add_command("db", MigrateCommand)
|
app_manager.add_command("db", MigrateCommand)
|
||||||
app_manager.add_command("runserver", Server(port=8000))
|
app_manager.add_command("runserver", Server(port=8000))
|
||||||
# Add admin interface
|
|
||||||
init_admin(app, db)
|
|
||||||
|
|
||||||
# Init login manager
|
# Init login manager
|
||||||
login_manager = LoginManager()
|
login_manager = LoginManager()
|
||||||
|
|
|
@ -9,9 +9,6 @@
|
||||||
('general_bp.about', 'About'),
|
('general_bp.about', 'About'),
|
||||||
('stats_blueprint.stats', 'Stats'),
|
('stats_blueprint.stats', 'Stats'),
|
||||||
] -%}
|
] -%}
|
||||||
{% if not current_user.is_anonymous() and current_user.is_admin() -%}
|
|
||||||
{% set navbar = navbar + [('admin.index', 'Admin')] -%}
|
|
||||||
{% endif -%}
|
|
||||||
{% set active_page = active_page|default('index') -%}
|
{% set active_page = active_page|default('index') -%}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
|
|
Loading…
Reference in a new issue