mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-24 02:24:20 +00:00
Add edit corpus file form
This commit is contained in:
parent
fbde788b27
commit
6dd16e8e78
@ -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()
|
||||
|
@ -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('/<int:corpus_id>/files/<int:corpus_file_id>/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')
|
||||
|
@ -53,7 +53,7 @@
|
||||
<td>{{ file.title }}</td>
|
||||
<td>{{ file.publishing_year }}</td>
|
||||
<td class="right-align">
|
||||
<a class="waves-effect waves-light btn-small"><i class="material-icons">edit</i></a>
|
||||
<a class="waves-effect waves-light btn-small" href="{{ url_for('corpora.edit_corpus_file', corpus_file_id=file.id, corpus_id=corpus.id) }}"><i class="material-icons">edit</i></a>
|
||||
<a class="waves-effect waves-light btn-small" href="{{ url_for('corpora.download_corpus_file', corpus_file_id=file.id, corpus_id=corpus.id) }}"><i class="material-icons">file_download</i></a>
|
||||
<a class="waves-effect waves-light btn-small red" href="{{ url_for('corpora.delete_corpus_file', corpus_file_id=file.id, corpus_id=corpus.id) }}"><i class="material-icons">delete</i></a>
|
||||
</td>
|
||||
|
53
app/templates/corpora/edit_corpus_file.html.j2
Normal file
53
app/templates/corpora/edit_corpus_file.html.j2
Normal file
@ -0,0 +1,53 @@
|
||||
{% extends "limited_width.html.j2" %}
|
||||
{% block page_content %}
|
||||
<div class="col s12 m4">
|
||||
<h3 id="title">...</h3>
|
||||
<p id="description">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</p>
|
||||
<a class="waves-effect waves-light btn" href="{{ url_for('corpora.corpus', corpus_id=corpus_file.corpus.id) }}"><i class="material-icons left">arrow_back</i>Back to corpus</a>
|
||||
</div>
|
||||
|
||||
<div class="col s12 m8">
|
||||
<div class="card">
|
||||
<form method="POST">
|
||||
<div class="card-content">
|
||||
{{ edit_corpus_file_form.hidden_tag() }}
|
||||
<div class="row">
|
||||
<div class="col s12 m4">
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">person</i>
|
||||
{{ 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 %}
|
||||
<span class="helper-text red-text">{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col s12 m4">
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">title</i>
|
||||
{{ 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 %}
|
||||
<span class="helper-text red-text">{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col s12 m4">
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">access_time</i>
|
||||
{{ 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 %}
|
||||
<span class="helper-text red-text">{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-action right-align">
|
||||
<button class="btn waves-effect waves-light" id="submit" name="submit" type="submit">Submit<i class="material-icons right">send</i></button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user