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 %}