From b46090133d8e9ced5d65d0f84e78a62b575f22c5 Mon Sep 17 00:00:00 2001 From: Stephan Porada Date: Mon, 28 Oct 2019 09:16:34 +0100 Subject: [PATCH] Add first iteration of query and analysis corpora page --- app/main/forms.py | 12 +++- app/main/views.py | 12 +++- .../main/corpora/corpus_analysis.html.j2 | 55 ++++++++++++------- 3 files changed, 56 insertions(+), 23 deletions(-) diff --git a/app/main/forms.py b/app/main/forms.py index cd2c1b23..80e6becf 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -1,7 +1,7 @@ from flask_wtf import FlaskForm from wtforms import (MultipleFileField, StringField, SubmitField, - ValidationError) -from wtforms.validators import DataRequired, Length + ValidationError, IntegerField) +from wtforms.validators import DataRequired, Length, NumberRange class CreateCorpusForm(FlaskForm): @@ -16,3 +16,11 @@ class CreateCorpusForm(FlaskForm): if not file.filename.lower().endswith('.vrt'): raise ValidationError('File does not have an approved ' 'extension: .vrt') + + +class QueryForm(FlaskForm): + query = StringField('CQP Query', validators=[DataRequired()]) + # hits_per_page = IntegerField('Hits per page', + # validators=[DataRequired(), + # NumberRange(min=10, max=50)]) + submit = SubmitField('Start Query') diff --git a/app/main/views.py b/app/main/views.py index 5ef53c42..c2382881 100644 --- a/app/main/views.py +++ b/app/main/views.py @@ -3,12 +3,13 @@ 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 CreateCorpusForm +from .forms import CreateCorpusForm, QueryForm from .. import db from ..models import Corpus, CorpusFile, Job from werkzeug.utils import secure_filename import os import threading +import logging @main.route('/') @@ -62,12 +63,19 @@ def corpus_download(corpus_id): filename=file) -@main.route('/corpora//analysis') +@main.route('/corpora//analysis', methods=['GET', 'POST']) @login_required def corpus_analysis(corpus_id): corpus = Corpus.query.get_or_404(corpus_id) + form = QueryForm() + if form.validate_on_submit(): + logger = logging.getLogger(__name__) + logger.warning('Data has been sent!') + flash('Query has been sent!') + return redirect(url_for('main.corpus_analysis', corpus_id=corpus_id)) return render_template('main/corpora/corpus_analysis.html.j2', corpus=corpus, + form=form, 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 cbe60bcf..211e9f49 100644 --- a/app/templates/main/corpora/corpus_analysis.html.j2 +++ b/app/templates/main/corpora/corpus_analysis.html.j2 @@ -29,26 +29,43 @@
+
- Card Title - - - - - - - - - - - - - - - - -
FirstnameLastnameAge
JillSmith50
EveJackson94
-
+ {{ form.hidden_tag() }} + Query and analysis +
+ search + + {{ form.query.label }} + {% for error in form.query.errors %} + {{ error }} + {% endfor %} +
+
+ {{ form.submit(class='btn') }} +
+ +
{% endblock %}