diff --git a/app/__init__.py b/app/__init__.py index 318502f4..076b006a 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -61,6 +61,7 @@ def create_app(config: Config = Config) -> Flask: init_error_handlers(app) from .admin import bp as admin_blueprint + default_breadcrumb_root(admin_blueprint, '.admin') app.register_blueprint(admin_blueprint, url_prefix='/admin') from .api import bp as api_blueprint @@ -71,7 +72,7 @@ def create_app(config: Config = Config) -> Flask: app.register_blueprint(auth_blueprint, url_prefix='/') from .contributions import bp as contributions_blueprint - default_breadcrumb_root(contributions_blueprint, '.contributions') + default_breadcrumb_root(contributions_blueprint, '.dashboard.contributions') app.register_blueprint(contributions_blueprint, url_prefix='/contributions') from .corpora import bp as corpora_blueprint diff --git a/app/admin/__init__.py b/app/admin/__init__.py index b5936b4c..be000a9a 100644 --- a/app/admin/__init__.py +++ b/app/admin/__init__.py @@ -1,5 +1,20 @@ from flask import Blueprint +from flask_login import login_required +from app.decorators import admin_required 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 diff --git a/app/admin/json_routes.py b/app/admin/json_routes.py new file mode 100644 index 00000000..d8b45425 --- /dev/null +++ b/app/admin/json_routes.py @@ -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//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 diff --git a/app/admin/routes.py b/app/admin/routes.py index 95ce7730..15ff0d9f 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -1,34 +1,25 @@ -from flask import current_app, flash, redirect, render_template, url_for -from flask_login import login_required -from threading import Thread +from flask import flash, redirect, render_template, url_for +from flask_breadcrumbs import register_breadcrumb from app import db, hashids -from app.decorators import admin_required from app.models import Role, User, UserSettingJobStatusMailNotificationLevel -from app.users.forms import ( - EditNotificationSettingsForm -) +from app.users.forms import EditNotificationSettingsForm from app.users.forms import EditProfileSettingsForm from . import bp from .forms import AdminEditUserForm - - -@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 app.users.utils import ( + user_endpoint_arguments_constructor as user_eac, + user_dynamic_list_constructor as user_dlc +) @bp.route('') +@register_breadcrumb(bp, '.', 'admin_panel_settingsAdministration') def index(): return redirect(url_for('.users')) @bp.route('/users') +@register_breadcrumb(bp, '.users', 'groupUsers') def users(): users = [x.to_json_serializeable(backrefs=True) for x in User.query.all()] return render_template( @@ -39,12 +30,14 @@ def users(): @bp.route('/users/') +@register_breadcrumb(bp, '.users.entity', '', dynamic_list_constructor=user_dlc) def user(user_id): user = User.query.get_or_404(user_id) return render_template('admin/user.html.j2', title='User', user=user) @bp.route('/users//edit', methods=['GET', 'POST']) +@register_breadcrumb(bp, '.users.entity.edit', 'Edit', endpoint_arguments_constructor=user_eac) def edit_user(user_id): user = User.query.get_or_404(user_id) admin_edit_user_form = AdminEditUserForm( @@ -92,20 +85,3 @@ def edit_user(user_id): title='Edit user', user=user ) - - -@bp.route('/users//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 diff --git a/app/contributions/__init__.py b/app/contributions/__init__.py index 22f3e514..478631f9 100644 --- a/app/contributions/__init__.py +++ b/app/contributions/__init__.py @@ -5,3 +5,4 @@ bp = Blueprint('contributions', __name__) from . import routes from . import spacy_nlp_pipeline_models from . import tesseract_ocr_pipeline_models +from . import transkribus_htr_pipeline_models diff --git a/app/contributions/routes.py b/app/contributions/routes.py index dacf5b62..4bdc5cc7 100644 --- a/app/contributions/routes.py +++ b/app/contributions/routes.py @@ -1,14 +1,11 @@ -from flask import render_template +from flask import redirect, url_for from flask_breadcrumbs import register_breadcrumb from flask_login import login_required from . import bp @bp.route('') -@register_breadcrumb(bp, '.', 'new_labelContributions') +@register_breadcrumb(bp, '.', 'new_labelMy Contributions') @login_required def contributions(): - return render_template( - 'contributions/contributions.html.j2', - title='Contributions' - ) + return redirect(url_for('main.dashboard', _anchor='contributions')) diff --git a/app/contributions/transkribus_htr_pipeline_models/__init__.py b/app/contributions/transkribus_htr_pipeline_models/__init__.py new file mode 100644 index 00000000..e91268cf --- /dev/null +++ b/app/contributions/transkribus_htr_pipeline_models/__init__.py @@ -0,0 +1,2 @@ +from .. import bp +from . import routes diff --git a/app/contributions/transkribus_htr_pipeline_models/routes.py b/app/contributions/transkribus_htr_pipeline_models/routes.py new file mode 100644 index 00000000..317ff9b9 --- /dev/null +++ b/app/contributions/transkribus_htr_pipeline_models/routes.py @@ -0,0 +1,9 @@ +from flask import abort +from flask_login import login_required +from . import bp + + +@bp.route('/transkribus_htr_pipeline_models') +@login_required +def transkribus_htr_pipeline_models(): + return abort(503) diff --git a/app/templates/_sidenav.html.j2 b/app/templates/_sidenav.html.j2 index 3c891591..5ee67954 100644 --- a/app/templates/_sidenav.html.j2 +++ b/app/templates/_sidenav.html.j2 @@ -25,7 +25,7 @@
  • dashboardDashboard
  • IMy Corpora
  • JMy Jobs
  • -
  • new_labelContribute
  • +
  • new_labelMy Contributions
  • Processes & Services
  • diff --git a/app/templates/contributions/contributions.html.j2 b/app/templates/contributions/contributions.html.j2 deleted file mode 100644 index 059dc9b2..00000000 --- a/app/templates/contributions/contributions.html.j2 +++ /dev/null @@ -1,44 +0,0 @@ -{% extends "base.html.j2" %} -{% import "materialize/wtf.html.j2" as wtf %} - -{% block page_content %} -
    -
    -
    -

    {{ title }}

    -
    - -
    -
    - -
    - Tesseract OCR Pipeline Models -

    Here you can see and edit the models that you have created. You can also create new models.

    -
    -
    -
    - -
    -
    - -
    - SpaCy NLP Pipeline Models -

    Here you can see and edit the models that you have created. You can also create new models.

    -
    -
    -
    - - -
    -
    -{% endblock page_content %} diff --git a/app/templates/main/dashboard.html.j2 b/app/templates/main/dashboard.html.j2 index 1598e139..0b8e6f31 100644 --- a/app/templates/main/dashboard.html.j2 +++ b/app/templates/main/dashboard.html.j2 @@ -41,6 +41,39 @@ + +
    +

    My Contributions

    +
    +
    + +
    + Tesseract OCR Pipeline Models +

    Here you can see and edit the models that you have created. You can also create new models.

    +
    +
    +
    + +
    +
    + +
    + SpaCy NLP Pipeline Models +

    Here you can see and edit the models that you have created. You can also create new models.

    +
    +
    +
    + +
    +
    + +
    + Transkribus HTR Pipeline Models +

    Here you can see and edit the models that you have created. You can also create new models.

    +
    +
    +
    +
    {% endblock page_content %} diff --git a/app/users/routes.py b/app/users/routes.py index bc2e90fb..5431dfd0 100644 --- a/app/users/routes.py +++ b/app/users/routes.py @@ -78,7 +78,7 @@ def profile_avatar(user_id): @bp.route('//edit', methods=['GET', 'POST']) -@register_breadcrumb(bp, '.entity.edit', 'settingsEdit', endpoint_arguments_constructor=user_eac) +@register_breadcrumb(bp, 'breadcrumbs.settings', 'settingsSettings', endpoint_arguments_constructor=user_eac) @login_required def edit_profile(user_id): user = User.query.get_or_404(user_id) @@ -172,5 +172,5 @@ def edit_profile(user_id): change_password_form=change_password_form, edit_notification_settings_form=edit_notification_settings_form, user=user, - title='User Settings' + title='Settings' )