diff --git a/app/admin/views.py b/app/admin/views.py index 566fbac9..0cc915b1 100644 --- a/app/admin/views.py +++ b/app/admin/views.py @@ -2,7 +2,7 @@ from app import db from app.decorators import admin_required from app.models import Role, User from app.tables import AdminUserItem, AdminUserTable -from app.background_functions import delete_user_ +from app.profile.background_functions import delete_user_ from flask import current_app, flash, redirect, render_template, url_for from flask_login import login_required from . import admin @@ -31,7 +31,7 @@ def for_admins_only(): @login_required @admin_required def admin_user_page(user_id): - selected_user = User.query.filter_by(id=user_id).first() + selected_user = User.query.get_or_404(user_id) title = 'Administration of user {} with ID: {}'.format( selected_user.username, selected_user.id diff --git a/app/auth/views.py b/app/auth/views.py index 146294f3..74afc490 100644 --- a/app/auth/views.py +++ b/app/auth/views.py @@ -41,15 +41,15 @@ def logout(): def register(): if not current_user.is_anonymous: return redirect(url_for('main.dashboard')) - form = RegistrationForm() - if form.validate_on_submit(): - user = User(email=form.email.data.lower(), - password=form.password.data, - username=form.username.data) + registration_form = RegistrationForm() + if registration_form.validate_on_submit(): + user = User(email=registration_form.email.data.lower(), + password=registration_form.password.data, + username=registration_form.username.data) db.session.add(user) db.session.commit() dir = os.path.join(current_app.config['OPAQUE_STORAGE_DIRECTORY'], - str(job.user_id), 'jobs', str(job.id)) + str(user.id)) try: os.makedirs(dir) except OSError: @@ -57,15 +57,11 @@ def register(): user.delete() else: token = user.generate_confirmation_token() - send_email(user.email, - 'Confirm Your Account', - 'auth/email/confirm', - token=token, - user=user) + send_email(user.email, 'Confirm Your Account', + 'auth/email/confirm', token=token, user=user) flash('A confirmation email has been sent to you by email.') return redirect(url_for('auth.login')) - return render_template('auth/register.html.j2', - form=form, + return render_template('auth/register.html.j2', form=registration_form, title='Register') diff --git a/app/background_functions.py b/app/background_functions.py deleted file mode 100644 index b98b3bd1..00000000 --- a/app/background_functions.py +++ /dev/null @@ -1,25 +0,0 @@ -from .models import Corpus, Job, User - - -def delete_corpus_(app, corpus_id): - with app.app_context(): - corpus = Corpus.query.filter_by(id=corpus_id).first() - if corpus is None: - raise Exception('Corpus {} not found!'.format(corpus_id)) - corpus.delete() - - -def delete_job_(app, job_id): - with app.app_context(): - job = Job.query.filter_by(id=job_id).first() - if job is None: - raise Exception('Job {} not found!'.format(job_id)) - job.delete() - - -def delete_user_(app, user_id): - with app.app_context(): - user = User.query.filter_by(id=user_id).first() - if user is None: - raise Exception('User {} not found!'.format(user_id)) - user.delete() diff --git a/app/jobs/background_functions.py b/app/jobs/background_functions.py new file mode 100644 index 00000000..db47332e --- /dev/null +++ b/app/jobs/background_functions.py @@ -0,0 +1,9 @@ +from app.models import Job + + +def delete_job_(app, job_id): + with app.app_context(): + job = Job.query.filter_by(id=job_id).first() + if job is None: + raise Exception('Job {} not found!'.format(job_id)) + job.delete() diff --git a/app/jobs/views.py b/app/jobs/views.py index 20b86a23..7b1b24fd 100644 --- a/app/jobs/views.py +++ b/app/jobs/views.py @@ -1,9 +1,9 @@ from app.models import Job, JobInput, JobResult -from app.background_functions import delete_job_ from flask import (abort, current_app, flash, redirect, render_template, send_from_directory, url_for) from flask_login import current_user, login_required from . import jobs +from .background_functions import delete_job_ import os import threading diff --git a/app/profile/background_functions.py b/app/profile/background_functions.py new file mode 100644 index 00000000..db136f72 --- /dev/null +++ b/app/profile/background_functions.py @@ -0,0 +1,9 @@ +from app.models import User + + +def delete_user_(app, user_id): + with app.app_context(): + user = User.query.filter_by(id=user_id).first() + if user is None: + raise Exception('User {} not found!'.format(user_id)) + user.delete() diff --git a/app/profile/views.py b/app/profile/views.py index 2eaa1b02..82423059 100644 --- a/app/profile/views.py +++ b/app/profile/views.py @@ -1,8 +1,8 @@ from app import db, logger -from app.background_functions import delete_user_ from flask import abort, current_app, flash, redirect, render_template, url_for from flask_login import current_user, login_required, logout_user from . import profile +from .background_functions import delete_user_ from .forms import ChangePasswordForm, EditProfileForm, EditUserSettingsForm import threading