Merge branch 'development' of gitlab.ub.uni-bielefeld.de:sfb1288inf/opaque into development

This commit is contained in:
Patrick Jentsch 2019-10-30 14:26:17 +01:00
commit 217a5a9e0c
4 changed files with 99 additions and 64 deletions

View File

@ -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
@ -35,7 +35,8 @@ class EditCorpusFileForm(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'),
@ -43,8 +44,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'),
@ -52,10 +52,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()])

View File

@ -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
@ -56,25 +56,35 @@ def corpus(corpus_id):
@main.route('/corpora/<int:corpus_id>/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)

View File

@ -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 */
}

View File

@ -1,48 +1,24 @@
{% extends "full_width.html.j2" %}
{% block page_content %}
<div class="col s12 m9 l9">
<div class="card">
<div class="card-content">
<span class="card-title">Query Results</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>
{% for i in range(0,51) %}
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
{% endfor %}
</table>
</div>
</div>
</div>
<div class="col s12 m3 l3 sticky">
<div class="card">
<form method="POST">
<div class="card-content">
{{ form.hidden_tag() }}
<span class="card-title">Query and analysis</span>
<br>
<div class="input-field">
<i class="material-icons prefix">search</i>
<input autofocus size="1024" data-length="1024" id="{{ form.query.id }}" name="{{ form.query.id }}" required="" type="text" value="{{ query if query != None else '' }}"></input>
{{ form.query(class='materialize-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') }}
<button class="btn" type="submit" name="action">Start Query
<i class="material-icons left">search</i>
</button>
</div>
<br>
<span class="card-title">Help</span>
@ -72,9 +48,53 @@
<span class="helper-text red-text">{{ error }}</span>
{% endfor %}
</div>
<br>
</form>
<span class="card-title">Download Results</span>
<p>Downlaod all results of the current query as csv, excel or json file.</p>
<form method="POST">
{{ form.hidden_tag() }}
<div class="input-field">
<i class="material-icons prefix">insert_drive_file</i>
{{ dl_form.file_type() }}
{{ dl_form.file_type.label }}
{% for error in dl_form.file_type.errors %}
<span class="helper-text red-text">{{ error }}</span>
{% endfor %}
</div>
<div class="right-align">
<button class="btn" type="submit" name="action">Download
<i class="material-icons left">file_download</i>
</button>
</div>
</form>
</div>
</div>
</div>
<div class="col s12 m9 l9">
<div class="card">
<div class="card-content">
<span class="card-title">Query Results</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>
{% for i in range(0,51) %}
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
{% endfor %}
</table>
</div>
</div>
</div>
{% endblock %}