From 446eca2d22dd57b3afeebbdac9899645a97cc355 Mon Sep 17 00:00:00 2001 From: Stephan Porada Date: Fri, 10 Jan 2020 12:13:42 +0100 Subject: [PATCH] Add function to edit new metadata fields --- app/corpora/forms.py | 16 ++++++++++++++-- app/corpora/views.py | 13 +++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/corpora/forms.py b/app/corpora/forms.py index e508fe30..c06e3833 100644 --- a/app/corpora/forms.py +++ b/app/corpora/forms.py @@ -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): diff --git a/app/corpora/views.py b/app/corpora/views.py index 4c1da169..4287446d 100644 --- a/app/corpora/views.py +++ b/app/corpora/views.py @@ -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(),