Update background functions

This commit is contained in:
Patrick Jentsch 2019-11-14 13:40:05 +01:00
parent 7dd55c47a0
commit 1b02d73d66
7 changed files with 31 additions and 42 deletions

View File

@ -2,7 +2,7 @@ from app import db
from app.decorators import admin_required from app.decorators import admin_required
from app.models import Role, User from app.models import Role, User
from app.tables import AdminUserItem, AdminUserTable 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 import current_app, flash, redirect, render_template, url_for
from flask_login import login_required from flask_login import login_required
from . import admin from . import admin
@ -31,7 +31,7 @@ def for_admins_only():
@login_required @login_required
@admin_required @admin_required
def admin_user_page(user_id): 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( title = 'Administration of user {} with ID: {}'.format(
selected_user.username, selected_user.username,
selected_user.id selected_user.id

View File

@ -41,15 +41,15 @@ def logout():
def register(): def register():
if not current_user.is_anonymous: if not current_user.is_anonymous:
return redirect(url_for('main.dashboard')) return redirect(url_for('main.dashboard'))
form = RegistrationForm() registration_form = RegistrationForm()
if form.validate_on_submit(): if registration_form.validate_on_submit():
user = User(email=form.email.data.lower(), user = User(email=registration_form.email.data.lower(),
password=form.password.data, password=registration_form.password.data,
username=form.username.data) username=registration_form.username.data)
db.session.add(user) db.session.add(user)
db.session.commit() db.session.commit()
dir = os.path.join(current_app.config['OPAQUE_STORAGE_DIRECTORY'], dir = os.path.join(current_app.config['OPAQUE_STORAGE_DIRECTORY'],
str(job.user_id), 'jobs', str(job.id)) str(user.id))
try: try:
os.makedirs(dir) os.makedirs(dir)
except OSError: except OSError:
@ -57,15 +57,11 @@ def register():
user.delete() user.delete()
else: else:
token = user.generate_confirmation_token() token = user.generate_confirmation_token()
send_email(user.email, send_email(user.email, 'Confirm Your Account',
'Confirm Your Account', 'auth/email/confirm', token=token, user=user)
'auth/email/confirm',
token=token,
user=user)
flash('A confirmation email has been sent to you by email.') flash('A confirmation email has been sent to you by email.')
return redirect(url_for('auth.login')) return redirect(url_for('auth.login'))
return render_template('auth/register.html.j2', return render_template('auth/register.html.j2', form=registration_form,
form=form,
title='Register') title='Register')

View File

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

View File

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

View File

@ -1,9 +1,9 @@
from app.models import Job, JobInput, JobResult from app.models import Job, JobInput, JobResult
from app.background_functions import delete_job_
from flask import (abort, current_app, flash, redirect, render_template, from flask import (abort, current_app, flash, redirect, render_template,
send_from_directory, url_for) send_from_directory, url_for)
from flask_login import current_user, login_required from flask_login import current_user, login_required
from . import jobs from . import jobs
from .background_functions import delete_job_
import os import os
import threading import threading

View File

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

View File

@ -1,8 +1,8 @@
from app import db, logger 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 import abort, current_app, flash, redirect, render_template, url_for
from flask_login import current_user, login_required, logout_user from flask_login import current_user, login_required, logout_user
from . import profile from . import profile
from .background_functions import delete_user_
from .forms import ChangePasswordForm, EditProfileForm, EditUserSettingsForm from .forms import ChangePasswordForm, EditProfileForm, EditUserSettingsForm
import threading import threading