1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-08 21:21:06 +00:00

Added Flask-Admin and Flask-DebugToolbar

This commit is contained in:
Mo 2021-04-19 01:33:46 +02:00
parent 66f4a056b7
commit f9dd498d92
6 changed files with 137 additions and 3 deletions

View file

@ -2,8 +2,12 @@ from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_security import Security, SQLAlchemyUserDatastore
from flask_security.models import fsqla_v2 as fsqla
from flask_admin import Admin
#DEBUG
from flask_debugtoolbar import DebugToolbarExtension
app = Flask(__name__)
app.debug = True #DEBUG
app.config["SECRET_KEY"] = "dev"
app.config['SECURITY_PASSWORD_SALT'] = "devSalt" # os.environ.get("SECURITY_PASSWORD_SALT", "")
@ -13,11 +17,18 @@ db = SQLAlchemy(app)
fsqla.FsModels.set_db_info(db)
app.config["DEBUG_TB_INTERCEPT_REDIRECTS"] = False #DEBUG
DebugToolbarExtension(app) #DEBUG
from advlabdb import customClasses
admin = Admin(app, name="Admin@AdvLabDB", template_mode='bootstrap3', index_view=customClasses.AdminIndexView())
from advlabdb import models
# Setup Flask-Security
user_datastore = SQLAlchemyUserDatastore(db, models.User, models.Role)
security = Security(app, user_datastore)
Security(app, user_datastore)
from advlabdb import routes
from advlabdb import forms
from advlabdb import modelViews

13
advlabdb/customClasses.py Normal file
View file

@ -0,0 +1,13 @@
from flask_admin import AdminIndexView as OldAdminIndexView
from flask_admin.contrib.sqla import ModelView as OldModelView
from flask_security import current_user
class AdminIndexView(OldAdminIndexView):
def is_accessible(self):
return current_user.has_role("admin")
class ModelView(OldModelView):
def is_accessible(self):
return current_user.has_role("admin")

View file

@ -1,6 +1,6 @@
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField, BooleanField
from wtforms.validators import DataRequired, Length, Email, EqualTo, ValidationError
from wtforms.validators import DataRequired, Email, ValidationError
from advlabdb.models import User

17
advlabdb/modelViews.py Normal file
View file

@ -0,0 +1,17 @@
from advlabdb import admin
from advlabdb.customClasses import ModelView
from advlabdb.models import *
admin.add_view(ModelView(Student, db.session))
admin.add_view(ModelView(PartStudent, db.session))
admin.add_view(ModelView(Group, db.session))
admin.add_view(ModelView(GroupExperiment, db.session))
admin.add_view(ModelView(Experiment, db.session))
admin.add_view(ModelView(PartExperiment, db.session))
admin.add_view(ModelView(Assistant, db.session))
admin.add_view(ModelView(Appointment, db.session))
admin.add_view(ModelView(Part, db.session))
admin.add_view(ModelView(Semester, db.session))
admin.add_view(ModelView(ExperimentMark, db.session))
admin.add_view(ModelView(User, db.session))
admin.add_view(ModelView(Role, db.session))

92
poetry.lock generated
View file

@ -41,6 +41,19 @@ python-versions = "*"
dnspython = ">=1.15.0"
idna = ">=2.0.0"
[[package]]
name = "flake8"
version = "3.9.1"
description = "the modular source code checker: pep8 pyflakes and co"
category = "dev"
optional = false
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7"
[package.dependencies]
mccabe = ">=0.6.0,<0.7.0"
pycodestyle = ">=2.7.0,<2.8.0"
pyflakes = ">=2.3.0,<2.4.0"
[[package]]
name = "flask"
version = "1.1.2"
@ -60,6 +73,36 @@ dev = ["pytest", "coverage", "tox", "sphinx", "pallets-sphinx-themes", "sphinxco
docs = ["sphinx", "pallets-sphinx-themes", "sphinxcontrib-log-cabinet", "sphinx-issues"]
dotenv = ["python-dotenv"]
[[package]]
name = "flask-admin"
version = "1.5.8"
description = "Simple and extensible admin interface framework for Flask"
category = "main"
optional = false
python-versions = "*"
[package.dependencies]
Flask = ">=0.7"
wtforms = "*"
[package.extras]
aws = ["boto"]
azure = ["azure-storage-blob"]
[[package]]
name = "flask-debugtoolbar"
version = "0.11.0"
description = "A toolbar overlay for debugging Flask applications."
category = "dev"
optional = false
python-versions = "*"
[package.dependencies]
Blinker = "*"
Flask = ">=0.8"
itsdangerous = "*"
werkzeug = "*"
[[package]]
name = "flask-login"
version = "0.5.0"
@ -175,6 +218,14 @@ category = "main"
optional = false
python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*"
[[package]]
name = "mccabe"
version = "0.6.1"
description = "McCabe checker, plugin for flake8"
category = "dev"
optional = false
python-versions = "*"
[[package]]
name = "passlib"
version = "1.7.4"
@ -189,6 +240,22 @@ bcrypt = ["bcrypt (>=3.1.0)"]
build_docs = ["sphinx (>=1.6)", "sphinxcontrib-fulltoc (>=1.2.0)", "cloud-sptheme (>=1.10.1)"]
totp = ["cryptography"]
[[package]]
name = "pycodestyle"
version = "2.7.0"
description = "Python style guide checker"
category = "dev"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
[[package]]
name = "pyflakes"
version = "2.3.1"
description = "passive checker of Python programs"
category = "dev"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
[[package]]
name = "sqlalchemy"
version = "1.4.9"
@ -251,7 +318,7 @@ locale = ["Babel (>=1.3)"]
[metadata]
lock-version = "1.1"
python-versions = "^3.8"
content-hash = "396528708e8c3b0568687eb473506ff98b5537939c1453a65dc43ef0a9cfa6e1"
content-hash = "9290321edbee89035d70215dd23581d01caa59d4fda0913156c8acd1e1bfb637"
[metadata.files]
blinker = [
@ -269,10 +336,21 @@ email-validator = [
{file = "email-validator-1.1.2.tar.gz", hash = "sha256:1a13bd6050d1db4475f13e444e169b6fe872434922d38968c67cea9568cce2f0"},
{file = "email_validator-1.1.2-py2.py3-none-any.whl", hash = "sha256:094b1d1c60d790649989d38d34f69e1ef07792366277a2cf88684d03495d018f"},
]
flake8 = [
{file = "flake8-3.9.1-py2.py3-none-any.whl", hash = "sha256:3b9f848952dddccf635be78098ca75010f073bfe14d2c6bda867154bea728d2a"},
{file = "flake8-3.9.1.tar.gz", hash = "sha256:1aa8990be1e689d96c745c5682b687ea49f2e05a443aff1f8251092b0014e378"},
]
flask = [
{file = "Flask-1.1.2-py2.py3-none-any.whl", hash = "sha256:8a4fdd8936eba2512e9c85df320a37e694c93945b33ef33c89946a340a238557"},
{file = "Flask-1.1.2.tar.gz", hash = "sha256:4efa1ae2d7c9865af48986de8aeb8504bf32c7f3d6fdc9353d34b21f4b127060"},
]
flask-admin = [
{file = "Flask-Admin-1.5.8.tar.gz", hash = "sha256:eb06a1f31b98881dee53a55c64faebd1990d6aac38826364b280df0b2679ff74"},
]
flask-debugtoolbar = [
{file = "Flask-DebugToolbar-0.11.0.tar.gz", hash = "sha256:3c4e79d354ede014e6657c545a536d4fb273cc89e3fd6b4835b02e346dd3aab4"},
{file = "Flask_DebugToolbar-0.11.0-py2.py3-none-any.whl", hash = "sha256:0e9a80d4c599233c68376e81cc99976200b5ac5248cfb24f18935cc5b69ac5b3"},
]
flask-login = [
{file = "Flask-Login-0.5.0.tar.gz", hash = "sha256:6d33aef15b5bcead780acc339464aae8a6e28f13c90d8b1cf9de8b549d1c0b4b"},
{file = "Flask_Login-0.5.0-py2.py3-none-any.whl", hash = "sha256:7451b5001e17837ba58945aead261ba425fdf7b4f0448777e597ddab39f4fba0"},
@ -403,10 +481,22 @@ markupsafe = [
{file = "MarkupSafe-1.1.1-cp39-cp39-win_amd64.whl", hash = "sha256:b7d644ddb4dbd407d31ffb699f1d140bc35478da613b441c582aeb7c43838dd8"},
{file = "MarkupSafe-1.1.1.tar.gz", hash = "sha256:29872e92839765e546828bb7754a68c418d927cd064fd4708fab9fe9c8bb116b"},
]
mccabe = [
{file = "mccabe-0.6.1-py2.py3-none-any.whl", hash = "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42"},
{file = "mccabe-0.6.1.tar.gz", hash = "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"},
]
passlib = [
{file = "passlib-1.7.4-py2.py3-none-any.whl", hash = "sha256:aa6bca462b8d8bda89c70b382f0c298a20b5560af6cbfa2dce410c0a2fb669f1"},
{file = "passlib-1.7.4.tar.gz", hash = "sha256:defd50f72b65c5402ab2c573830a6978e5f202ad0d984793c8dde2c4152ebe04"},
]
pycodestyle = [
{file = "pycodestyle-2.7.0-py2.py3-none-any.whl", hash = "sha256:514f76d918fcc0b55c6680472f0a37970994e07bbb80725808c17089be302068"},
{file = "pycodestyle-2.7.0.tar.gz", hash = "sha256:c389c1d06bf7904078ca03399a4816f974a1d590090fecea0c63ec26ebaf1cef"},
]
pyflakes = [
{file = "pyflakes-2.3.1-py2.py3-none-any.whl", hash = "sha256:7893783d01b8a89811dd72d7dfd4d84ff098e5eed95cfa8905b22bbffe52efc3"},
{file = "pyflakes-2.3.1.tar.gz", hash = "sha256:f5bc8ecabc05bb9d291eb5203d6810b49040f6ff446a756326104746cc00c1db"},
]
sqlalchemy = [
{file = "SQLAlchemy-1.4.9-cp27-cp27m-macosx_10_14_x86_64.whl", hash = "sha256:e26791ac43806dec1f18d328596db87f1b37f9d8271997dd1233054b4c377f51"},
{file = "SQLAlchemy-1.4.9-cp27-cp27m-manylinux1_x86_64.whl", hash = "sha256:c4485040d86d4b3d9aa509fd3c492de3687d9bf52fb85d66b33912ad068a088c"},

View file

@ -12,8 +12,11 @@ SQLAlchemy = "^1.4.4"
Flask-WTF = "^0.14.3"
email-validator = "^1.1.2"
Flask-Security-Too = "^4.0.0"
Flask-Admin = "^1.5.8"
[tool.poetry.dev-dependencies]
flake8 = "^3.9.1"
Flask-DebugToolbar = "^0.11.0"
[build-system]
requires = ["poetry-core>=1.0.0"]