Merge branch 'public-corpus' of gitlab.ub.uni-bielefeld.de:sfb1288inf/nopaque into public-corpus

This commit is contained in:
Inga Kirschnick 2023-03-15 09:19:14 +01:00
commit bd86a71222
12 changed files with 102 additions and 90 deletions

View File

@ -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
@ -71,7 +72,7 @@ def create_app(config: Config = Config) -> Flask:
app.register_blueprint(auth_blueprint, url_prefix='/') app.register_blueprint(auth_blueprint, url_prefix='/')
from .contributions import bp as contributions_blueprint 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') app.register_blueprint(contributions_blueprint, url_prefix='/contributions')
from .corpora import bp as corpora_blueprint from .corpora import bp as corpora_blueprint

View File

@ -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
View 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

View File

@ -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

View File

@ -5,3 +5,4 @@ bp = Blueprint('contributions', __name__)
from . import routes from . import routes
from . import spacy_nlp_pipeline_models from . import spacy_nlp_pipeline_models
from . import tesseract_ocr_pipeline_models from . import tesseract_ocr_pipeline_models
from . import transkribus_htr_pipeline_models

View File

@ -1,14 +1,11 @@
from flask import render_template from flask import redirect, url_for
from flask_breadcrumbs import register_breadcrumb from flask_breadcrumbs import register_breadcrumb
from flask_login import login_required from flask_login import login_required
from . import bp from . import bp
@bp.route('') @bp.route('')
@register_breadcrumb(bp, '.', '<i class="material-icons left">new_label</i>Contributions') @register_breadcrumb(bp, '.', '<i class="material-icons left">new_label</i>My Contributions')
@login_required @login_required
def contributions(): def contributions():
return render_template( return redirect(url_for('main.dashboard', _anchor='contributions'))
'contributions/contributions.html.j2',
title='Contributions'
)

View File

@ -0,0 +1,2 @@
from .. import bp
from . import routes

View File

@ -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)

View File

@ -25,7 +25,7 @@
<li><a href="{{ url_for('main.dashboard') }}"><i class="material-icons">dashboard</i>Dashboard</a></li> <li><a href="{{ url_for('main.dashboard') }}"><i class="material-icons">dashboard</i>Dashboard</a></li>
<li><a href="{{ url_for('main.dashboard', _anchor='corpora') }}" style="padding-left: 47px;"><i class="nopaque-icons">I</i>My Corpora</a></li> <li><a href="{{ url_for('main.dashboard', _anchor='corpora') }}" style="padding-left: 47px;"><i class="nopaque-icons">I</i>My Corpora</a></li>
<li><a href="{{ url_for('main.dashboard', _anchor='jobs') }}" style="padding-left: 47px;"><i class="nopaque-icons">J</i>My Jobs</a></li> <li><a href="{{ url_for('main.dashboard', _anchor='jobs') }}" style="padding-left: 47px;"><i class="nopaque-icons">J</i>My Jobs</a></li>
<li><a href="{{ url_for('contributions.contributions') }}"><i class="material-icons">new_label</i>Contribute</a></li> <li><a href="{{ url_for('main.dashboard', _anchor='contributions') }}" style="padding-left: 47px;"><i class="material-icons">new_label</i>My Contributions</a></li>
<li class="social-area-color-base social-area-color-border-darken" style="border-left: 10px solid; margin-top: 5px;"><a href="{{ url_for('main.social_area') }}"><i class="material-icons">group</i>Social Area</a></li> <li class="social-area-color-base social-area-color-border-darken" style="border-left: 10px solid; margin-top: 5px;"><a href="{{ url_for('main.social_area') }}"><i class="material-icons">group</i>Social Area</a></li>
<li><div class="divider"></div></li> <li><div class="divider"></div></li>
<li><a class="subheader">Processes & Services</a></li> <li><a class="subheader">Processes & Services</a></li>

View File

@ -1,44 +0,0 @@
{% extends "base.html.j2" %}
{% import "materialize/wtf.html.j2" as wtf %}
{% block page_content %}
<div class="container">
<div class="row">
<div class="col s12">
<h1 id="title">{{ title }}</h1>
</div>
<div class="col s4">
<div class="card extension-selector hoverable service-color" data-service="tesseract-ocr-pipeline">
<a href="{{ url_for('.tesseract_ocr_pipeline_models') }}" style="position: absolute; width: 100%; height: 100%;"></a>
<div class="card-content">
<span class="card-title" data-service="tesseract-ocr-pipeline">Tesseract OCR Pipeline Models</span>
<p>Here you can see and edit the models that you have created. You can also create new models.</p>
</div>
</div>
</div>
<div class="col s4">
<div class="card extension-selector hoverable service-color" data-service="spacy-nlp-pipeline">
<a href="{{ url_for('.spacy_nlp_pipeline_models') }}" style="position: absolute; width: 100%; height: 100%;"></a>
<div class="card-content">
<span class="card-title">SpaCy NLP Pipeline Models</span>
<p>Here you can see and edit the models that you have created. You can also create new models.</p>
</div>
</div>
</div>
<!--
<div class="col s4">
<div class="card extension-selector hoverable service-color" data-service="transkribus-htr-pipeline">
<a href="" style="position: absolute; width: 100%; height: 100%;"></a>
<div class="card-content">
<span class="card-title">Transkribus HTR Pipeline Models</span>
<p>Here you can see and edit the models that you have created. You can also create new models.</p>
</div>
</div>
</div>
-->
</div>
</div>
{% endblock page_content %}

View File

@ -41,6 +41,39 @@
</div> </div>
</div> </div>
</div> </div>
<div class="col s12" id="contributions">
<h3>My Contributions</h3>
<div class="col s4">
<div class="card extension-selector hoverable service-color" data-service="tesseract-ocr-pipeline">
<a href="{{ url_for('contributions.tesseract_ocr_pipeline_models') }}" style="position: absolute; width: 100%; height: 100%;"></a>
<div class="card-content">
<span class="card-title" data-service="tesseract-ocr-pipeline">Tesseract OCR Pipeline Models</span>
<p>Here you can see and edit the models that you have created. You can also create new models.</p>
</div>
</div>
</div>
<div class="col s4">
<div class="card extension-selector hoverable service-color" data-service="spacy-nlp-pipeline">
<a href="{{ url_for('contributions.spacy_nlp_pipeline_models') }}" style="position: absolute; width: 100%; height: 100%;"></a>
<div class="card-content">
<span class="card-title">SpaCy NLP Pipeline Models</span>
<p>Here you can see and edit the models that you have created. You can also create new models.</p>
</div>
</div>
</div>
<div class="col s4">
<div class="card extension-selector hoverable service-color" data-service="transkribus-htr-pipeline">
<a href="{{ url_for('contributions.transkribus_htr_pipeline_models') }}" style="position: absolute; width: 100%; height: 100%;"></a>
<div class="card-content">
<span class="card-title">Transkribus HTR Pipeline Models</span>
<p>Here you can see and edit the models that you have created. You can also create new models.</p>
</div>
</div>
</div>
</div>
</div> </div>
</div> </div>
{% endblock page_content %} {% endblock page_content %}

View File

@ -78,7 +78,7 @@ def profile_avatar(user_id):
@bp.route('/<hashid:user_id>/edit', methods=['GET', 'POST']) @bp.route('/<hashid:user_id>/edit', methods=['GET', 'POST'])
@register_breadcrumb(bp, '.entity.edit', '<i class="material-icons left">settings</i>Edit', endpoint_arguments_constructor=user_eac) @register_breadcrumb(bp, 'breadcrumbs.settings', '<i class="material-icons left">settings</i>Settings', endpoint_arguments_constructor=user_eac)
@login_required @login_required
def edit_profile(user_id): def edit_profile(user_id):
user = User.query.get_or_404(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, change_password_form=change_password_form,
edit_notification_settings_form=edit_notification_settings_form, edit_notification_settings_form=edit_notification_settings_form,
user=user, user=user,
title='User Settings' title='Settings'
) )