From 68c38ae1983b012e53f6e97656c3d36b0b3653ec Mon Sep 17 00:00:00 2001 From: nberting Date: Thu, 7 Jun 2018 09:59:08 +0200 Subject: [PATCH] added upload new version of file into edit form --- app/forms.py | 1 + app/templates/edit_book_detail.html | 13 ++++++++++-- app/views.py | 29 ++++++++++++++++++++------ whoosh/Book/MAIN_taxstcerlfadcokk.seg | Bin 0 -> 5276 bytes whoosh/Book/_MAIN_4.toc | Bin 0 -> 2306 bytes 5 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 whoosh/Book/MAIN_taxstcerlfadcokk.seg create mode 100644 whoosh/Book/_MAIN_4.toc diff --git a/app/forms.py b/app/forms.py index 0db4fdf..e276a3d 100755 --- a/app/forms.py +++ b/app/forms.py @@ -25,6 +25,7 @@ class EditForm(FlaskForm): author = FieldList(FormField(AuthorForm, default=lambda: Author()), min_entries=1) category = StringField('category', validators=[InputRequired()]) year_published = StringField('year published', [validators.Length(max=4)],default=None) + file = FileField() class ChatForm(FlaskForm): message = StringField('message', validators=[InputRequired()]) diff --git a/app/templates/edit_book_detail.html b/app/templates/edit_book_detail.html index c936ff4..094aee6 100755 --- a/app/templates/edit_book_detail.html +++ b/app/templates/edit_book_detail.html @@ -7,7 +7,7 @@ -
+ {{ form.csrf_token }}

{{ form.title.label }} {{ form.title(size=20, class="form-control") }}

@@ -32,10 +32,19 @@
- {{ form.category.label }} {{ form.category(size=20, class="form-control") }} + {{ form.category.label }} {{ form.category(size=20, + class="form-control") }}

{{ form.year_published.label }} {{ form.year_published(size=4, class="form-control") }} +
+
+ Current file: {{ book.file }} +
+
+ + Upload new file: {{form.file}} +

diff --git a/app/views.py b/app/views.py index acc2e22..7d77122 100755 --- a/app/views.py +++ b/app/views.py @@ -134,16 +134,13 @@ def edit_book_by_id(id): if request.method == 'POST': if user_form.validate_on_submit(): - # check if the post request has the file part - title = user_form.title.data # You could also have used request.form['name'] - input_authors = user_form.author.data # You could also have used request.form['email'] + # on submit, check fields + title = user_form.title.data + input_authors = user_form.author.data category = user_form.category.data year_published = user_form.year_published.data if year_published=="": year_published = None - # save user to database - #book = Book(title, author, filename, cover, file_extension) - book = Book.query.filter_by(id=id).first() book.title = title book.category = category @@ -159,6 +156,26 @@ def edit_book_by_id(id): a = Author(author_name=author_name) db.session.add(a) book.authors.append(a) + + # editing / uploading new file + if user_form.file.data: + file = request.files['file'] + if file.filename == '': + flash('No selected file') + return redirect(request.url) + if file and allowed_file(file.filename): + filename = secure_filename(file.filename) + allbooks = db.session.query(Book).all() + id = book.id + new_filename = str(id) +"_"+ filename + fullpath = os.path.join(app.config['UPLOAD_FOLDER'], new_filename) + name, file_extension = os.path.splitext(new_filename) + file.save(fullpath) + book.cover = get_cover(fullpath, name) + book.file = new_filename + else: + flash('allowed file formats: %s' % ALLOWED_EXTENSIONS) + db.session.commit() flash("%s updated" % (title)) return redirect(url_for('show_book_by_id', id=id)) diff --git a/whoosh/Book/MAIN_taxstcerlfadcokk.seg b/whoosh/Book/MAIN_taxstcerlfadcokk.seg new file mode 100644 index 0000000000000000000000000000000000000000..a10c22262e80e2750ddc649e7aad5112616e3627 GIT binary patch literal 5276 zcmZQz00AL>1_q{HCLoIii04+sWhboCP3cHTN=P{2qnXl^z-Gkbdxm>v*H;Gj&#a;f zPRu}M3xRk|xUo~t|NsBzG%#s+GkP<)+kXIx0)aQPHwz)-!Nh4+6k&FCT!h0 zVeQ@tvHT3@0)*MAW|uPoy9|Zdpmtrv;x7ho22_82&el)4!ptDa!`zO?iOk;2sM=^4 z9HiM5OdvS&g*m9^uVMmr^$Bx&1bY}m5)p)C15(Ni44K8nr405BU@=A}CMXM{1VQEi znVdij)KFZInw*)KgI^CwJqWXc^)MQmn8VdGz*s;jIJg01nFBFIJyTL@3QQFvGc%@} z7=alJY(6`XR%T#I&PdEG!mpzmssrL}rjo=Ygcq<{@f@VVf6EFHAPoX`5DJq#=XFvF zD$0v2t2BRlAe4UzS=@f@!$v5-2w6P${rW3V{vu@YrsT*U5I!TQ7y$xCQwTk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