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 0000000..a10c222 Binary files /dev/null and b/whoosh/Book/MAIN_taxstcerlfadcokk.seg differ diff --git a/whoosh/Book/_MAIN_4.toc b/whoosh/Book/_MAIN_4.toc new file mode 100644 index 0000000..e17d8c1 Binary files /dev/null and b/whoosh/Book/_MAIN_4.toc differ