Code enhancement

This commit is contained in:
Patrick Jentsch 2019-10-25 15:09:19 +02:00
parent 0a6bc055a0
commit 775ddc601e

View File

@ -20,7 +20,8 @@ def index():
@login_required @login_required
def corpus(corpus_id): def 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)
return render_template('main/corpora/corpus.html.j2', return render_template('main/corpora/corpus.html.j2',
corpus=corpus, corpus=corpus,
@ -57,20 +58,16 @@ def corpus_analysis(corpus_id):
@login_required @login_required
def dashboard(): def dashboard():
create_corpus_form = CreateCorpusForm() create_corpus_form = CreateCorpusForm()
if create_corpus_form.validate_on_submit(): if create_corpus_form.validate_on_submit():
app = current_app._get_current_object()
corpus = Corpus(creator=current_user._get_current_object(), corpus = Corpus(creator=current_user._get_current_object(),
description=create_corpus_form.description.data, description=create_corpus_form.description.data,
title=create_corpus_form.title.data) title=create_corpus_form.title.data)
db.session.add(corpus) db.session.add(corpus)
db.session.commit() db.session.commit()
dir = os.path.join(current_app.config['OPAQUE_STORAGE_DIRECTORY'],
dir = os.path.join(app.config['OPAQUE_STORAGE_DIRECTORY'],
str(corpus.user_id), str(corpus.user_id),
'corpora', 'corpora',
str(corpus.id)) str(corpus.id))
try: try:
os.makedirs(dir) os.makedirs(dir)
except OSError: except OSError:
@ -89,7 +86,6 @@ def dashboard():
db.session.commit() db.session.commit()
flash('Corpus created!') flash('Corpus created!')
return redirect(url_for('main.dashboard')) return redirect(url_for('main.dashboard'))
return render_template('main/dashboard.html.j2', return render_template('main/dashboard.html.j2',
create_corpus_form=create_corpus_form, create_corpus_form=create_corpus_form,
title='Dashboard') title='Dashboard')