Commit d979ed89 authored by Cervinko Cera's avatar Cervinko Cera

Fixes for editing Authors

parent 34cd613e
...@@ -88,7 +88,7 @@ class Authors(Base): ...@@ -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)
......
...@@ -662,7 +662,20 @@ def edit_book(book_id): ...@@ -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"])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment