mirror of
https://github.com/logos-co/open-law.git
synced 2025-01-10 06:46:04 +00:00
add user and start of deleting function
This commit is contained in:
parent
c86d6796d4
commit
bb25fcb77c
@ -98,6 +98,7 @@ def create_app(environment="development"):
|
|||||||
)
|
)
|
||||||
|
|
||||||
for view in [
|
for view in [
|
||||||
|
ProtectedModelView(m.User, db.session, name="User", endpoint="/user_"),
|
||||||
ProtectedModelView(m.Book, db.session, name="Book", endpoint="/book_"),
|
ProtectedModelView(m.Book, db.session, name="Book", endpoint="/book_"),
|
||||||
ProtectedModelView(
|
ProtectedModelView(
|
||||||
m.Collection, db.session, name="Collection", endpoint="/collection_"
|
m.Collection, db.session, name="Collection", endpoint="/collection_"
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from flask_admin.contrib.sqla import ModelView
|
from flask_admin.contrib.sqla import ModelView
|
||||||
from flask_login import current_user
|
from flask_login import current_user
|
||||||
from flask import redirect, url_for
|
from flask import redirect, url_for, flash
|
||||||
|
from app.logger import log
|
||||||
|
|
||||||
|
|
||||||
class ProtectedModelView(ModelView):
|
class ProtectedModelView(ModelView):
|
||||||
@ -10,3 +11,26 @@ class ProtectedModelView(ModelView):
|
|||||||
def inaccessible_callback(self, name, **kwargs):
|
def inaccessible_callback(self, name, **kwargs):
|
||||||
# redirect to login page if user doesn't have access
|
# redirect to login page if user doesn't have access
|
||||||
return redirect(url_for("main.index"))
|
return redirect(url_for("main.index"))
|
||||||
|
|
||||||
|
def delete_model(self, model):
|
||||||
|
"""
|
||||||
|
Delete model.
|
||||||
|
:param model:
|
||||||
|
Model to delete
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
self.on_model_delete(model)
|
||||||
|
# Add your custom logic here and don't forget to commit any changes e.g.
|
||||||
|
# self.session.commit()
|
||||||
|
except Exception as ex:
|
||||||
|
if not self.handle_view_exception(ex):
|
||||||
|
flash("Failed to delete record.", "danger")
|
||||||
|
log(log.WARNING, "Failed to delete record.Because [%s]", ex)
|
||||||
|
|
||||||
|
self.session.rollback()
|
||||||
|
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
self.after_model_delete(model)
|
||||||
|
|
||||||
|
return True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user