From 31c015f761f0c2dd8bae14ca79d936929a1b5a55 Mon Sep 17 00:00:00 2001 From: Stephan Porada Date: Tue, 29 Oct 2019 17:42:32 +0100 Subject: [PATCH] Add query analysis form options etc. --- app/main/forms.py | 29 ++++++++++++++--- app/main/views.py | 11 ++++++- .../main/corpora/corpus_analysis.html.j2 | 31 ++++++++++++------- 3 files changed, 54 insertions(+), 17 deletions(-) diff --git a/app/main/forms.py b/app/main/forms.py index 20826e48..a3ff4a63 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -1,6 +1,6 @@ from flask_wtf import FlaskForm from wtforms import (MultipleFileField, StringField, SubmitField, - ValidationError, IntegerField) + ValidationError, IntegerField, SelectField) from wtforms.validators import DataRequired, Length, NumberRange @@ -26,8 +26,27 @@ class AddCorpusFileForm(FlaskForm): class QueryForm(FlaskForm): - query = StringField('CQP Query', validators=[DataRequired()]) - # hits_per_page = IntegerField('Hits per page', - # validators=[DataRequired(), - # NumberRange(min=10, max=50)]) + query = StringField('CQP Query', validators=[DataRequired(), (Length(1, 1024))]) + hits_per_page = SelectField('Hits per page', + choices=[('', 'Nr. of hits per page'), + ('10', '10'), + ('20', '20'), + ('30', '30'), + ('40', '40'), + ('50', '50')], + validators=[DataRequired()], + default='30') + context = SelectField('Context', + choices=[('', 'Words of context around hit'), + ('5', '5'), + ('10', '10'), + ('15', '15'), + ('20', '20'), + ('25', '25')], + validators=[DataRequired()], + default='10') submit = SubmitField('Start Query') + + +class QueryDownloadForm(FlaskForm): + pass diff --git a/app/main/views.py b/app/main/views.py index bff10de1..e2202423 100644 --- a/app/main/views.py +++ b/app/main/views.py @@ -55,15 +55,24 @@ def corpus_download(corpus_id): @login_required def corpus_analysis(corpus_id): corpus = Corpus.query.get_or_404(corpus_id) + query = request.args.get('query') form = QueryForm() if form.validate_on_submit(): logger = logging.getLogger(__name__) logger.warning('Data has been sent!') + logger.warning('Data labels: {data}'.format(data=[data for data in form.data])) + logger.warning('Query: {q}'.format(q=form.query.data)) + logger.warning('Hits: {hits}'.format(hits=form.hits_per_page.data)) + logger.warning('Context: {context}'.format(context=form.context.data)) flash('Query has been sent!') - return redirect(url_for('main.corpus_analysis', corpus_id=corpus_id)) + query = form.query.data + logger.warning('Session query: {sq}'.format(sq=query)) + return redirect(url_for('main.corpus_analysis', corpus_id=corpus_id, + query=query)) return render_template('main/corpora/corpus_analysis.html.j2', corpus=corpus, form=form, + query=query, title='Corpus: ' + corpus.title) diff --git a/app/templates/main/corpora/corpus_analysis.html.j2 b/app/templates/main/corpora/corpus_analysis.html.j2 index 211e9f49..62919497 100644 --- a/app/templates/main/corpora/corpus_analysis.html.j2 +++ b/app/templates/main/corpora/corpus_analysis.html.j2 @@ -35,7 +35,7 @@ Query and analysis
search - + {{ form.query.label }} {% for error in form.query.errors %} {{ error }} @@ -44,7 +44,7 @@
{{ form.submit(class='btn') }}
- +