From 0dc015b29c0851a3ea71afc830ab31a6b74a64f8 Mon Sep 17 00:00:00 2001 From: Stephan Porada Date: Wed, 30 Oct 2019 14:06:23 +0100 Subject: [PATCH] Add more form fields to corpus analysis --- app/main/forms.py | 18 +-- app/main/views.py | 24 ++-- app/static/css/opaque.css | 1 + .../main/corpora/corpus_analysis.html.j2 | 117 ++++++++++-------- 4 files changed, 96 insertions(+), 64 deletions(-) diff --git a/app/main/forms.py b/app/main/forms.py index e26c34da..23621bbb 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -1,6 +1,6 @@ from flask_wtf import FlaskForm from wtforms import (FileField, StringField, SubmitField, - ValidationError, IntegerField, SelectField) + ValidationError, IntegerField, SelectField, TextAreaField) from wtforms.validators import DataRequired, Length @@ -26,7 +26,8 @@ class CreateCorpusForm(FlaskForm): class QueryForm(FlaskForm): - query = StringField('CQP Query', validators=[DataRequired(), (Length(1, 1024))]) + query = TextAreaField('CQP Query', validators=[DataRequired(), + (Length(1, 1024))]) hits_per_page = SelectField('Hits per page', choices=[('', 'Nr. of hits per page'), ('10', '10'), @@ -34,8 +35,7 @@ class QueryForm(FlaskForm): ('30', '30'), ('40', '40'), ('50', '50')], - validators=[DataRequired()], - default='30') + validators=[DataRequired()]) context = SelectField('Context', choices=[('', 'Words of context around hit'), ('5', '5'), @@ -43,10 +43,14 @@ class QueryForm(FlaskForm): ('15', '15'), ('20', '20'), ('25', '25')], - validators=[DataRequired()], - default='10') + validators=[DataRequired()]) submit = SubmitField('Start Query') class QueryDownloadForm(FlaskForm): - pass + file_type = SelectField('File type', + choices=[('', 'Choose file type'), + ('csv', 'csv'), + ('json', 'json'), + ('excel', 'excel')], + validators=[DataRequired()]) diff --git a/app/main/views.py b/app/main/views.py index 0d138b2d..29763e80 100644 --- a/app/main/views.py +++ b/app/main/views.py @@ -3,7 +3,7 @@ from flask import (abort, current_app, flash, redirect, request, render_template, url_for, send_from_directory) from flask_login import current_user, login_required from . import main -from .forms import AddCorpusFileForm, CreateCorpusForm, QueryForm +from .forms import AddCorpusFileForm, CreateCorpusForm, QueryForm, QueryDownloadForm from .. import db from ..models import Corpus, CorpusFile, Job, JobInput, JobResult from werkzeug.utils import secure_filename @@ -87,25 +87,35 @@ def corpus_download(corpus_id): @main.route('/corpora//analysis', methods=['GET', 'POST']) @login_required def corpus_analysis(corpus_id): + logger = logging.getLogger(__name__) corpus = Corpus.query.get_or_404(corpus_id) query = request.args.get('query') - form = QueryForm() + logger.warning('Query first: {}'.format(query)) + hits_per_page = request.args.get('hits_per_page', 30) + context = request.args.get('context', 10) + dl_form = QueryDownloadForm() + form = QueryForm(hits_per_page=hits_per_page, context=context, query=query) 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('Query Second: {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!') 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)) + hits_per_page = form.hits_per_page.data + context = form.context.data + logger.warning('Query Thrid: {sq}'.format(sq=query)) + return redirect(url_for('main.corpus_analysis', + corpus_id=corpus_id, + query=query, + hits_per_page=hits_per_page, + context=context)) return render_template('main/corpora/corpus_analysis.html.j2', corpus=corpus, form=form, - query=query, + dl_form=dl_form, title='Corpus: ' + corpus.title) diff --git a/app/static/css/opaque.css b/app/static/css/opaque.css index 7fa300c9..97a17bd7 100644 --- a/app/static/css/opaque.css +++ b/app/static/css/opaque.css @@ -80,4 +80,5 @@ indicator will show up how the column is sorted right now.; */ position: sticky; top: 80px; padding: 50px; + z-index: 999; /* tmp fix */ } diff --git a/app/templates/main/corpora/corpus_analysis.html.j2 b/app/templates/main/corpora/corpus_analysis.html.j2 index 62919497..64a51bc0 100644 --- a/app/templates/main/corpora/corpus_analysis.html.j2 +++ b/app/templates/main/corpora/corpus_analysis.html.j2 @@ -1,6 +1,73 @@ {% extends "full_width.html.j2" %} {% block page_content %} +
+
+
+
+ {{ form.hidden_tag() }} + Query and analysis +
+
+ {{ form.query(class='materialize-textarea') }} + {{ form.query.label }} + {% for error in form.query.errors %} + {{ error }} + {% endfor %} +
+
+ +
+
+ Help + +
+ Options +
+
+ format_list_numbered + {{ form.hits_per_page() }} + {{ form.hits_per_page.label }} + {% for error in form.hits_per_page.errors %} + {{ error }} + {% endfor %} +
+
+
+ short_text + {{ form.context() }} + {{ form.context.label }} + {% for error in form.context.errors %} + {{ error }} + {% endfor %} +
+
+ + Download Results +

Downlaod all results of the current query as csv, excel or json file.

+
+ insert_drive_file + {{ dl_form.file_type() }} + {{ dl_form.file_type.label }} + {% for error in dl_form.file_type.errors %} + {{ error }} + {% endfor %} +
+
+ +
+
+
+
@@ -27,54 +94,4 @@
-
-
-
-
- {{ form.hidden_tag() }} - Query and analysis -
- search - - {{ form.query.label }} - {% for error in form.query.errors %} - {{ error }} - {% endfor %} -
-
- {{ form.submit(class='btn') }} -
-
- Help - -
- Options -
-
- format_list_numbered - {{ form.hits_per_page() }} - {{ form.hits_per_page.label }} - {% for error in form.hits_per_page.errors %} - {{ error }} - {% endfor %} -
-
-
- short_text - {{ form.context() }} - {{ form.context.label }} - {% for error in form.context.errors %} - {{ error }} - {% endfor %} -
- Download Results -
-
-
-
{% endblock %}