diff --git a/app/corpora/forms.py b/app/corpora/forms.py index cf1ed639..16f7eb58 100644 --- a/app/corpora/forms.py +++ b/app/corpora/forms.py @@ -27,7 +27,7 @@ class AddCorpusForm(FlaskForm): class EditCorpusFileForm(FlaskForm): author = StringField('Author', validators=[DataRequired(), Length(1, 64)]) - corpus_file_id = IntegerField('', validators=[DataRequired()]) + #corpus_file_id = IntegerField('', validators=[DataRequired()]) publishing_year = IntegerField('Publishing year', validators=[DataRequired()]) submit = SubmitField() diff --git a/app/corpora/views.py b/app/corpora/views.py index 80a3f3a9..aef61908 100644 --- a/app/corpora/views.py +++ b/app/corpora/views.py @@ -2,8 +2,8 @@ from flask import (abort, current_app, flash, redirect, request, render_template, url_for, send_from_directory) from flask_login import current_user, login_required from . import corpora -from .forms import (AddCorpusFileForm, AddCorpusForm, QueryDownloadForm, - QueryForm) +from .forms import (AddCorpusFileForm, AddCorpusForm, EditCorpusFileForm, + QueryDownloadForm, QueryForm) from .. import db from ..models import Corpus, CorpusFile from werkzeug.utils import secure_filename @@ -150,3 +150,25 @@ def download_corpus_file(corpus_id, corpus_file_id): corpus_file.dir) return send_from_directory(as_attachment=True, directory=dir, filename=corpus_file.filename) + + +@corpora.route('//files//edit', methods=['GET', 'POST']) +@login_required +def edit_corpus_file(corpus_id, corpus_file_id): + corpus_file = CorpusFile.query.get_or_404(corpus_file_id) + if not corpus_file.corpus_id == corpus_id: + abort(404) + if not (corpus_file.corpus.creator == current_user + or current_user.is_administrator()): + abort(403) + edit_corpus_file_form = EditCorpusFileForm() + if edit_corpus_file_form.validate_on_submit(): + corpus_file.author = edit_corpus_file_form.author.data + corpus_file.publishing_year = edit_corpus_file_form.publishing_year.data + corpus_file.title = edit_corpus_file_form.title.data + db.session.commit() + flash('Corpus file edited!') + return redirect(url_for('corpora.corpus', corpus_id=corpus_id)) + return render_template('corpora/edit_corpus_file.html.j2', + edit_corpus_file_form=edit_corpus_file_form, + corpus_file=corpus_file, title='Edit corpus file') diff --git a/app/templates/corpora/corpus.html.j2 b/app/templates/corpora/corpus.html.j2 index 57c45b57..97740799 100644 --- a/app/templates/corpora/corpus.html.j2 +++ b/app/templates/corpora/corpus.html.j2 @@ -53,7 +53,7 @@ {{ file.title }} {{ file.publishing_year }} - edit + edit file_download delete diff --git a/app/templates/corpora/edit_corpus_file.html.j2 b/app/templates/corpora/edit_corpus_file.html.j2 new file mode 100644 index 00000000..c23ec548 --- /dev/null +++ b/app/templates/corpora/edit_corpus_file.html.j2 @@ -0,0 +1,53 @@ +{% extends "limited_width.html.j2" %} +{% block page_content %} +
+

...

+

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

+ arrow_backBack to corpus +
+ +
+
+
+
+ {{ edit_corpus_file_form.hidden_tag() }} +
+
+
+ person + {{ edit_corpus_file_form.author(data_length='64', value=corpus_file.author) }} + {{ edit_corpus_file_form.author.label }} + {% for error in edit_corpus_file_form.author.errors %} + {{ error }} + {% endfor %} +
+
+
+
+ title + {{ edit_corpus_file_form.title(data_length='64', value=corpus_file.title) }} + {{ edit_corpus_file_form.title.label }} + {% for error in edit_corpus_file_form.title.errors %} + {{ error }} + {% endfor %} +
+
+
+
+ access_time + {{ edit_corpus_file_form.publishing_year(value=corpus_file.publishing_year) }} + {{ edit_corpus_file_form.publishing_year.label }} + {% for error in edit_corpus_file_form.publishing_year.errors %} + {{ error }} + {% endfor %} +
+
+
+
+
+ +
+
+
+
+{% endblock %}