From 63217a7e1dceba8817b7fe73b46b4d66b25acabc Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Wed, 13 Apr 2022 09:08:11 +0200 Subject: [PATCH] Fix uploading corpus files --- app/corpora/forms.py | 2 +- app/corpora/routes.py | 5 ++--- app/templates/corpora/add_corpus_file.html.j2 | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/corpora/forms.py b/app/corpora/forms.py index 7e1e98d8..8c214595 100644 --- a/app/corpora/forms.py +++ b/app/corpora/forms.py @@ -16,7 +16,7 @@ class AddCorpusFileForm(FlaskForm): ''' # Required fields author = StringField('Author', validators=[InputRequired(), Length(min=1, max=255)]) - publishing_year = IntegerField('Publishing year', validators=[InputRequired(), Length(min=1, max=255)]) + publishing_year = IntegerField('Publishing year', validators=[InputRequired()]) title = StringField('Title', validators=[InputRequired(), Length(min=1, max=255)]) vrt = FileField('File', validators=[FileRequired()]) # Optional fields diff --git a/app/corpora/routes.py b/app/corpora/routes.py index 681789d9..44405e7d 100644 --- a/app/corpora/routes.py +++ b/app/corpora/routes.py @@ -195,7 +195,6 @@ def add_corpus_file(corpus_id): if not form.validate(): return make_response(form.errors, 400) # Save the file - filename = secure_filename(form.file.data.filename) corpus_file = CorpusFile( address=form.address.data, author=form.author.data, @@ -203,7 +202,7 @@ def add_corpus_file(corpus_id): chapter=form.chapter.data, corpus=corpus, editor=form.editor.data, - filename=filename, + filename=form.vrt.data.filename, institution=form.institution.data, journal=form.journal.data, mimetype='application/vrt+xml', @@ -217,7 +216,7 @@ def add_corpus_file(corpus_id): db.session.flush(objects=[corpus_file]) db.session.refresh(corpus_file) try: - form.file.data.save(corpus_file.path) + form.vrt.data.save(corpus_file.path) except OSError as e: current_app.logger.error(e) db.session.rollback() diff --git a/app/templates/corpora/add_corpus_file.html.j2 b/app/templates/corpora/add_corpus_file.html.j2 index 034fb5c2..725ee0cb 100644 --- a/app/templates/corpora/add_corpus_file.html.j2 +++ b/app/templates/corpora/add_corpus_file.html.j2 @@ -46,7 +46,7 @@
addAdd additional metadata
{% for field in form - if field.short_name not in ['author', 'csrf_token', 'file', 'publishing_year', 'submit', 'title'] %} + if field.short_name not in ['author', 'csrf_token', 'vrt', 'publishing_year', 'submit', 'title'] %} {{ wtf.render_field(field, material_icon=field.label.text[0:1]) }} {% endfor %}