diff --git a/app/corpora/views.py b/app/corpora/views.py index c91b8783c008b4cd8d774e12a1eaee820efabe82..9c86a6448cc87c5684bae9ffd2e020104e80c8ff 100644 --- a/app/corpora/views.py +++ b/app/corpora/views.py @@ -1,4 +1,4 @@ -from app import db, logger +from app import db from app.models import Corpus, CorpusFile from flask import (abort, current_app, flash, redirect, request, render_template, url_for, send_from_directory) @@ -6,7 +6,7 @@ from flask_login import current_user, login_required from werkzeug.utils import secure_filename from . import corpora from .background_functions import (delete_corpus_, delete_corpus_file_, - edit_corpus_file_) + edit_corpus_file_) from .forms import (AddCorpusFileForm, AddCorpusForm, EditCorpusFileForm, QueryDownloadForm, QueryForm) import os @@ -48,31 +48,21 @@ def corpus(corpus_id): title='Corpus') -@corpora.route('/<int:corpus_id>/analysis', methods=['GET', 'POST']) +@corpora.route('/<int:corpus_id>/analyse') @login_required -def corpus_analysis(corpus_id): +def analyse_corpus(corpus_id): corpus = Corpus.query.get_or_404(corpus_id) if corpus.status == 'prepared': corpus.status = 'start analysis' db.session.commit() - query = request.args.get('query') - 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(): - flash('Query has been sent!') - query = form.query.data - hits_per_page = form.hits_per_page.data - context = form.context.data - return redirect(url_for('corpora.corpus_analysis', corpus_id=corpus_id, - query=query, hits_per_page=hits_per_page, - context=context)) - return render_template('corpora/corpus_analysis.html.j2', + query_download_form = QueryDownloadForm() + query_form = QueryForm(context=request.args.get('context', 10), + hits_per_page=request.args.get('hits_per_page', 30), + query=request.args.get('query')) + return render_template('corpora/analyse_corpus.html.j2', corpus_id=corpus_id, - form=form, dl_form=dl_form, - title='Corpus: {}'.format(corpus.title)) + query_download_form=query_download_form, + query_form=query_form, title='Analyse Corpus') @corpora.route('/<int:corpus_id>/delete') diff --git a/app/templates/corpora/corpus_analysis.html.j2 b/app/templates/corpora/analyse_corpus.html.j2 similarity index 85% rename from app/templates/corpora/corpus_analysis.html.j2 rename to app/templates/corpora/analyse_corpus.html.j2 index 7185f13dc0083308ce6a6970d2ee6fbe599473b8..080eeca1d35c70ec6a0d91a4707cdccdb0978798 100644 --- a/app/templates/corpora/corpus_analysis.html.j2 +++ b/app/templates/corpora/analyse_corpus.html.j2 @@ -6,12 +6,12 @@ <div class="card"> <div class="card-content"> <form id="query-form" method="POST"> - {{ form.hidden_tag() }} + {{ query_form.hidden_tag() }} <span class="card-title">Query and analysis</span> <div class="input-field"> - {{ form.query(class='materialize-textarea') }} - {{ form.query.label }} - {% for error in form.query.errors %} + {{ query_form.query(class='materialize-textarea') }} + {{ query_form.query.label }} + {% for error in query_form.query.errors %} <span class="helper-text red-text">{{ error }}</span> {% endfor %} </div> @@ -23,17 +23,17 @@ <span class="card-title">Options</span> <div class="input-field"> <i class="material-icons prefix">format_list_numbered</i> - {{ form.hits_per_page() }} - {{ form.hits_per_page.label }} - {% for error in form.hits_per_page.errors %} + {{ query_form.hits_per_page() }} + {{ query_form.hits_per_page.label }} + {% for error in query_form.hits_per_page.errors %} <span class="helper-text red-text">{{ error }}</span> {% endfor %} </div> <div class="input-field"> <i class="material-icons prefix">short_text</i> - {{ form.context() }} - {{ form.context.label }} - {% for error in form.context.errors %} + {{ query_form.context() }} + {{ query_form.context.label }} + {% for error in query_form.context.errors %} <span class="helper-text red-text">{{ error }}</span> {% endfor %} </div> @@ -44,14 +44,14 @@ <div class="card"> <div class="card-content"> <form id="download-form" method="POST"> - {{ dl_form.hidden_tag() }} + {{ query_download_form.hidden_tag() }} <span class="card-title">Download Results</span> <p>Downlaod all results of the current query as csv, excel or json file.</p> <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 %} + {{ query_download_form.file_type() }} + {{ query_download_form.file_type.label }} + {% for error in query_download_form.file_type.errors %} <span class="helper-text red-text">{{ error }}</span> {% endfor %} </div> diff --git a/app/templates/corpora/corpus.html.j2 b/app/templates/corpora/corpus.html.j2 index 98e1f81ea8e769ce797f706a16ffe2d9ee092c1e..84367cf83f890413c7c6038fca7c4b057197959d 100644 --- a/app/templates/corpora/corpus.html.j2 +++ b/app/templates/corpora/corpus.html.j2 @@ -98,7 +98,7 @@ </div> </div> <div class="card-action right-align"> - <a href="{{ url_for('corpora.corpus_analysis', corpus_id=corpus.id) }}" class="waves-effect waves-light btn hide" id="analyse"><i class="material-icons left">help</i>Analyse</a> + <a href="{{ url_for('corpora.analyse_corpus', corpus_id=corpus.id) }}" class="waves-effect waves-light btn hide" id="analyse"><i class="material-icons left">help</i>Analyse</a> {% if corpus.files[0] is defined %} <a href="{{ url_for('corpora.prepare_corpus', corpus_id=corpus.id) }}" class="waves-effect waves-light btn" id="prepare"><i class="material-icons left">whatshot</i>Prepare</a> {% endif %}