diff --git a/app/corpora/events.py b/app/corpora/events.py index 1fa74fe4..713cffbc 100644 --- a/app/corpora/events.py +++ b/app/corpora/events.py @@ -1,6 +1,6 @@ from app import db, logger, socketio from app.events import connected_sessions -from app.models import Corpus +from app.models import Corpus, User from flask import current_app, request from flask_login import current_user, login_required from .CQiWrapper.CQiWrapper import CQiWrapper @@ -17,21 +17,13 @@ corpus_analysis_sessions = {} corpus_analysis_clients = {} -@socketio.on('request_corpus_analysis') +@socketio.on('corpus_analysis_init') @login_required -def request_corpus_analysis(corpus_id): - corpus = Corpus.query.get(corpus_id) - if corpus is None: - socketio.emit('init_corpus_analysis', '[404]: Not Found', - room=request.sid) - elif not (corpus.creator == current_user - or current_user.is_administrator()): - socketio.emit('init_corpus_analysis', '[403]: Forbidden', - room=request.sid) - else: - socketio.start_background_task(corpus_analysis_session_handler, - current_app._get_current_object(), - corpus_id, request.sid) +def init_corpus_analysis(corpus_id): + logger.warning("a") + socketio.start_background_task(corpus_analysis_session_handler, + current_app._get_current_object(), + corpus_id, current_user.id, request.sid) @socketio.on('corpus_analysis') @@ -91,10 +83,21 @@ def inspect_match(message): socketio.emit('match_context', match_context, room=request.sid) -def corpus_analysis_session_handler(app, corpus_id, session_id): +def corpus_analysis_session_handler(app, corpus_id, user_id, session_id): with app.app_context(): ''' Setup analysis session ''' corpus = Corpus.query.get(corpus_id) + user = User.query.get(user_id) + if corpus is None: + logger.warning("404") + response = {'code': 404, 'msg': 'Not Found'} + socketio.emit('corpus_analysis_init', response, room=session_id) + return + elif not (corpus.creator == user or user.is_administrator()): + logger.warning("403") + response = {'code': 403, 'msg': 'Forbidden'} + socketio.emit('corpus_analysis_init', response, room=session_id) + return while corpus.status != 'analysing': db.session.refresh(corpus) socketio.sleep(3) @@ -105,8 +108,8 @@ def corpus_analysis_session_handler(app, corpus_id, session_id): corpus_analysis_sessions[corpus_id] = [session_id] else: corpus_analysis_sessions[corpus_id].append(session_id) - socketio.emit('request_corpus_analysis', '[201]: Created', - room=session_id) + response = {'code': 201, 'msg': 'Created'} + socketio.emit('corpus_analysis_init', response, room=session_id) ''' Observe analysis session ''' while session_id in connected_sessions: socketio.sleep(3) diff --git a/app/corpora/forms.py b/app/corpora/forms.py index 52bbb36a..e6fadb12 100644 --- a/app/corpora/forms.py +++ b/app/corpora/forms.py @@ -1,6 +1,6 @@ from flask_wtf import FlaskForm -from wtforms import (FileField, StringField, SubmitField, - ValidationError, IntegerField, SelectField, TextAreaField) +from wtforms import (BooleanField, FileField, StringField, SubmitField, + ValidationError, IntegerField, SelectField) from wtforms.validators import DataRequired, Length @@ -50,7 +50,8 @@ class EditCorpusFileForm(FlaskForm): class QueryForm(FlaskForm): - query = StringField('CQP Query', + expert_mode = BooleanField('Expert mode') + query = StringField('Query', validators=[DataRequired(), Length(1, 1024)]) hits_per_page = SelectField('Hits per page', choices=[('', 'Nr. of hits per page'), diff --git a/app/templates/corpora/analyse_corpus_pjentsch.html.j2 b/app/templates/corpora/analyse_corpus_pjentsch.html.j2 new file mode 100644 index 00000000..06c24b97 --- /dev/null +++ b/app/templates/corpora/analyse_corpus_pjentsch.html.j2 @@ -0,0 +1,423 @@ +{% extends "full_width.html.j2" %} + +{% block page_content %} + + +
+ +
+Title | +Left context | +Match | +Right Context | +
---|