Add function to edit new metadata fields

This commit is contained in:
Stephan Porada 2020-01-10 12:13:42 +01:00
parent c2923013a3
commit 446eca2d22
2 changed files with 25 additions and 4 deletions

View File

@ -33,8 +33,20 @@ class AddCorpusForm(FlaskForm):
title = StringField('Title', validators=[DataRequired(), Length(1, 32)])
class EditCorpusFileForm(AddCorpusFileForm):
pass
class EditCorpusFileForm(FlaskForm):
address = StringField('Adress', validators=[Length(0, 255)])
author = StringField('Author', validators=[DataRequired(), Length(1, 255)])
booktitle = StringField('Booktitle', validators=[Length(0, 255)])
chapter = StringField('Chapter', validators=[Length(0, 255)])
editor = StringField('Editor', validators=[Length(0, 255)])
institution = StringField('institution', validators=[Length(0, 255)])
journal = StringField('Journal', validators=[Length(0, 255)])
pages = StringField('Pages', validators=[Length(0, 255)])
publisher = StringField('Publisher', validators=[Length(0, 255)])
publishing_year = IntegerField('Publishing year', validators=[DataRequired()])
school = StringField('School', validators=[Length(0, 255)])
submit = SubmitField()
title = StringField('Title', validators=[DataRequired(), Length(1, 255)])
class QueryForm(FlaskForm):

View File

@ -166,8 +166,17 @@ def edit_corpus_file(corpus_id, corpus_file_id):
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
ids = [field.id for field in edit_corpus_file_form if not
(field.id == 'submit'
or field.id == "csrf_token"
or field.id == "file")]
data = [field.data for field in edit_corpus_file_form if not
(field.id == 'submit'
or field.id == "csrf_token"
or field.id == "file")]
field_dict = dict(zip(ids, data))
stmt = db.update(CorpusFile).where(CorpusFile.id==corpus_file_id).values(**field_dict)
db.session.execute(stmt)
db.session.commit()
thread = Thread(target=edit_corpus_file_,
args=(current_app._get_current_object(),