|
|
@ -172,7 +172,7 @@ def remove_book_by_id(id): |
|
|
|
@app.route('/books/<int:id>/edit', methods=['POST', 'GET']) |
|
|
|
def edit_book_by_id(id): |
|
|
|
book_to_edit = Book.query.filter_by(id=id).first() |
|
|
|
user_form = EditForm(title = book_to_edit.title, author =book_to_edit.authors, category = book_to_edit.category, year_published= book_to_edit.year_published, message= book_to_edit.message) |
|
|
|
user_form = EditForm(title = book_to_edit.title, author =book_to_edit.authors, category = book_to_edit.category, year_published= book_to_edit.year_published, message= book_to_edit.message, sameness=book_to_edit.sameness, gender=book_to_edit.gender, diversity=book_to_edit.diversity, who=book_to_edit.who) |
|
|
|
|
|
|
|
if request.method == 'POST': |
|
|
|
if user_form.validate_on_submit(): |
|
|
@ -182,6 +182,11 @@ def edit_book_by_id(id): |
|
|
|
category = user_form.category.data |
|
|
|
year_published = user_form.year_published.data |
|
|
|
message = user_form.message.data |
|
|
|
sameness = user_form.sameness.data |
|
|
|
gender = user_form.gender.data |
|
|
|
diversity = user_form.diversity.data |
|
|
|
who = user_form.who.data |
|
|
|
|
|
|
|
if year_published=="": |
|
|
|
year_published = None |
|
|
|
book = Book.query.filter_by(id=id).first() |
|
|
@ -189,6 +194,10 @@ def edit_book_by_id(id): |
|
|
|
book.category = category |
|
|
|
book.year_published = year_published |
|
|
|
book.message = message |
|
|
|
book.sameness = sameness |
|
|
|
book.gender = gender |
|
|
|
book.diversity = diversity |
|
|
|
book.who = who |
|
|
|
|
|
|
|
#authors update |
|
|
|
book.authors.clear() |
|
|
@ -258,7 +267,6 @@ def add_book(): |
|
|
|
sameness = upload_form.sameness.data |
|
|
|
gender = upload_form.gender.data |
|
|
|
diversity = upload_form.diversity.data |
|
|
|
time = upload_form.time.data |
|
|
|
who = upload_form.who.data |
|
|
|
|
|
|
|
if year_published=="": |
|
|
@ -308,9 +316,8 @@ def add_book(): |
|
|
|
html_string = render_template('potential_pdf.html', pbooks = pbooks) |
|
|
|
html = HTML(string=html_string) |
|
|
|
html.write_pdf(target='app/uploads/potential.pdf'); |
|
|
|
print ('potential_pdf') |
|
|
|
|
|
|
|
book = Book(title, filename, cover, file_extension, category, year_published, message, sameness, diversity, gender, who, time) |
|
|
|
book = Book(title, filename, cover, file_extension, category, year_published, message, sameness, diversity, gender, who) |
|
|
|
db.session.add(book) |
|
|
|
for author in authors: |
|
|
|
author_name = author.get("author_name") |
|
|
@ -667,17 +674,32 @@ def import_csv(): |
|
|
|
print("allreadyexists") |
|
|
|
else: |
|
|
|
cover = '' |
|
|
|
if row['file']: |
|
|
|
if row['file'] == '': |
|
|
|
file = 'potential.pdf' |
|
|
|
# file_extension = '.pdf' |
|
|
|
# ptitle = row['title'] |
|
|
|
# pbook = Potential(ptitle) |
|
|
|
# db.session.add(pbook) |
|
|
|
# db.session.commit() |
|
|
|
# pbooks = Potential.query.all() |
|
|
|
# template = 'app/templates/potential_pdf.html' |
|
|
|
# html_string = render_template('potential_pdf.html', pbooks = pbooks) |
|
|
|
# html = HTML(string=html_string) |
|
|
|
# html.write_pdf(target='app/uploads/potential.pdf') |
|
|
|
# print ('writing to potential_pdf') |
|
|
|
|
|
|
|
else: |
|
|
|
fullpath = os.path.join(app.config['UPLOAD_FOLDER'], row['file']) |
|
|
|
name, file_extension = os.path.splitext(row['file']) |
|
|
|
print ('get_cover', fullpath, name) |
|
|
|
cover = get_cover(fullpath, name) |
|
|
|
file = str(id) + "_" + row['file'] |
|
|
|
|
|
|
|
if row['year_published']: |
|
|
|
year_published = int(row['year_published']) |
|
|
|
else: |
|
|
|
year_published = None; |
|
|
|
book = Book(row['title'], row['file'], cover, row['fileformat'], row['category'],year_published, None, None, None, None, None, None) |
|
|
|
book = Book(row['title'], file, cover, row['fileformat'], row['category'],year_published, None, None, None, None, None) |
|
|
|
book.scapeX = float(row['scapeX']) |
|
|
|
book.scapeY = float(row['scapeY']) |
|
|
|
|
|
|
|