From 04fe6b063e4b9921eaf6a00b70ec7a7feb6bf5a8 Mon Sep 17 00:00:00 2001
From: Patrick Jentsch
Date: Tue, 5 Nov 2019 13:40:31 +0100
Subject: [PATCH] Add sanity checks for corpus preparation
---
app/corpora/views.py | 9 ++++++---
app/templates/corpora/corpus.html.j2 | 2 ++
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/app/corpora/views.py b/app/corpora/views.py
index 2e5e9130..e6c82d77 100644
--- a/app/corpora/views.py
+++ b/app/corpora/views.py
@@ -85,9 +85,12 @@ def prepare_corpus(corpus_id):
corpus = Corpus.query.get_or_404(corpus_id)
if not (corpus.creator == current_user or current_user.is_administrator()):
abort(403)
- corpus.status = 'preparable'
- db.session.commit()
- flash('Corpus marked for preparation!')
+ if len(corpus.files.all()) > 0:
+ corpus.status = 'preparable'
+ db.session.commit()
+ flash('Corpus marked for preparation!')
+ else:
+ flash('Can not prepare corpus, please add corpus file(s).')
return redirect(url_for('corpora.corpus', corpus_id=corpus_id))
diff --git a/app/templates/corpora/corpus.html.j2 b/app/templates/corpora/corpus.html.j2
index 7ab6fcf5..89a2d49b 100644
--- a/app/templates/corpora/corpus.html.j2
+++ b/app/templates/corpora/corpus.html.j2
@@ -24,7 +24,9 @@
{% if corpus.status == 'prepared' %}
helpAnalyse
{% endif %}
+ {% if corpus.files[0] is defined %}
whatshotPrepare
+ {% endif %}
deleteDelete Corpus