From 4950a407afd72ecbc8f5ed7eb92e5d0656c963a1 Mon Sep 17 00:00:00 2001
From: Patrick Jentsch
Date: Mon, 13 Sep 2021 11:45:43 +0200
Subject: [PATCH] rename blueprint variables (blueprint_name -> bp) and view
files (views.py -> routes.py)
---
app/__init__.py | 16 ++++++-------
app/admin/__init__.py | 4 ++--
app/admin/{views.py => routes.py} | 12 +++++-----
app/auth/__init__.py | 4 ++--
app/auth/{views.py => routes.py} | 20 ++++++++--------
app/corpora/__init__.py | 4 ++--
app/corpora/{views.py => routes.py} | 35 ++++++++++++++--------------
app/errors/__init__.py | 4 ++--
app/errors/handlers.py | 10 ++++----
app/jobs/__init__.py | 4 ++--
app/jobs/{views.py => routes.py} | 12 +++++-----
app/main/__init__.py | 4 ++--
app/main/{views.py => routes.py} | 14 +++++------
app/services/__init__.py | 4 ++--
app/services/{views.py => routes.py} | 6 ++---
app/settings/__init__.py | 4 ++--
app/settings/{views.py => routes.py} | 12 +++++-----
requirements.txt | 1 +
18 files changed, 85 insertions(+), 85 deletions(-)
rename app/admin/{views.py => routes.py} (89%)
rename app/auth/{views.py => routes.py} (93%)
rename app/corpora/{views.py => routes.py} (94%)
rename app/jobs/{views.py => routes.py} (90%)
rename app/main/{views.py => routes.py} (86%)
rename app/services/{views.py => routes.py} (96%)
rename app/settings/{views.py => routes.py} (90%)
diff --git a/app/__init__.py b/app/__init__.py
index e7a21381..9a1f7df8 100644
--- a/app/__init__.py
+++ b/app/__init__.py
@@ -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')
diff --git a/app/admin/__init__.py b/app/admin/__init__.py
index 9bb011f8..b5936b4c 100644
--- a/app/admin/__init__.py
+++ b/app/admin/__init__.py
@@ -1,5 +1,5 @@
from flask import Blueprint
-admin = Blueprint('admin', __name__)
-from . import views
+bp = Blueprint('admin', __name__)
+from . import routes
diff --git a/app/admin/views.py b/app/admin/routes.py
similarity index 89%
rename from app/admin/views.py
rename to app/admin/routes.py
index 7f62d4a9..c9a04053 100644
--- a/app/admin/views.py
+++ b/app/admin/routes.py
@@ -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/')
+@bp.route('/users/')
@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//delete')
+@bp.route('/users//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//edit', methods=['GET', 'POST']) # noqa
+@bp.route('/users//edit', methods=['GET', 'POST']) # noqa
@login_required
@admin_required
def edit_user(user_id):
diff --git a/app/auth/__init__.py b/app/auth/__init__.py
index a45dc3f3..6f6ba82d 100644
--- a/app/auth/__init__.py
+++ b/app/auth/__init__.py
@@ -1,5 +1,5 @@
from flask import Blueprint
-auth = Blueprint('auth', __name__)
-from . import views
+bp = Blueprint('auth', __name__)
+from . import routes
diff --git a/app/auth/views.py b/app/auth/routes.py
similarity index 93%
rename from app/auth/views.py
rename to app/auth/routes.py
index b6355642..d45c0644 100644
--- a/app/auth/views.py
+++ b/app/auth/routes.py
@@ -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/')
+@bp.route('/confirm/')
@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/', methods=['GET', 'POST'])
+@bp.route('/reset/', methods=['GET', 'POST'])
def reset_password(token):
if current_user.is_authenticated:
return redirect(url_for('main.dashboard'))
diff --git a/app/corpora/__init__.py b/app/corpora/__init__.py
index 18392bab..af44719d 100644
--- a/app/corpora/__init__.py
+++ b/app/corpora/__init__.py
@@ -1,5 +1,5 @@
from flask import Blueprint
-corpora = Blueprint('corpora', __name__)
-from . import events, views # noqa
\ No newline at end of file
+bp = Blueprint('corpora', __name__)
+from . import events, routes # noqa
diff --git a/app/corpora/views.py b/app/corpora/routes.py
similarity index 94%
rename from app/corpora/views.py
rename to app/corpora/routes.py
index 0c5b9cfe..40ada4bd 100644
--- a/app/corpora/views.py
+++ b/app/corpora/routes.py
@@ -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('/')
+@bp.route('/')
@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('//download')
+@bp.route('//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('//analyse')
+@bp.route('//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('//delete')
+@bp.route('//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('//files/add', methods=['GET', 'POST'])
+@bp.route('//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('//files//delete')
+@bp.route('//files//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('//files//download')
+@bp.route('//files//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('//files/',
- methods=['GET', 'POST'])
+@bp.route('//files/', 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('//prepare')
+@bp.route('//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/')
+@bp.route('/result/')
@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//inspect')
+@bp.route('/result//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//delete')
+@bp.route('/result//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//download')
+@bp.route('/result//download')
@login_required
def download_query_result(query_result_id):
query_result = QueryResult.query.get_or_404(query_result_id)
diff --git a/app/errors/__init__.py b/app/errors/__init__.py
index 3087208b..0d79af48 100644
--- a/app/errors/__init__.py
+++ b/app/errors/__init__.py
@@ -1,5 +1,5 @@
from flask import Blueprint
-errors = Blueprint('errors', __name__)
-from app.errors import handlers
+bp = Blueprint('errors', __name__)
+from . import handlers
diff --git a/app/errors/handlers.py b/app/errors/handlers.py
index c568fd8c..afbc543a 100644
--- a/app/errors/handlers.py
+++ b/app/errors/handlers.py
@@ -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):
diff --git a/app/jobs/__init__.py b/app/jobs/__init__.py
index 07e0e1bb..72244069 100644
--- a/app/jobs/__init__.py
+++ b/app/jobs/__init__.py
@@ -1,5 +1,5 @@
from flask import Blueprint
-jobs = Blueprint('jobs', __name__)
-from . import views
+bp = Blueprint('jobs', __name__)
+from . import routes
diff --git a/app/jobs/views.py b/app/jobs/routes.py
similarity index 90%
rename from app/jobs/views.py
rename to app/jobs/routes.py
index 4101c7ae..5db5692f 100644
--- a/app/jobs/views.py
+++ b/app/jobs/routes.py
@@ -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('/')
+@bp.route('/')
@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('//delete')
+@bp.route('//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('//inputs//download')
+@bp.route('//inputs//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('//restart')
+@bp.route('//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('//results//download')
+@bp.route('//results//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
diff --git a/app/main/__init__.py b/app/main/__init__.py
index d658fca7..65630224 100644
--- a/app/main/__init__.py
+++ b/app/main/__init__.py
@@ -1,5 +1,5 @@
from flask import Blueprint
-main = Blueprint('main', __name__)
-from . import views
+bp = Blueprint('main', __name__)
+from . import routes
diff --git a/app/main/views.py b/app/main/routes.py
similarity index 86%
rename from app/main/views.py
rename to app/main/routes.py
index 6f3816de..9edf5b99 100644
--- a/app/main/views.py
+++ b/app/main/routes.py
@@ -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')
diff --git a/app/services/__init__.py b/app/services/__init__.py
index 832a715f..5c553e89 100644
--- a/app/services/__init__.py
+++ b/app/services/__init__.py
@@ -73,5 +73,5 @@ SERVICES = {
}
-services = Blueprint('services', __name__)
-from . import views
+bp = Blueprint('services', __name__)
+from . import routes
diff --git a/app/services/views.py b/app/services/routes.py
similarity index 96%
rename from app/services/views.py
rename to app/services/routes.py
index 90d24bdd..b69c4e10 100644
--- a/app/services/views.py
+++ b/app/services/routes.py
@@ -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('/', methods=['GET', 'POST'])
+@bp.route('/', methods=['GET', 'POST'])
@login_required
def service(service):
# Check if the requested service exist
diff --git a/app/settings/__init__.py b/app/settings/__init__.py
index 2329d880..1dab5142 100644
--- a/app/settings/__init__.py
+++ b/app/settings/__init__.py
@@ -1,5 +1,5 @@
from flask import Blueprint
-settings = Blueprint('settings', __name__)
-from . import views # noqa
+bp = Blueprint('settings', __name__)
+from . import routes # noqa
diff --git a/app/settings/views.py b/app/settings/routes.py
similarity index 90%
rename from app/settings/views.py
rename to app/settings/routes.py
index a7fc0b38..ebc3a385 100644
--- a/app/settings/views.py
+++ b/app/settings/routes.py
@@ -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():
"""
diff --git a/requirements.txt b/requirements.txt
index 5faa3cee..95816e15 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -7,6 +7,7 @@ Flask-Login
Flask-Mail
Flask-Migrate
Flask-Paranoid
+Flask-RestPlus
Flask-SocketIO~=5.0.0
Flask-SQLAlchemy
Flask-WTF