From 5881444b9f03339c23bc6a8ee9aefe2a53204ec1 Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Thu, 31 Oct 2019 15:29:02 +0100 Subject: [PATCH] Use extra pages for add_corpus and add_corpus_file forms. --- app/corpora/forms.py | 1 + app/corpora/views.py | 48 ++++++------- app/templates/corpora/add_corpus.html.j2 | 46 +++++++++++++ app/templates/corpora/add_corpus_file.html.j2 | 67 +++++++++++++++++++ app/templates/corpora/corpus.html.j2 | 60 +---------------- app/templates/main/dashboard.html.j2 | 39 +---------- 6 files changed, 137 insertions(+), 124 deletions(-) create mode 100644 app/templates/corpora/add_corpus.html.j2 create mode 100644 app/templates/corpora/add_corpus_file.html.j2 diff --git a/app/corpora/forms.py b/app/corpora/forms.py index cf1ed639..02c90c58 100644 --- a/app/corpora/forms.py +++ b/app/corpora/forms.py @@ -1,4 +1,5 @@ from flask_wtf import FlaskForm +from werkzeug.utils import secure_filename from wtforms import (FileField, StringField, SubmitField, ValidationError, IntegerField, SelectField, TextAreaField) from wtforms.validators import DataRequired, Length diff --git a/app/corpora/views.py b/app/corpora/views.py index bd7793eb..80a3f3a9 100644 --- a/app/corpora/views.py +++ b/app/corpora/views.py @@ -1,23 +1,22 @@ from flask import (abort, current_app, flash, redirect, request, - render_template, session, url_for, send_from_directory) + render_template, url_for, send_from_directory) from flask_login import current_user, login_required -from werkzeug import MultiDict -from werkzeug.utils import secure_filename from . import corpora from .forms import (AddCorpusFileForm, AddCorpusForm, QueryDownloadForm, QueryForm) from .. import db from ..models import Corpus, CorpusFile +from werkzeug.utils import secure_filename import os import threading import logging -@corpora.route('/add', methods=['POST']) +@corpora.route('/add', methods=['GET', 'POST']) @login_required def add_corpus(): add_corpus_form = AddCorpusForm() - if not add_corpus_form.validate_on_submit(): + if add_corpus_form.validate_on_submit(): corpus = Corpus(creator=current_user, description=add_corpus_form.description.data, title=add_corpus_form.title.data) @@ -31,26 +30,21 @@ def add_corpus(): flash('OSError!') db.session.remove(corpus) db.session.commit() - flash('Corpus created!') + flash('Corpus added!') return redirect(url_for('corpora.corpus', corpus_id=corpus.id)) + return render_template('corpora/add_corpus.html.j2', + add_corpus_form=add_corpus_form, + title='Add corpus') @corpora.route('/') @login_required def corpus(corpus_id): - add_corpus_file_form_data = session.pop('add_corpus_file_form_data', - default=None) - add_corpus_file_form = AddCorpusFileForm( - MultiDict(add_corpus_file_form_data) - ) - if add_corpus_file_form_data is not None: - add_corpus_file_form.validate() corpus = Corpus.query.get_or_404(corpus_id) if not (corpus.creator == current_user or current_user.is_administrator()): abort(403) - return render_template('corpora/corpus.html.j2', - add_corpus_file_form=add_corpus_file_form, - corpus=corpus, title='Corpus') + return render_template('corpora/corpus.html.j2', corpus=corpus, + title='Corpus') @corpora.route('//analysis', methods=['GET', 'POST']) @@ -96,7 +90,7 @@ def delete_corpus(corpus_id): return redirect(url_for('main.dashboard')) -@corpora.route('//files/add', methods=['POST']) +@corpora.route('//files/add', methods=['GET', 'POST']) @login_required def add_corpus_file(corpus_id): corpus = Corpus.query.get_or_404(corpus_id) @@ -113,19 +107,19 @@ def add_corpus_file(corpus_id): # Save the file dir = os.path.join(str(corpus.user_id), 'corpora', str(corpus.id)) file.save(os.path.join(current_app.config['OPAQUE_STORAGE_DIRECTORY'], - dir, filename)) - author = add_corpus_file_form.author.data - publishing_year = add_corpus_file_form.publishing_year.data - title = add_corpus_file_form.title.data - corpus_file = CorpusFile(author=author, corpus=corpus, dir=dir, - filename=filename, - publishing_year=publishing_year, title=title) + dir, filename)) + + corpus_file = CorpusFile(author=add_corpus_file_form.author.data, + corpus=corpus, dir=dir, filename=filename, + publishing_year=add_corpus_file_form.publishing_year.data, + title=add_corpus_file_form.title.data) db.session.add(corpus_file) db.session.commit() flash('Corpus file added!') - else: - session['add_corpus_file_form_data'] = request.form - return redirect(url_for('corpora.corpus', corpus_id=corpus_id)) + return redirect(url_for('corpora.corpus', corpus_id=corpus_id)) + return render_template('corpora/add_corpus_file.html.j2', + add_corpus_file_form=add_corpus_file_form, + corpus=corpus, title='Add corpus file') @corpora.route('//files//delete') diff --git a/app/templates/corpora/add_corpus.html.j2 b/app/templates/corpora/add_corpus.html.j2 new file mode 100644 index 00000000..528adbbe --- /dev/null +++ b/app/templates/corpora/add_corpus.html.j2 @@ -0,0 +1,46 @@ +{% extends "limited_width.html.j2" %} +{% block page_content %} +
+

...

+

Fill out the following form to add a corpus to your corpora.

+ arrow_backBack to dashboard +
+ +
+
+
+
+ {{ add_corpus_form.hidden_tag() }} +
+
+
+ title + {{ add_corpus_form.title(data_length='32') }} + {{ add_corpus_form.title.label }} + {% for error in add_corpus_form.title.errors %} + {{ error }} + {% endfor %} +
+
+
+
+ description + {{ add_corpus_form.description(data_length='255') }} + {{ add_corpus_form.description.label }} + {% for error in add_corpus_form.description.errors %} + {{ error }} + {% endfor %} +
+
+
+

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,

+
+
+
+
+ +
+
+
+
+{% endblock %} diff --git a/app/templates/corpora/add_corpus_file.html.j2 b/app/templates/corpora/add_corpus_file.html.j2 new file mode 100644 index 00000000..6a0ad009 --- /dev/null +++ b/app/templates/corpora/add_corpus_file.html.j2 @@ -0,0 +1,67 @@ +{% extends "limited_width.html.j2" %} +{% block page_content %} +
+

{{ corpus.title }}

+

Fill out the following form to add a corpus file in verticalized text format (.vrt).

+ arrow_backBack to corpus +
+ +
+
+
+
+ {{ add_corpus_file_form.hidden_tag() }} +
+
+
+ person + {{ add_corpus_file_form.author(data_length='64') }} + {{ add_corpus_file_form.author.label }} + {% for error in add_corpus_file_form.author.errors %} + {{ error }} + {% endfor %} +
+
+
+
+ title + {{ add_corpus_file_form.title(data_length='64') }} + {{ add_corpus_file_form.title.label }} + {% for error in add_corpus_file_form.title.errors %} + {{ error }} + {% endfor %} +
+
+
+
+ access_time + {{ add_corpus_file_form.publishing_year() }} + {{ add_corpus_file_form.publishing_year.label }} + {% for error in add_corpus_file_form.publishing_year.errors %} + {{ error }} + {% endfor %} +
+
+
+
+
+ {{ add_corpus_file_form.file.label.text }} + {{ add_corpus_file_form.file(accept='.vrt') }} +
+
+ +
+ {% for error in add_corpus_file_form.file.errors %} + {{ error }} + {% endfor %} +
+
+
+
+
+ +
+
+
+
+{% endblock %} diff --git a/app/templates/corpora/corpus.html.j2 b/app/templates/corpora/corpus.html.j2 index 7aa747df..b786b045 100644 --- a/app/templates/corpora/corpus.html.j2 +++ b/app/templates/corpora/corpus.html.j2 @@ -22,7 +22,7 @@ helpAnalyse - + addAdd corpus file @@ -69,64 +69,6 @@ - -
    @@ -85,43 +85,6 @@ jobList.on("searchComplete", List.updatePagination); - -