rename blueprint variables (blueprint_name -> bp) and view files (views.py -> routes.py)

This commit is contained in:
Patrick Jentsch 2021-09-13 11:45:43 +02:00
parent bc5c8ef074
commit 4950a407af
18 changed files with 85 additions and 85 deletions

View File

@ -34,14 +34,14 @@ def create_app(config_name):
with app.app_context():
from .events import socketio as socketio_events
from .events import sqlalchemy as sqlalchemy_events
from .admin import admin as admin_blueprint
from .auth import auth as auth_blueprint
from .corpora import corpora as corpora_blueprint
from .errors import errors as errors_blueprint
from .jobs import jobs as jobs_blueprint
from .main import main as main_blueprint
from .services import services as services_blueprint
from .settings import settings as settings_blueprint
from .admin import bp as admin_blueprint
from .auth import bp as auth_blueprint
from .corpora import bp as corpora_blueprint
from .errors import bp as errors_blueprint
from .jobs import bp as jobs_blueprint
from .main import bp as main_blueprint
from .services import bp as services_blueprint
from .settings import bp as settings_blueprint
app.register_blueprint(admin_blueprint, url_prefix='/admin')
app.register_blueprint(auth_blueprint, url_prefix='/auth')

View File

@ -1,5 +1,5 @@
from flask import Blueprint
admin = Blueprint('admin', __name__)
from . import views
bp = Blueprint('admin', __name__)
from . import routes

View File

@ -1,6 +1,6 @@
from flask import flash, redirect, render_template, url_for
from flask_login import login_required
from . import admin
from . import bp
from .forms import EditGeneralSettingsAdminForm
from .. import db
from ..decorators import admin_required
@ -8,14 +8,14 @@ from ..models import Role, User
from ..settings import tasks as settings_tasks
@admin.route('/')
@bp.route('/')
@login_required
@admin_required
def index():
return redirect(url_for('.users'))
@admin.route('/users')
@bp.route('/users')
@login_required
@admin_required
def users():
@ -24,7 +24,7 @@ def users():
return render_template('admin/users.html.j2', title='Users', users=users)
@admin.route('/users/<int:user_id>')
@bp.route('/users/<int:user_id>')
@login_required
@admin_required
def user(user_id):
@ -32,7 +32,7 @@ def user(user_id):
return render_template('admin/user.html.j2', title='User', user=user)
@admin.route('/users/<int:user_id>/delete')
@bp.route('/users/<int:user_id>/delete')
@login_required
@admin_required
def delete_user(user_id):
@ -41,7 +41,7 @@ def delete_user(user_id):
return redirect(url_for('.users'))
@admin.route('/users/<int:user_id>/edit', methods=['GET', 'POST']) # noqa
@bp.route('/users/<int:user_id>/edit', methods=['GET', 'POST']) # noqa
@login_required
@admin_required
def edit_user(user_id):

View File

@ -1,5 +1,5 @@
from flask import Blueprint
auth = Blueprint('auth', __name__)
from . import views
bp = Blueprint('auth', __name__)
from . import routes

View File

@ -1,7 +1,7 @@
from datetime import datetime
from flask import abort, flash, redirect, render_template, request, url_for
from flask_login import current_user, login_user, login_required, logout_user
from . import auth
from . import bp
from .forms import (LoginForm, ResetPasswordForm, ResetPasswordRequestForm,
RegistrationForm)
from .. import db
@ -11,7 +11,7 @@ import logging
import os
@auth.before_app_request
@bp.before_app_request
def before_request():
"""
Checks if a user is unconfirmed when visiting specific sites. Redirects to
@ -27,7 +27,7 @@ def before_request():
return redirect(url_for('auth.unconfirmed'))
@auth.route('/login', methods=['GET', 'POST'])
@bp.route('/login', methods=['GET', 'POST'])
def login():
if current_user.is_authenticated:
return redirect(url_for('main.dashboard'))
@ -46,7 +46,7 @@ def login():
return render_template('auth/login.html.j2', form=form, title='Log in')
@auth.route('/logout')
@bp.route('/logout')
@login_required
def logout():
logout_user()
@ -54,7 +54,7 @@ def logout():
return redirect(url_for('main.index'))
@auth.route('/register', methods=['GET', 'POST'])
@bp.route('/register', methods=['GET', 'POST'])
def register():
if current_user.is_authenticated:
return redirect(url_for('main.dashboard'))
@ -83,7 +83,7 @@ def register():
title='Register')
@auth.route('/confirm/<token>')
@bp.route('/confirm/<token>')
@login_required
def confirm(token):
if current_user.confirmed:
@ -97,7 +97,7 @@ def confirm(token):
return redirect(url_for('.unconfirmed'))
@auth.route('/unconfirmed')
@bp.route('/unconfirmed')
def unconfirmed():
if current_user.is_anonymous:
return redirect(url_for('main.index'))
@ -106,7 +106,7 @@ def unconfirmed():
return render_template('auth/unconfirmed.html.j2', title='Unconfirmed')
@auth.route('/confirm')
@bp.route('/confirm')
@login_required
def resend_confirmation():
token = current_user.generate_confirmation_token()
@ -117,7 +117,7 @@ def resend_confirmation():
return redirect(url_for('auth.unconfirmed'))
@auth.route('/reset', methods=['GET', 'POST'])
@bp.route('/reset', methods=['GET', 'POST'])
def reset_password_request():
if current_user.is_authenticated:
return redirect(url_for('main.dashboard'))
@ -136,7 +136,7 @@ def reset_password_request():
title='Password Reset')
@auth.route('/reset/<token>', methods=['GET', 'POST'])
@bp.route('/reset/<token>', methods=['GET', 'POST'])
def reset_password(token):
if current_user.is_authenticated:
return redirect(url_for('main.dashboard'))

View File

@ -1,5 +1,5 @@
from flask import Blueprint
corpora = Blueprint('corpora', __name__)
from . import events, views # noqa
bp = Blueprint('corpora', __name__)
from . import events, routes # noqa

View File

@ -1,7 +1,7 @@
from flask import (abort, flash, make_response, redirect, request,
render_template, url_for, send_from_directory)
from flask_login import current_user, login_required
from . import corpora
from . import bp
from . import tasks
from .forms import (AddCorpusFileForm, AddCorpusForm, AddQueryResultForm,
EditCorpusFileForm, QueryDownloadForm, QueryForm,
@ -20,7 +20,7 @@ from zipfile import ZipFile
from .import_corpus import check_zip_contents
@corpora.route('/add', methods=['GET', 'POST'])
@bp.route('/add', methods=['GET', 'POST'])
@login_required
def add_corpus():
form = AddCorpusForm()
@ -45,7 +45,7 @@ def add_corpus():
title='Add corpus')
@corpora.route('/import', methods=['GET', 'POST'])
@bp.route('/import', methods=['GET', 'POST'])
@login_required
def import_corpus():
form = ImportCorpusForm()
@ -114,7 +114,7 @@ def import_corpus():
title='Import Corpus')
@corpora.route('/<int:corpus_id>')
@bp.route('/<int:corpus_id>')
@login_required
def corpus(corpus_id):
corpus = Corpus.query.get_or_404(corpus_id)
@ -125,7 +125,7 @@ def corpus(corpus_id):
corpus_files=corpus_files, title='Corpus')
@corpora.route('/<int:corpus_id>/download')
@bp.route('/<int:corpus_id>/download')
@login_required
def download_corpus(corpus_id):
corpus = Corpus.query.get_or_404(corpus_id)
@ -139,7 +139,7 @@ def download_corpus(corpus_id):
)
@corpora.route('/<int:corpus_id>/analyse')
@bp.route('/<int:corpus_id>/analyse')
@login_required
def analyse_corpus(corpus_id):
corpus = Corpus.query.get_or_404(corpus_id)
@ -164,7 +164,7 @@ def analyse_corpus(corpus_id):
)
@corpora.route('/<int:corpus_id>/delete')
@bp.route('/<int:corpus_id>/delete')
@login_required
def delete_corpus(corpus_id):
corpus = Corpus.query.get_or_404(corpus_id)
@ -175,7 +175,7 @@ def delete_corpus(corpus_id):
return redirect(url_for('main.dashboard'))
@corpora.route('/<int:corpus_id>/files/add', methods=['GET', 'POST'])
@bp.route('/<int:corpus_id>/files/add', methods=['GET', 'POST'])
@login_required
def add_corpus_file(corpus_id):
corpus = Corpus.query.get_or_404(corpus_id)
@ -210,7 +210,7 @@ def add_corpus_file(corpus_id):
form=form, title='Add corpus file')
@corpora.route('/<int:corpus_id>/files/<int:corpus_file_id>/delete')
@bp.route('/<int:corpus_id>/files/<int:corpus_file_id>/delete')
@login_required
def delete_corpus_file(corpus_id, corpus_file_id):
corpus_file = CorpusFile.query.get_or_404(corpus_file_id)
@ -224,7 +224,7 @@ def delete_corpus_file(corpus_id, corpus_file_id):
return redirect(url_for('.corpus', corpus_id=corpus_id))
@corpora.route('/<int:corpus_id>/files/<int:corpus_file_id>/download')
@bp.route('/<int:corpus_id>/files/<int:corpus_file_id>/download')
@login_required
def download_corpus_file(corpus_id, corpus_file_id):
corpus_file = CorpusFile.query.get_or_404(corpus_file_id)
@ -238,8 +238,7 @@ def download_corpus_file(corpus_id, corpus_file_id):
filename=corpus_file.filename)
@corpora.route('/<int:corpus_id>/files/<int:corpus_file_id>',
methods=['GET', 'POST'])
@bp.route('/<int:corpus_id>/files/<int:corpus_file_id>', methods=['GET', 'POST'])
@login_required
def corpus_file(corpus_id, corpus_file_id):
corpus = Corpus.query.get_or_404(corpus_id)
@ -284,7 +283,7 @@ def corpus_file(corpus_id, corpus_file_id):
title='Edit corpus file')
@corpora.route('/<int:corpus_id>/prepare')
@bp.route('/<int:corpus_id>/prepare')
@login_required
def prepare_corpus(corpus_id):
corpus = Corpus.query.get_or_404(corpus_id)
@ -299,7 +298,7 @@ def prepare_corpus(corpus_id):
# Following are view functions to add, view etc. exported results.
@corpora.route('/result/add', methods=['GET', 'POST'])
@bp.route('/result/add', methods=['GET', 'POST'])
@login_required
def add_query_result():
'''
@ -350,7 +349,7 @@ def add_query_result():
form=form, title='Add query result')
@corpora.route('/result/<int:query_result_id>')
@bp.route('/result/<int:query_result_id>')
@login_required
def query_result(query_result_id):
query_result = QueryResult.query.get_or_404(query_result_id)
@ -361,7 +360,7 @@ def query_result(query_result_id):
query_result=query_result, title='Query result')
@corpora.route('/result/<int:query_result_id>/inspect')
@bp.route('/result/<int:query_result_id>/inspect')
@login_required
def inspect_query_result(query_result_id):
'''
@ -391,7 +390,7 @@ def inspect_query_result(query_result_id):
title='Inspect query result')
@corpora.route('/result/<int:query_result_id>/delete')
@bp.route('/result/<int:query_result_id>/delete')
@login_required
def delete_query_result(query_result_id):
query_result = QueryResult.query.get_or_404(query_result_id)
@ -403,7 +402,7 @@ def delete_query_result(query_result_id):
return redirect(url_for('services.service', service="corpus_analysis"))
@corpora.route('/result/<int:query_result_id>/download')
@bp.route('/result/<int:query_result_id>/download')
@login_required
def download_query_result(query_result_id):
query_result = QueryResult.query.get_or_404(query_result_id)

View File

@ -1,5 +1,5 @@
from flask import Blueprint
errors = Blueprint('errors', __name__)
from app.errors import handlers
bp = Blueprint('errors', __name__)
from . import handlers

View File

@ -1,8 +1,8 @@
from flask import render_template, request, jsonify
from . import errors
from . import bp
@errors.app_errorhandler(403)
@bp.app_errorhandler(403)
def forbidden(e):
if (request.accept_mimetypes.accept_json
and not request.accept_mimetypes.accept_html):
@ -12,7 +12,7 @@ def forbidden(e):
return render_template('errors/403.html.j2', title='Forbidden'), 403
@errors.app_errorhandler(404)
@bp.app_errorhandler(404)
def not_found(e):
if (request.accept_mimetypes.accept_json
and not request.accept_mimetypes.accept_html):
@ -22,7 +22,7 @@ def not_found(e):
return render_template('errors/404.html.j2', title='Not Found'), 404
@errors.app_errorhandler(413)
@bp.app_errorhandler(413)
def payload_too_large(e):
if (request.accept_mimetypes.accept_json
and not request.accept_mimetypes.accept_html):
@ -32,7 +32,7 @@ def payload_too_large(e):
return render_template('errors/413.html.j2', title='Payload Too Large'), 413
@errors.app_errorhandler(500)
@bp.app_errorhandler(500)
def internal_server_error(e):
if (request.accept_mimetypes.accept_json
and not request.accept_mimetypes.accept_html):

View File

@ -1,5 +1,5 @@
from flask import Blueprint
jobs = Blueprint('jobs', __name__)
from . import views
bp = Blueprint('jobs', __name__)
from . import routes

View File

@ -1,14 +1,14 @@
from flask import (abort, flash, redirect, render_template,
send_from_directory, url_for)
from flask_login import current_user, login_required
from . import jobs
from . import bp
from . import tasks
from ..decorators import admin_required
from ..models import Job, JobInput, JobResult
import os
@jobs.route('/<int:job_id>')
@bp.route('/<int:job_id>')
@login_required
def job(job_id):
job = Job.query.get_or_404(job_id)
@ -19,7 +19,7 @@ def job(job_id):
title='Job')
@jobs.route('/<int:job_id>/delete')
@bp.route('/<int:job_id>/delete')
@login_required
def delete_job(job_id):
job = Job.query.get_or_404(job_id)
@ -30,7 +30,7 @@ def delete_job(job_id):
return redirect(url_for('main.dashboard'))
@jobs.route('/<int:job_id>/inputs/<int:job_input_id>/download')
@bp.route('/<int:job_id>/inputs/<int:job_input_id>/download')
@login_required
def download_job_input(job_id, job_input_id):
job_input = JobInput.query.filter(JobInput.job_id == job_id, JobInput.id == job_input_id).first_or_404() # noqa
@ -42,7 +42,7 @@ def download_job_input(job_id, job_input_id):
filename=job_input.filename)
@jobs.route('/<int:job_id>/restart')
@bp.route('/<int:job_id>/restart')
@login_required
@admin_required
def restart(job_id):
@ -55,7 +55,7 @@ def restart(job_id):
return redirect(url_for('.job', job_id=job_id))
@jobs.route('/<int:job_id>/results/<int:job_result_id>/download')
@bp.route('/<int:job_id>/results/<int:job_result_id>/download')
@login_required
def download_job_result(job_id, job_result_id):
job_result = JobResult.query.filter(JobResult.job_id == job_id, JobResult.id == job_result_id).first_or_404() # noqa

View File

@ -1,5 +1,5 @@
from flask import Blueprint
main = Blueprint('main', __name__)
from . import views
bp = Blueprint('main', __name__)
from . import routes

View File

@ -1,11 +1,11 @@
from flask import flash, redirect, render_template, url_for
from flask_login import login_required, login_user
from . import main
from . import bp
from ..auth.forms import LoginForm
from ..models import User
@main.route('/', methods=['GET', 'POST'])
@bp.route('/', methods=['GET', 'POST'])
def index():
form = LoginForm(prefix='login-form')
if form.validate_on_submit():
@ -19,28 +19,28 @@ def index():
return render_template('main/index.html.j2', form=form, title='nopaque')
@main.route('/about_and_faq')
@bp.route('/about_and_faq')
def about_and_faq():
return render_template('main/about_and_faq.html.j2', title='About and faq')
@main.route('/dashboard')
@bp.route('/dashboard')
@login_required
def dashboard():
return render_template('main/dashboard.html.j2', title='Dashboard')
@main.route('/news')
@bp.route('/news')
def news():
return render_template('main/news.html.j2', title='News')
@main.route('/privacy_policy')
@bp.route('/privacy_policy')
def privacy_policy():
return render_template('main/privacy_policy.html.j2',
title='Privacy statement (GDPR)')
@main.route('/terms_of_use')
@bp.route('/terms_of_use')
def terms_of_use():
return render_template('main/terms_of_use.html.j2', title='Terms of Use')

View File

@ -73,5 +73,5 @@ SERVICES = {
}
services = Blueprint('services', __name__)
from . import views
bp = Blueprint('services', __name__)
from . import routes

View File

@ -2,7 +2,7 @@ from flask import (abort, flash, make_response, render_template, request,
url_for)
from flask_login import current_user, login_required
from werkzeug.utils import secure_filename
from . import services
from . import bp
from . import SERVICES
from .. import db
from .forms import AddJobForms
@ -12,14 +12,14 @@ import logging
import os
@services.route('/corpus-analysis')
@bp.route('/corpus-analysis')
@login_required
def corpus_analysis():
return render_template('services/corpus_analysis.html.j2',
title='Corpus analysis')
@services.route('/<service>', methods=['GET', 'POST'])
@bp.route('/<service>', methods=['GET', 'POST'])
@login_required
def service(service):
# Check if the requested service exist

View File

@ -1,5 +1,5 @@
from flask import Blueprint
settings = Blueprint('settings', __name__)
from . import views # noqa
bp = Blueprint('settings', __name__)
from . import routes # noqa

View File

@ -1,18 +1,18 @@
from flask import flash, redirect, render_template, url_for
from flask_login import current_user, login_required, logout_user
from . import settings, tasks
from . import bp, tasks
from .forms import (ChangePasswordForm, EditGeneralSettingsForm,
EditNotificationSettingsForm)
from .. import db
@settings.route('/')
@bp.route('/')
@login_required
def index():
return redirect(url_for('.edit_general_settings'))
@settings.route('/change_password', methods=['GET', 'POST'])
@bp.route('/change_password', methods=['GET', 'POST'])
@login_required
def change_password():
form = ChangePasswordForm()
@ -25,7 +25,7 @@ def change_password():
form=form, title='Change password')
@settings.route('/edit_general_settings', methods=['GET', 'POST'])
@bp.route('/edit_general_settings', methods=['GET', 'POST'])
@login_required
def edit_general_settings():
form = EditGeneralSettingsForm()
@ -43,7 +43,7 @@ def edit_general_settings():
form=form, title='General settings')
@settings.route('/edit_notification_settings', methods=['GET', 'POST'])
@bp.route('/edit_notification_settings', methods=['GET', 'POST'])
@login_required
def edit_notification_settings():
form = EditNotificationSettingsForm()
@ -63,7 +63,7 @@ def edit_notification_settings():
form=form, title='Notification settings')
@settings.route('/delete')
@bp.route('/delete')
@login_required
def delete():
"""

View File

@ -7,6 +7,7 @@ Flask-Login
Flask-Mail
Flask-Migrate
Flask-Paranoid
Flask-RestPlus
Flask-SocketIO~=5.0.0
Flask-SQLAlchemy
Flask-WTF