From d979ed89c6f6ad8d6e0d89ea68c959dc073794d2 Mon Sep 17 00:00:00 2001 From: Cervinko Cera Date: Mon, 28 Mar 2016 16:42:38 +0200 Subject: [PATCH] Fixes for editing Authors --- cps/db.py | 2 +- cps/web.py | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cps/db.py b/cps/db.py index d4d0381f..33c4f061 100755 --- a/cps/db.py +++ b/cps/db.py @@ -88,7 +88,7 @@ class Authors(Base): def __init__(self, name, sort, link): self.name = name self.sort = sort - self.sort = link + self.link = link def __repr__(self): return u"".format(self.name, self.sort, self.link) diff --git a/cps/web.py b/cps/web.py index 8a45db4d..26520a76 100755 --- a/cps/web.py +++ b/cps/web.py @@ -662,7 +662,20 @@ def edit_book(book_id): to_save = request.form.to_dict() #print to_save 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": img = requests.get(to_save["cover_url"])