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 flask_wtf import FlaskForm
from wtforms import (MultipleFileField, StringField, SubmitField, from wtforms import (MultipleFileField, StringField, SubmitField,
ValidationError) ValidationError, IntegerField)
from wtforms.validators import DataRequired, Length from wtforms.validators import DataRequired, Length, NumberRange
class CreateCorpusForm(FlaskForm): class CreateCorpusForm(FlaskForm):
@ -16,3 +16,11 @@ class CreateCorpusForm(FlaskForm):
if not file.filename.lower().endswith('.vrt'): if not file.filename.lower().endswith('.vrt'):
raise ValidationError('File does not have an approved ' raise ValidationError('File does not have an approved '
'extension: .vrt') '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) render_template, url_for, send_from_directory)
from flask_login import current_user, login_required from flask_login import current_user, login_required
from . import main from . import main
from .forms import CreateCorpusForm from .forms import CreateCorpusForm, QueryForm
from .. import db from .. import db
from ..models import Corpus, CorpusFile, Job from ..models import Corpus, CorpusFile, Job
from werkzeug.utils import secure_filename from werkzeug.utils import secure_filename
import os import os
import threading import threading
import logging
@main.route('/') @main.route('/')
@ -62,12 +63,19 @@ def corpus_download(corpus_id):
filename=file) filename=file)
@main.route('/corpora/<int:corpus_id>/analysis') @main.route('/corpora/<int:corpus_id>/analysis', methods=['GET', 'POST'])
@login_required @login_required
def corpus_analysis(corpus_id): def corpus_analysis(corpus_id):
corpus = Corpus.query.get_or_404(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', return render_template('main/corpora/corpus_analysis.html.j2',
corpus=corpus, corpus=corpus,
form=form,
title='Corpus: ' + corpus.title) title='Corpus: ' + corpus.title)

View File

@ -29,26 +29,43 @@
</div> </div>
<div class="col s12 m3 l3 sticky"> <div class="col s12 m3 l3 sticky">
<div class="card"> <div class="card">
<form method="POST">
<div class="card-content"> <div class="card-content">
<span class="card-title">Card Title</span> {{ form.hidden_tag() }}
<table class="responsive highlight"> <span class="card-title">Query and analysis</span>
<tr> <div class="input-field">
<th>Firstname</th> <i class="material-icons prefix">search</i>
<th>Lastname</th> <textarea id="{{ form.query.id }}" name="{{ form.query.id }}" required="" type="text" value="" class="materialize-textarea"></textarea>
<th>Age</th> {{ form.query.label }}
</tr> {% for error in form.query.errors %}
<tr> <span class="helper-text red-text">{{ error }}</span>
<td>Jill</td> {% endfor %}
<td>Smith</td> </div>
<td>50</td> <div class="right-align">
</tr> {{ form.submit(class='btn') }}
<tr> </div>
<td>Eve</td> <!-- <br>
<td>Jackson</td> <span class="card-title">Help</span>
<td>94</td> <ul>
</tr> <li>
</table> <a href="http://cwb.sourceforge.net/files/CQP_Tutorial/">
</div> 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>
</div> </div>
{% endblock %} {% endblock %}