Fixes for editing Authors

This commit is contained in:
Cervinko Cera 2016-03-28 16:42:38 +02:00
parent 34cd613e29
commit d979ed89c6
2 changed files with 15 additions and 2 deletions

View File

@ -88,7 +88,7 @@ class Authors(Base):
def __init__(self, name, sort, link): def __init__(self, name, sort, link):
self.name = name self.name = name
self.sort = sort self.sort = sort
self.sort = link self.link = link
def __repr__(self): def __repr__(self):
return u"<Authors('{0},{1}{2}')>".format(self.name, self.sort, self.link) return u"<Authors('{0},{1}{2}')>".format(self.name, self.sort, self.link)

View File

@ -662,7 +662,20 @@ def edit_book(book_id):
to_save = request.form.to_dict() to_save = request.form.to_dict()
#print to_save #print to_save
book.title = to_save["book_title"] book.title = to_save["book_title"]
book.authors[0].name = to_save["author_name"]
is_author = db.session.query(db.Authors).filter(db.Authors.name.like('%' + to_save["author_name"].strip() + '%')).first()
if book.authors[0].name not in ("Unknown", "Unbekannt", "", " "):
if is_author:
book.authors.append(is_author)
book.authors.remove(db.session.query(db.Authors).get(book.authors[0].id))
else:
book.authors[0].name = to_save["author_name"].strip()
else:
if is_author:
book.authors.append(is_author)
else:
book.authors.append(db.Authors(to_save["author_name"].strip(), "", ""))
book.authors.remove(db.session.query(db.Authors).get(book.authors[0].id))
if to_save["cover_url"] and os.path.splitext(to_save["cover_url"])[1].lower() == ".jpg": if to_save["cover_url"] and os.path.splitext(to_save["cover_url"])[1].lower() == ".jpg":
img = requests.get(to_save["cover_url"]) img = requests.get(to_save["cover_url"])