Spaces:
Runtime error
Runtime error
File size: 899 Bytes
b9a69cb |
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 |
from flask_admin import Admin
from flask_admin.base import AdminIndexView
from flask_admin.contrib import sqla
from flask_simplelogin import login_required
from werkzeug.security import generate_password_hash
from portalrhjobs.ext.database import db
from PortalRH.portalrhjobs.ext.models import User
# Proteger o admin com login via Monkey Patch
AdminIndexView._handle_view = login_required(AdminIndexView._handle_view)
sqla.ModelView._handle_view = login_required(sqla.ModelView._handle_view)
admin = Admin()
class UserAdmin(sqla.ModelView):
column_list = ['username']
can_edit = False
def on_model_change(self, form, model, is_created):
model.password = generate_password_hash(model.password)
def init_app(app):
admin.name = app
admin.template_mode = "bootstrap3"
admin.init_app(app)
admin.add_view(UserAdmin(User, db.session)) |