Add sanity checks for corpus preparation

This commit is contained in:
Patrick Jentsch 2019-11-05 13:40:31 +01:00
parent 910a187c04
commit 04fe6b063e
2 changed files with 8 additions and 3 deletions

View File

@ -85,9 +85,12 @@ def prepare_corpus(corpus_id):
corpus = Corpus.query.get_or_404(corpus_id) corpus = Corpus.query.get_or_404(corpus_id)
if not (corpus.creator == current_user or current_user.is_administrator()): if not (corpus.creator == current_user or current_user.is_administrator()):
abort(403) abort(403)
corpus.status = 'preparable' if len(corpus.files.all()) > 0:
db.session.commit() corpus.status = 'preparable'
flash('Corpus marked for preparation!') 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)) return redirect(url_for('corpora.corpus', corpus_id=corpus_id))

View File

@ -24,7 +24,9 @@
{% if corpus.status == 'prepared' %} {% if corpus.status == 'prepared' %}
<a href="{{ url_for('corpora.corpus_analysis', corpus_id=corpus.id) }}" class="waves-effect waves-light btn"><i class="material-icons left">help</i>Analyse</a> <a href="{{ url_for('corpora.corpus_analysis', corpus_id=corpus.id) }}" class="waves-effect waves-light btn"><i class="material-icons left">help</i>Analyse</a>
{% endif %} {% endif %}
{% if corpus.files[0] is defined %}
<a href="{{ url_for('corpora.prepare_corpus', corpus_id=corpus.id) }}" class="waves-effect waves-light btn"><i class="material-icons left">whatshot</i>Prepare</a> <a href="{{ url_for('corpora.prepare_corpus', corpus_id=corpus.id) }}" class="waves-effect waves-light btn"><i class="material-icons left">whatshot</i>Prepare</a>
{% endif %}
<a data-target="delete-corpus-modal" class="waves-effect waves-light btn red modal-trigger"><i class="material-icons left">delete</i>Delete Corpus</a> <a data-target="delete-corpus-modal" class="waves-effect waves-light btn red modal-trigger"><i class="material-icons left">delete</i>Delete Corpus</a>
</div> </div>
</div> </div>