Add first iteration of query and analysis corpora page

This commit is contained in:
Stephan Porada 2019-10-28 09:16:34 +01:00
parent 409d94d0ae
commit b46090133d
3 changed files with 56 additions and 23 deletions

View File

@ -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')

View File

@ -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/<int:corpus_id>/analysis')
@main.route('/corpora/<int:corpus_id>/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)

View File

@ -29,26 +29,43 @@
</div>
<div class="col s12 m3 l3 sticky">
<div class="card">
<form method="POST">
<div class="card-content">
<span class="card-title">Card Title</span>
<table class="responsive highlight">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
{{ form.hidden_tag() }}
<span class="card-title">Query and analysis</span>
<div class="input-field">
<i class="material-icons prefix">search</i>
<textarea id="{{ form.query.id }}" name="{{ form.query.id }}" required="" type="text" value="" class="materialize-textarea"></textarea>
{{ form.query.label }}
{% for error in form.query.errors %}
<span class="helper-text red-text">{{ error }}</span>
{% endfor %}
</div>
<div class="right-align">
{{ form.submit(class='btn') }}
</div>
<!-- <br>
<span class="card-title">Help</span>
<ul>
<li>
<a href="http://cwb.sourceforge.net/files/CQP_Tutorial/">
CQP Query Language Tutorial</a>
</li>
</ul>
<br>
<span class="card-title">Options</span>
<select>
<option value="" disabled selected>Choose your option</option>
<option value="1">10</option>
<option value="2">20</option>
<option value="3">25</option>
<option value="3">50</option>
</select>
<label>Materialize Select</label>
<br>
<span class="card-title">Download Results</span>
</div> -->
</form>
</div>
</div>
{% endblock %}