diff --git a/app/corpora/background_functions.py b/app/corpora/background_functions.py index e12cf51c..442b9424 100644 --- a/app/corpora/background_functions.py +++ b/app/corpora/background_functions.py @@ -3,7 +3,7 @@ from app.models import Corpus, CorpusFile def delete_corpus_(app, corpus_id): with app.app_context(): - corpus = Corpus.query.filter_by(id=corpus_id).first() + corpus = Corpus.query.get(corpus_id) if corpus is None: raise Exception('Corpus {} not found!'.format(corpus_id)) corpus.delete() @@ -11,7 +11,7 @@ def delete_corpus_(app, corpus_id): def delete_corpus_file_(app, corpus_file_id): with app.app_context(): - corpus_file = CorpusFile.query.filter_by(id=corpus_file_id).first() + corpus_file = CorpusFile.query.get(corpus_file_id) if corpus_file is None: raise Exception('Corpus file {} not found!'.format(corpus_file_id)) corpus_file.delete() @@ -19,7 +19,7 @@ def delete_corpus_file_(app, corpus_file_id): def edit_corpus_file_(app, corpus_file_id): with app.app_context(): - corpus_file = CorpusFile.query.filter_by(id=corpus_file_id).first() + corpus_file = CorpusFile.query.get(corpus_file_id) if corpus_file is None: raise Exception('Corpus file {} not found!'.format(corpus_file_id)) corpus_file.insert_metadata() diff --git a/app/corpora/events.py b/app/corpora/events.py index 81c184c9..c25aadbe 100644 --- a/app/corpora/events.py +++ b/app/corpora/events.py @@ -22,7 +22,7 @@ analysis_clients = {} @socketio.on('init_corpus_analysis') @login_required def init_corpus_analysis(corpus_id): - corpus = Corpus.query.filter_by(id=corpus_id).first() + corpus = Corpus.query.get(corpus_id) if corpus is None: socketio.emit('init_corpus_analysis', '[ERROR 404]: Not Found', room=request.sid) @@ -85,7 +85,10 @@ def recv_query(message): def observe_corpus_analysis_connection(app, corpus_id, session_id): with app.app_context(): - corpus = Corpus.query.filter_by(id=corpus_id).first() + corpus = Corpus.query.get(corpus_id) + if corpus is None: + ''' TODO: Handle this ''' + return while corpus.status != 'analysing': db.session.refresh(corpus) socketio.sleep(3) diff --git a/app/events.py b/app/events.py index 73022cc5..c05ea980 100644 --- a/app/events.py +++ b/app/events.py @@ -72,7 +72,10 @@ def user_ressource_subscription_handler(app, user_id, session_id, else 'update-jobs'} with app.app_context(): # Gather current values from database. - user = User.query.filter_by(id=user_id).first() + user = User.query.get(user_id) + if user is None: + ''' TODO: Handle this ''' + return corpora = {corpus.id: corpus.to_dict() for corpus in user.corpora} jobs = {job.id: job.to_dict() for job in user.jobs} # Send initial values to the user. diff --git a/app/jobs/background_functions.py b/app/jobs/background_functions.py index db47332e..f90c2daa 100644 --- a/app/jobs/background_functions.py +++ b/app/jobs/background_functions.py @@ -3,7 +3,7 @@ from app.models import Job def delete_job_(app, job_id): with app.app_context(): - job = Job.query.filter_by(id=job_id).first() + job = Job.query.get(job_id) if job is None: raise Exception('Job {} not found!'.format(job_id)) job.delete() diff --git a/app/profile/background_functions.py b/app/profile/background_functions.py index db136f72..62be9b6f 100644 --- a/app/profile/background_functions.py +++ b/app/profile/background_functions.py @@ -3,7 +3,7 @@ from app.models import User def delete_user_(app, user_id): with app.app_context(): - user = User.query.filter_by(id=user_id).first() + user = User.query.get(user_id) if user is None: raise Exception('User {} not found!'.format(user_id)) user.delete()