mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-14 16:55:42 +00:00
Add breadcrumbs to admin package
This commit is contained in:
parent
b8e63d2342
commit
2efc9533ec
@ -61,6 +61,7 @@ def create_app(config: Config = Config) -> Flask:
|
|||||||
init_error_handlers(app)
|
init_error_handlers(app)
|
||||||
|
|
||||||
from .admin import bp as admin_blueprint
|
from .admin import bp as admin_blueprint
|
||||||
|
default_breadcrumb_root(admin_blueprint, '.admin')
|
||||||
app.register_blueprint(admin_blueprint, url_prefix='/admin')
|
app.register_blueprint(admin_blueprint, url_prefix='/admin')
|
||||||
|
|
||||||
from .api import bp as api_blueprint
|
from .api import bp as api_blueprint
|
||||||
|
@ -1,5 +1,20 @@
|
|||||||
from flask import Blueprint
|
from flask import Blueprint
|
||||||
|
from flask_login import login_required
|
||||||
|
from app.decorators import admin_required
|
||||||
|
|
||||||
|
|
||||||
bp = Blueprint('admin', __name__)
|
bp = Blueprint('admin', __name__)
|
||||||
from . import routes
|
|
||||||
|
|
||||||
|
@bp.before_request
|
||||||
|
@login_required
|
||||||
|
@admin_required
|
||||||
|
def before_request():
|
||||||
|
'''
|
||||||
|
Ensures that the routes in this package can be visited only by users with
|
||||||
|
administrator privileges (login_required and admin_required).
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
from . import json_routes, routes
|
||||||
|
22
app/admin/json_routes.py
Normal file
22
app/admin/json_routes.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
from flask import current_app
|
||||||
|
from threading import Thread
|
||||||
|
from app import db
|
||||||
|
from app.models import User
|
||||||
|
from . import bp
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/users/<hashid:user_id>/delete', methods=['DELETE'])
|
||||||
|
def delete_user(user_id):
|
||||||
|
def _delete_user(app, user_id):
|
||||||
|
with app.app_context():
|
||||||
|
user = User.query.get(user_id)
|
||||||
|
user.delete()
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
User.query.get_or_404(user_id)
|
||||||
|
thread = Thread(
|
||||||
|
target=_delete_user,
|
||||||
|
args=(current_app._get_current_object(), user_id)
|
||||||
|
)
|
||||||
|
thread.start()
|
||||||
|
return {}, 202
|
@ -1,34 +1,25 @@
|
|||||||
from flask import current_app, flash, redirect, render_template, url_for
|
from flask import flash, redirect, render_template, url_for
|
||||||
from flask_login import login_required
|
from flask_breadcrumbs import register_breadcrumb
|
||||||
from threading import Thread
|
|
||||||
from app import db, hashids
|
from app import db, hashids
|
||||||
from app.decorators import admin_required
|
|
||||||
from app.models import Role, User, UserSettingJobStatusMailNotificationLevel
|
from app.models import Role, User, UserSettingJobStatusMailNotificationLevel
|
||||||
from app.users.forms import (
|
from app.users.forms import EditNotificationSettingsForm
|
||||||
EditNotificationSettingsForm
|
|
||||||
)
|
|
||||||
from app.users.forms import EditProfileSettingsForm
|
from app.users.forms import EditProfileSettingsForm
|
||||||
from . import bp
|
from . import bp
|
||||||
from .forms import AdminEditUserForm
|
from .forms import AdminEditUserForm
|
||||||
|
from app.users.utils import (
|
||||||
|
user_endpoint_arguments_constructor as user_eac,
|
||||||
@bp.before_request
|
user_dynamic_list_constructor as user_dlc
|
||||||
@login_required
|
)
|
||||||
@admin_required
|
|
||||||
def before_request():
|
|
||||||
'''
|
|
||||||
Ensures that the routes in this package can be visited only by users with
|
|
||||||
administrator privileges (login_required and admin_required).
|
|
||||||
'''
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('')
|
@bp.route('')
|
||||||
|
@register_breadcrumb(bp, '.', '<i class="material-icons left">admin_panel_settings</i>Administration')
|
||||||
def index():
|
def index():
|
||||||
return redirect(url_for('.users'))
|
return redirect(url_for('.users'))
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/users')
|
@bp.route('/users')
|
||||||
|
@register_breadcrumb(bp, '.users', '<i class="material-icons left">group</i>Users')
|
||||||
def users():
|
def users():
|
||||||
users = [x.to_json_serializeable(backrefs=True) for x in User.query.all()]
|
users = [x.to_json_serializeable(backrefs=True) for x in User.query.all()]
|
||||||
return render_template(
|
return render_template(
|
||||||
@ -39,12 +30,14 @@ def users():
|
|||||||
|
|
||||||
|
|
||||||
@bp.route('/users/<hashid:user_id>')
|
@bp.route('/users/<hashid:user_id>')
|
||||||
|
@register_breadcrumb(bp, '.users.entity', '', dynamic_list_constructor=user_dlc)
|
||||||
def user(user_id):
|
def user(user_id):
|
||||||
user = User.query.get_or_404(user_id)
|
user = User.query.get_or_404(user_id)
|
||||||
return render_template('admin/user.html.j2', title='User', user=user)
|
return render_template('admin/user.html.j2', title='User', user=user)
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/users/<hashid:user_id>/edit', methods=['GET', 'POST'])
|
@bp.route('/users/<hashid:user_id>/edit', methods=['GET', 'POST'])
|
||||||
|
@register_breadcrumb(bp, '.users.entity.edit', 'Edit', endpoint_arguments_constructor=user_eac)
|
||||||
def edit_user(user_id):
|
def edit_user(user_id):
|
||||||
user = User.query.get_or_404(user_id)
|
user = User.query.get_or_404(user_id)
|
||||||
admin_edit_user_form = AdminEditUserForm(
|
admin_edit_user_form = AdminEditUserForm(
|
||||||
@ -92,20 +85,3 @@ def edit_user(user_id):
|
|||||||
title='Edit user',
|
title='Edit user',
|
||||||
user=user
|
user=user
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/users/<hashid:user_id>/delete', methods=['DELETE'])
|
|
||||||
def delete_user(user_id):
|
|
||||||
def _delete_user(app, user_id):
|
|
||||||
with app.app_context():
|
|
||||||
user = User.query.get(user_id)
|
|
||||||
user.delete()
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
User.query.get_or_404(user_id)
|
|
||||||
thread = Thread(
|
|
||||||
target=_delete_user,
|
|
||||||
args=(current_app._get_current_object(), user_id)
|
|
||||||
)
|
|
||||||
thread.start()
|
|
||||||
return {}, 202
|
|
||||||
|
Loading…
Reference in New Issue
Block a user