|
|
@ -20,6 +20,9 @@ from functools import wraps
|
|
|
|
import base64
|
|
|
|
import base64
|
|
|
|
from sqlalchemy.sql import *
|
|
|
|
from sqlalchemy.sql import *
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
|
|
|
|
from wand.image import Image
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
from uuid import uuid4
|
|
|
|
|
|
|
|
|
|
|
|
app = (Flask(__name__))
|
|
|
|
app = (Flask(__name__))
|
|
|
|
|
|
|
|
|
|
|
@ -662,12 +665,16 @@ def edit_book(book_id):
|
|
|
|
db.session.connection().connection.connection.create_function("title_sort",1,db.title_sort)
|
|
|
|
db.session.connection().connection.connection.create_function("title_sort",1,db.title_sort)
|
|
|
|
book = db.session.query(db.Books).filter(db.Books.id == book_id).first()
|
|
|
|
book = db.session.query(db.Books).filter(db.Books.id == book_id).first()
|
|
|
|
if request.method == 'POST':
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
|
|
|
edited_books_id = set()
|
|
|
|
to_save = request.form.to_dict()
|
|
|
|
to_save = request.form.to_dict()
|
|
|
|
|
|
|
|
if book.title != to_save["book_title"]:
|
|
|
|
book.title = to_save["book_title"]
|
|
|
|
book.title = to_save["book_title"]
|
|
|
|
|
|
|
|
edited_books_id.add(book.id)
|
|
|
|
|
|
|
|
|
|
|
|
author_id = book.authors[0].id
|
|
|
|
author_id = book.authors[0].id
|
|
|
|
|
|
|
|
if book.authors[0].name != to_save["author_name"].strip():
|
|
|
|
is_author = db.session.query(db.Authors).filter(db.Authors.name == to_save["author_name"].strip()).first()
|
|
|
|
is_author = db.session.query(db.Authors).filter(db.Authors.name == to_save["author_name"].strip()).first()
|
|
|
|
|
|
|
|
edited_books_id.add(book.id)
|
|
|
|
if book.authors[0].name not in ("Unknown", "Unbekannt", "", " "):
|
|
|
|
if book.authors[0].name not in ("Unknown", "Unbekannt", "", " "):
|
|
|
|
if is_author:
|
|
|
|
if is_author:
|
|
|
|
book.authors.append(is_author)
|
|
|
|
book.authors.append(is_author)
|
|
|
@ -677,6 +684,8 @@ def edit_book(book_id):
|
|
|
|
db.session.query(db.Authors).filter(db.Authors.id == author_id).delete()
|
|
|
|
db.session.query(db.Authors).filter(db.Authors.id == author_id).delete()
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
book.authors[0].name = to_save["author_name"].strip()
|
|
|
|
book.authors[0].name = to_save["author_name"].strip()
|
|
|
|
|
|
|
|
for linked_book in db.session.query(db.Books).filter(db.Books.authors.any(db.Authors.id.is_(author_id))).all():
|
|
|
|
|
|
|
|
edited_books_id.add(linked_book.id)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
if is_author:
|
|
|
|
if is_author:
|
|
|
|
book.authors.append(is_author)
|
|
|
|
book.authors.append(is_author)
|
|
|
@ -720,9 +729,44 @@ def edit_book(book_id):
|
|
|
|
new_rating = db.Ratings(rating=int(to_save["rating"].strip()))
|
|
|
|
new_rating = db.Ratings(rating=int(to_save["rating"].strip()))
|
|
|
|
book.ratings[0] = new_rating
|
|
|
|
book.ratings[0] = new_rating
|
|
|
|
db.session.commit()
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
for b in edited_books_id:
|
|
|
|
|
|
|
|
helper.update_dir_stucture(b)
|
|
|
|
if "detail_view" in to_save:
|
|
|
|
if "detail_view" in to_save:
|
|
|
|
return redirect(url_for('show_book', id=book.id))
|
|
|
|
return redirect(url_for('show_book', id=book.id))
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return render_template('edit_book.html', book=book)
|
|
|
|
return render_template('edit_book.html', book=book)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return render_template('edit_book.html', book=book)
|
|
|
|
return render_template('edit_book.html', book=book)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/upload", methods = ["GET", "POST"])
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
|
|
|
def upload():
|
|
|
|
|
|
|
|
## create the function for sorting...
|
|
|
|
|
|
|
|
db.session.connection().connection.connection.create_function("title_sort",1,db.title_sort)
|
|
|
|
|
|
|
|
db.session.connection().connection.connection.create_function('uuid4', 0, lambda : str(uuid4()))
|
|
|
|
|
|
|
|
if request.method == 'POST' and 'btn-upload' in request.files:
|
|
|
|
|
|
|
|
file = request.files['btn-upload']
|
|
|
|
|
|
|
|
filename = file.filename
|
|
|
|
|
|
|
|
filename_root, fileextension = os.path.splitext(filename)
|
|
|
|
|
|
|
|
title_dir = helper.get_valid_filename(filename_root, False)
|
|
|
|
|
|
|
|
filepath = config.DB_ROOT + "/Unknown/" + title_dir
|
|
|
|
|
|
|
|
print filepath
|
|
|
|
|
|
|
|
if not os.path.exists(filepath):
|
|
|
|
|
|
|
|
os.makedirs(filepath)
|
|
|
|
|
|
|
|
file.save(os.path.join(filepath, filename))
|
|
|
|
|
|
|
|
with Image(filename=os.path.join(filepath, filename)+"[0]", resolution=150) as img:
|
|
|
|
|
|
|
|
img.compression_quality = 88
|
|
|
|
|
|
|
|
img.save(filename=os.path.join(filepath, "cover.jpg"))
|
|
|
|
|
|
|
|
is_author = db.session.query(db.Authors).filter(db.Authors.name.like("Unknown")).first()
|
|
|
|
|
|
|
|
if is_author:
|
|
|
|
|
|
|
|
db_author = is_author
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
db_author = db.Authors("Unknown", "", "")
|
|
|
|
|
|
|
|
db.session.add(db_author)
|
|
|
|
|
|
|
|
db_book = db.Books(filename_root, "", "", datetime.datetime.now(), "", 1, datetime.datetime(101, 01,01), "Unknown/" + title_dir, 1, db_author, [])
|
|
|
|
|
|
|
|
db_book.authors.append(db_author)
|
|
|
|
|
|
|
|
#todo append data,...
|
|
|
|
|
|
|
|
db.session.add(db_book)
|
|
|
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
print filename
|
|
|
|
|
|
|
|
return render_template('search.html', searchterm="")
|
|
|
|