diff --git a/app/corpora/forms.py b/app/corpora/forms.py index 9d97c496..e508fe30 100644 --- a/app/corpora/forms.py +++ b/app/corpora/forms.py @@ -13,7 +13,7 @@ class AddCorpusFileForm(FlaskForm): file = FileField('File', validators=[DataRequired()]) institution = StringField('institution', validators=[Length(0, 255)]) journal = StringField('Journal', validators=[Length(0, 255)]) - pages = StringField('pages', 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)]) @@ -33,12 +33,8 @@ class AddCorpusForm(FlaskForm): title = StringField('Title', validators=[DataRequired(), Length(1, 32)]) -class EditCorpusFileForm(FlaskForm): - author = StringField('Author', validators=[DataRequired(), Length(1, 64)]) - publishing_year = IntegerField('Publishing year', - validators=[DataRequired()]) - submit = SubmitField() - title = StringField('Title', validators=[DataRequired(), Length(1, 64)]) +class EditCorpusFileForm(AddCorpusFileForm): + pass class QueryForm(FlaskForm): diff --git a/app/corpora/views.py b/app/corpora/views.py index f2d6f83a..a6670d62 100644 --- a/app/corpora/views.py +++ b/app/corpora/views.py @@ -1,4 +1,4 @@ -from app import db +from app import db, logger from app.models import Corpus, CorpusFile from flask import (abort, current_app, flash, redirect, request, render_template, url_for, send_from_directory) @@ -97,10 +97,16 @@ def add_corpus_file(corpus_id): dir = os.path.join(str(corpus.user_id), 'corpora', str(corpus.id)) file.save(os.path.join(current_app.config['NOPAQUE_STORAGE'], dir, filename)) - corpus_file = CorpusFile(author=add_corpus_file_form.author.data, - corpus=corpus, dir=dir, filename=filename, - publishing_year=add_corpus_file_form.publishing_year.data, - title=add_corpus_file_form.title.data) + ids = [field.id for field in add_corpus_file_form if not + (field.id == 'submit' + or field.id == "csrf_token" + or field.id == "file")] + data = [field.data for field in add_corpus_file_form if not + (field.id == 'submit' + or field.id == "csrf_token" + or field.id == "file")] + field_dict = dict(zip(ids, data)) + corpus_file = CorpusFile(**field_dict, corpus=corpus, dir=dir, filename=filename) db.session.add(corpus_file) db.session.commit() thread = Thread(target=edit_corpus_file_, @@ -160,6 +166,7 @@ def edit_corpus_file(corpus_id, corpus_file_id): 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 + corpus_file.pages = edit_corpus_file_form.pages.data db.session.commit() thread = Thread(target=edit_corpus_file_, args=(current_app._get_current_object(), diff --git a/app/templates/_formhelpers.html.j2 b/app/templates/_formhelpers.html.j2 new file mode 100644 index 00000000..37d4f381 --- /dev/null +++ b/app/templates/_formhelpers.html.j2 @@ -0,0 +1,27 @@ +{% macro render_field(field) %} +