diff --git a/web/app/corpora/events.py b/web/app/corpora/events.py index 22804fbe..c09b7cf4 100644 --- a/web/app/corpora/events.py +++ b/web/app/corpora/events.py @@ -106,6 +106,10 @@ def corpus_analysis_get_meta_data(corpus_id): # write some metadata to the db db_corpus.current_nr_of_tokens = metadata['corpus_size_tokens'] db.session.commit() + event = 'user_{}_patch'.format(db_corpus.user_id) + jsonpatch = [{'op': 'replace', 'path': '/corpora/{}/current_nr_of_tokens'.format(db_corpus.id), 'value': db_corpus.current_nr_of_tokens}] # noqa + room = 'user_{}'.format(db_corpus.user_id) + socketio.emit(event, jsonpatch, room=room) # emit data payload = metadata @@ -300,3 +304,7 @@ def corpus_analysis_session_handler(app, corpus_id, user_id, session_id): corpus_analysis_sessions.pop(corpus_id, None) corpus.status = 'stop analysis' db.session.commit() + event = 'user_{}_patch'.format(corpus.user_id) + jsonpatch = [{'op': 'replace', 'path': '/corpora/{}/status'.format(corpus.id), 'value': corpus.status}] # noqa + room = 'user_{}'.format(corpus.user_id) + socketio.emit(event, jsonpatch, room=room) diff --git a/web/app/corpora/views.py b/web/app/corpora/views.py index cef864c9..91405515 100644 --- a/web/app/corpora/views.py +++ b/web/app/corpora/views.py @@ -153,6 +153,10 @@ def analyse_corpus(corpus_id): if corpus.status == 'prepared': corpus.status = 'start analysis' db.session.commit() + event = 'user_{}_patch'.format(corpus.user_id) + jsonpatch = [{'op': 'replace', 'path': '/corpora/{}/status'.format(corpus.id), 'value': corpus.status}] # noqa + room = 'user_{}'.format(corpus.user_id) + socketio.emit(event, jsonpatch, room=room) display_options_form = DisplayOptionsForm( prefix='display-options-form', result_context=request.args.get('context', 20), @@ -329,13 +333,13 @@ def add_query_result(): filename=form.file.data.filename, title=form.title.data) db.session.add(query_result) - db.session.commit() + db.session.flush() + db.session.refresh(query_result) try: os.makedirs(query_result.path) except OSError: logging.error('Make dir {} led to an OSError!'.format(query_result.path)) # noqa - db.session.delete(query_result) - db.session.commit() + db.session.rollback() flash('Internal Server Error', 'error') return make_response( {'redirect_url': url_for('.add_query_result')}, 500) @@ -361,6 +365,10 @@ def add_query_result(): query_result_file_content.pop('cpos_lookup') query_result.query_metadata = query_result_file_content db.session.commit() + event = 'user_{}_patch'.format(query_result.user_id) + jsonpatch = [{'op': 'add', 'path': '/query_results/{}'.format(query_result.id), 'value': query_result.to_dict()}] # noqa + room = 'user_{}'.format(query_result.user_id) + socketio.emit(event, jsonpatch, room=room) flash('Query result added!', 'result') return make_response({'redirect_url': url_for('.query_result', query_result_id=query_result.id)}, 201) # noqa return render_template('corpora/query_results/add_query_result.html.j2',