From 2207622bbf63105688620f05b58e2cb6ba512414 Mon Sep 17 00:00:00 2001 From: Cervinko Cera Date: Wed, 20 Apr 2016 00:23:14 +0200 Subject: [PATCH 01/23] fix for edit page after upload --- config.ini | 12 ++++++------ cps/web.py | 6 +++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/config.ini b/config.ini index 1bca2dc1..8f265869 100644 --- a/config.ini +++ b/config.ini @@ -1,12 +1,12 @@ [General] -DB_ROOT = -APP_DB_ROOT = -MAIN_DIR = -LOG_DIR = +DB_ROOT = /home/christoph/Calibre-Bibliothek_test +APP_DB_ROOT = /home/christoph/computer/calibre-web +MAIN_DIR = /home/christoph/computer/calibre-web +LOG_DIR = /home/christoph/computer/calibre-web PORT = 8083 NEWEST_BOOKS = 60 [Advanced] TITLE_REGEX = ^(A|The|An|Der|Die|Das|Den|Ein|Eine|Einen|Dem|Des|Einem|Eines)\s+ -DEVELOPMENT = 0 +DEVELOPMENT = 1 PUBLIC_REG = 0 -UPLOADING = 0 +UPLOADING = 1 diff --git a/cps/web.py b/cps/web.py index 28512c23..b6863a2b 100755 --- a/cps/web.py +++ b/cps/web.py @@ -896,4 +896,8 @@ def upload(): db.session.add(db_book) db.session.commit() - return render_template('edit_book.html', book=db_book) + author_names = [] + for author in db_book.authors: + author_names.append(author.name) + + return render_template('edit_book.html', book=db_book, authors=author_names) From e0432a9ad7fb85bd5eb5f4360e4520b527e79bf4 Mon Sep 17 00:00:00 2001 From: Cervinko Cera Date: Wed, 20 Apr 2016 00:29:53 +0200 Subject: [PATCH 02/23] fix for edit page after upload --- config.ini | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/config.ini b/config.ini index 8f265869..1bca2dc1 100644 --- a/config.ini +++ b/config.ini @@ -1,12 +1,12 @@ [General] -DB_ROOT = /home/christoph/Calibre-Bibliothek_test -APP_DB_ROOT = /home/christoph/computer/calibre-web -MAIN_DIR = /home/christoph/computer/calibre-web -LOG_DIR = /home/christoph/computer/calibre-web +DB_ROOT = +APP_DB_ROOT = +MAIN_DIR = +LOG_DIR = PORT = 8083 NEWEST_BOOKS = 60 [Advanced] TITLE_REGEX = ^(A|The|An|Der|Die|Das|Den|Ein|Eine|Einen|Dem|Des|Einem|Eines)\s+ -DEVELOPMENT = 1 +DEVELOPMENT = 0 PUBLIC_REG = 0 -UPLOADING = 1 +UPLOADING = 0 From 649d54b0f93f89dc8512e623c0ca88b4d3e1a32c Mon Sep 17 00:00:00 2001 From: Cervinko Cera Date: Wed, 20 Apr 2016 00:30:50 +0200 Subject: [PATCH 03/23] fix for edit page after upload --- config.ini | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 config.ini diff --git a/config.ini b/config.ini deleted file mode 100644 index 1bca2dc1..00000000 --- a/config.ini +++ /dev/null @@ -1,12 +0,0 @@ -[General] -DB_ROOT = -APP_DB_ROOT = -MAIN_DIR = -LOG_DIR = -PORT = 8083 -NEWEST_BOOKS = 60 -[Advanced] -TITLE_REGEX = ^(A|The|An|Der|Die|Das|Den|Ein|Eine|Einen|Dem|Des|Einem|Eines)\s+ -DEVELOPMENT = 0 -PUBLIC_REG = 0 -UPLOADING = 0 From cfd5b3ab1270e09038980a30114947630bf094b5 Mon Sep 17 00:00:00 2001 From: Cervinko Cera Date: Wed, 20 Apr 2016 07:54:28 +0200 Subject: [PATCH 04/23] fix for edit page after upload - reset config.ini --- config.ini | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 config.ini diff --git a/config.ini b/config.ini new file mode 100644 index 00000000..1bca2dc1 --- /dev/null +++ b/config.ini @@ -0,0 +1,12 @@ +[General] +DB_ROOT = +APP_DB_ROOT = +MAIN_DIR = +LOG_DIR = +PORT = 8083 +NEWEST_BOOKS = 60 +[Advanced] +TITLE_REGEX = ^(A|The|An|Der|Die|Das|Den|Ein|Eine|Einen|Dem|Des|Einem|Eines)\s+ +DEVELOPMENT = 0 +PUBLIC_REG = 0 +UPLOADING = 0 From 66cea6a3a65f32ee61171eb6f4b566aa413b7baa Mon Sep 17 00:00:00 2001 From: Cervinko Cera Date: Wed, 20 Apr 2016 08:00:28 +0200 Subject: [PATCH 05/23] fix for edit page after upload - reset config.ini --- config.ini | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 config.ini diff --git a/config.ini b/config.ini deleted file mode 100644 index 1bca2dc1..00000000 --- a/config.ini +++ /dev/null @@ -1,12 +0,0 @@ -[General] -DB_ROOT = -APP_DB_ROOT = -MAIN_DIR = -LOG_DIR = -PORT = 8083 -NEWEST_BOOKS = 60 -[Advanced] -TITLE_REGEX = ^(A|The|An|Der|Die|Das|Den|Ein|Eine|Einen|Dem|Des|Einem|Eines)\s+ -DEVELOPMENT = 0 -PUBLIC_REG = 0 -UPLOADING = 0 From 135818d18cecb770eabe81de1ef587e647d3a279 Mon Sep 17 00:00:00 2001 From: Cervinko Cera Date: Wed, 20 Apr 2016 18:58:34 +0200 Subject: [PATCH 06/23] reset config.ini --- config.ini | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 config.ini diff --git a/config.ini b/config.ini new file mode 100644 index 00000000..d35aa258 --- /dev/null +++ b/config.ini @@ -0,0 +1,12 @@ +[General] +DB_ROOT = +APP_DB_ROOT = +MAIN_DIR = +LOG_DIR = +PORT = 8083 +NEWEST_BOOKS = 60 +[Advanced] +TITLE_REGEX = ^(A|The|An|Der|Die|Das|Den|Ein|Eine|Einen|Dem|Des|Einem|Eines)\s+ +DEVELOPMENT = 0 +PUBLIC_REG = 0 +UPLOADING = 0 From 82271a78c94c7157fe0544c92f2cc06855e1df98 Mon Sep 17 00:00:00 2001 From: Cervinko Cera Date: Wed, 20 Apr 2016 19:00:17 +0200 Subject: [PATCH 07/23] config ini test --- config.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.ini b/config.ini index d35aa258..46624bf0 100644 --- a/config.ini +++ b/config.ini @@ -1,5 +1,5 @@ [General] -DB_ROOT = +DB_ROOT = test APP_DB_ROOT = MAIN_DIR = LOG_DIR = From 6c40bfdd08debfbb4b395dae4ec6f682dc743b33 Mon Sep 17 00:00:00 2001 From: Cervinko Cera Date: Wed, 20 Apr 2016 19:25:16 +0200 Subject: [PATCH 08/23] add config.ini_example and remove config.ini from git --- config.ini => config.ini_example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename config.ini => config.ini_example (93%) diff --git a/config.ini b/config.ini_example similarity index 93% rename from config.ini rename to config.ini_example index 46624bf0..d35aa258 100644 --- a/config.ini +++ b/config.ini_example @@ -1,5 +1,5 @@ [General] -DB_ROOT = test +DB_ROOT = APP_DB_ROOT = MAIN_DIR = LOG_DIR = From 0ee46e4b5e1bacad7c74ae7ce1b9999ba82b247d Mon Sep 17 00:00:00 2001 From: Cervinko Cera Date: Sun, 17 Apr 2016 18:03:47 +0200 Subject: [PATCH 09/23] custom columns unfinished --- cps/db.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ cps/helper.py | 6 ++++++ cps/web.py | 1 + 3 files changed, 64 insertions(+) diff --git a/cps/db.py b/cps/db.py index b08592a1..bfceabe9 100755 --- a/cps/db.py +++ b/cps/db.py @@ -49,6 +49,17 @@ books_languages_link = Table('books_languages_link', Base.metadata, Column('lang_code', Integer, ForeignKey('languages.id'), primary_key=True) ) +#cc = conn.execute("SELECT id FROM custom_columns") +#cc_ids = [] +#books_custom_column_links = {} +#for row in cc: +# cc_link=Table('books_custom_column_' + str(row.id) + '_link', Base.metadata, +# Column('book', Integer, ForeignKey('books.id'), primary_key=True), +# Column('custom_column', Integer, ForeignKey('custom_column_' + str(row.id) + '.id'), primary_key=True) +# ) +# books_custom_column_links[row.id] = cc_link +# cc_ids.append(row.id) + class Comments(Base): __tablename__ = 'comments' @@ -170,6 +181,16 @@ class Books(Base): series = relationship('Series', secondary=books_series_link, backref='books') ratings = relationship('Ratings', secondary=books_ratings_link, backref='books') languages = relationship('Languages', secondary=books_languages_link, backref='books') + #custom_columns = {} + #for id in cc_ids: + # print id + # custom_columns[id] = relationship(cc_classes[id], secondary=books_custom_column_links[id], backref='books') + #custom_columns[1] = relationship(cc_classes[1], secondary=books_custom_column_links[1], backref='books') + #custom_columns[2] = relationship(cc_classes[2], secondary=books_custom_column_links[2], backref='books') + #custom_columns[3] = relationship(cc_classes[3], secondary=books_custom_column_links[3], backref='books') + + + def __init__(self, title, sort, author_sort, timestamp, pubdate, series_index, last_modified, path, has_cover, authors, tags): self.title = title @@ -184,8 +205,44 @@ class Books(Base): def __repr__(self): return u"".format(self.title, self.sort, self.author_sort, self.timestamp, self.pubdate, self.series_index, self.last_modified ,self.path, self.has_cover) + +class Custom_Columns(Base): + __tablename__ = 'custom_columns' + + id = Column(Integer,primary_key=True) + label = Column(String) + name = Column(String) + datatype = Column(String) + mark_for_delete = Column(Boolean) + editable = Column(Boolean) + display = Column(String) + is_multiple = Column(Boolean) + normalized = Column(Boolean) + +#class Custom_Column(object): +# def __init__(self, value): +# self.value = value + +#def get_cc_table(id): +# custom_column = Custom_Column +# table_name = 'custom_column_' + str(id) +# table_object = Table(table_name, Base.metadata, +# Column('id', Integer, primary_key=True, autoincrement=True), +# Column('value', String) +# ) +# clear_mappers() +# mapper(custom_column, table_object, properties={'books' + str(id): relationship(Books, secondary=books_custom_column_links[id] , backref='custom_column_' + str(id))}) +# return custom_column + +#cc_classes={} +#for id in cc_ids: +# cc_classes[id] = get_cc_table(id) +#print cc_classes + Base.metadata.create_all(engine) Session = sessionmaker() Session.configure(bind=engine) session = Session() + + diff --git a/cps/helper.py b/cps/helper.py index 7ac5532d..629c8109 100755 --- a/cps/helper.py +++ b/cps/helper.py @@ -199,3 +199,9 @@ def update_dir_stucture(book_id): os.renames(path, new_author_path) book.path = new_authordir + "/" + book.path.split("/")[1] db.session.commit() + +def get_custom_columns(id): + cc = db.session.query(db.Custom_Columns).all() + for c in cc: + print c.name + diff --git a/cps/web.py b/cps/web.py index b6863a2b..978b7f53 100755 --- a/cps/web.py +++ b/cps/web.py @@ -316,6 +316,7 @@ def discover(page): @app.route("/book/") def show_book(id): entries = db.session.query(db.Books).filter(db.Books.id == id).first() + helper.get_custom_columns(entries.id) book_in_shelfs = [] shelfs = ub.session.query(ub.BookShelf).filter(ub.BookShelf.book_id == id).all() for entry in shelfs: From 202cbc26a70b5de59e54e9a159fe6c63f5ff96eb Mon Sep 17 00:00:00 2001 From: Cervinko Cera Date: Wed, 20 Apr 2016 00:20:02 +0200 Subject: [PATCH 10/23] custom columns unfinished --- cps/db.py | 70 +++++++++++++----------------------- cps/helper.py | 8 ++--- cps/templates/detail.html | 17 +++++++++ cps/templates/edit_book.html | 19 ++++++++++ cps/web.py | 17 +++++---- 5 files changed, 75 insertions(+), 56 deletions(-) diff --git a/cps/db.py b/cps/db.py index bfceabe9..52c350da 100755 --- a/cps/db.py +++ b/cps/db.py @@ -49,17 +49,24 @@ books_languages_link = Table('books_languages_link', Base.metadata, Column('lang_code', Integer, ForeignKey('languages.id'), primary_key=True) ) -#cc = conn.execute("SELECT id FROM custom_columns") -#cc_ids = [] -#books_custom_column_links = {} -#for row in cc: -# cc_link=Table('books_custom_column_' + str(row.id) + '_link', Base.metadata, -# Column('book', Integer, ForeignKey('books.id'), primary_key=True), -# Column('custom_column', Integer, ForeignKey('custom_column_' + str(row.id) + '.id'), primary_key=True) -# ) -# books_custom_column_links[row.id] = cc_link -# cc_ids.append(row.id) - +cc = conn.execute("SELECT id FROM custom_columns") +cc_ids = [] + +books_custom_column_links = {} +for row in cc: + books_custom_column_links[row.id] = Table('books_custom_column_' + str(row.id) + '_link', Base.metadata, + Column('book', Integer, ForeignKey('books.id'), primary_key=True), + Column('value', Integer, ForeignKey('custom_column_' + str(row.id) + '.id'), primary_key=True) + ) + #books_custom_column_links[row.id]= + cc_ids.append(row.id) + +cc_classes = {} +for id in cc_ids: + ccdict={'__tablename__':'custom_column_' + str(id), + 'id':Column(Integer, primary_key=True), + 'value':Column(String)} + cc_classes[id] = type('Custom_Column_' + str(id), (Base,), ccdict) class Comments(Base): __tablename__ = 'comments' @@ -163,7 +170,7 @@ class Data(Base): class Books(Base): __tablename__ = 'books' - id = Column(Integer,primary_key=True) + id = Column(Integer, primary_key=True) title = Column(String) sort = Column(String) author_sort = Column(String) @@ -181,17 +188,7 @@ class Books(Base): series = relationship('Series', secondary=books_series_link, backref='books') ratings = relationship('Ratings', secondary=books_ratings_link, backref='books') languages = relationship('Languages', secondary=books_languages_link, backref='books') - #custom_columns = {} - #for id in cc_ids: - # print id - # custom_columns[id] = relationship(cc_classes[id], secondary=books_custom_column_links[id], backref='books') - #custom_columns[1] = relationship(cc_classes[1], secondary=books_custom_column_links[1], backref='books') - #custom_columns[2] = relationship(cc_classes[2], secondary=books_custom_column_links[2], backref='books') - #custom_columns[3] = relationship(cc_classes[3], secondary=books_custom_column_links[3], backref='books') - - - def __init__(self, title, sort, author_sort, timestamp, pubdate, series_index, last_modified, path, has_cover, authors, tags): self.title = title self.sort = sort @@ -205,7 +202,9 @@ class Books(Base): def __repr__(self): return u"".format(self.title, self.sort, self.author_sort, self.timestamp, self.pubdate, self.series_index, self.last_modified ,self.path, self.has_cover) - +for id in cc_ids: + setattr(Books, 'custom_column_' + str(id), relationship(cc_classes[id], secondary=books_custom_column_links[id], backref='books')) + class Custom_Columns(Base): __tablename__ = 'custom_columns' @@ -217,30 +216,9 @@ class Custom_Columns(Base): editable = Column(Boolean) display = Column(String) is_multiple = Column(Boolean) - normalized = Column(Boolean) - -#class Custom_Column(object): -# def __init__(self, value): -# self.value = value - -#def get_cc_table(id): -# custom_column = Custom_Column -# table_name = 'custom_column_' + str(id) -# table_object = Table(table_name, Base.metadata, -# Column('id', Integer, primary_key=True, autoincrement=True), -# Column('value', String) -# ) -# clear_mappers() -# mapper(custom_column, table_object, properties={'books' + str(id): relationship(Books, secondary=books_custom_column_links[id] , backref='custom_column_' + str(id))}) -# return custom_column - -#cc_classes={} -#for id in cc_ids: -# cc_classes[id] = get_cc_table(id) -#print cc_classes - + normalized = Column(Boolean) -Base.metadata.create_all(engine) +#Base.metadata.create_all(engine) Session = sessionmaker() Session.configure(bind=engine) session = Session() diff --git a/cps/helper.py b/cps/helper.py index 629c8109..4bd9d952 100755 --- a/cps/helper.py +++ b/cps/helper.py @@ -200,8 +200,8 @@ def update_dir_stucture(book_id): book.path = new_authordir + "/" + book.path.split("/")[1] db.session.commit() -def get_custom_columns(id): - cc = db.session.query(db.Custom_Columns).all() - for c in cc: - print c.name +#def get_custom_columns(id): +# cc = db.session.query(db.Custom_Columns).all() +# for c in cc: +# print c.name diff --git a/cps/templates/detail.html b/cps/templates/detail.html index bcaad48a..5cf9d5e2 100644 --- a/cps/templates/detail.html +++ b/cps/templates/detail.html @@ -58,6 +58,23 @@

{% endif %} + + {% if cc|length > 0 %} +

+

+ {% for c in cc %} + {% if entry['custom_column_' ~ c.id]|length > 0 %} + {{ c.name }}: + {% for column in entry['custom_column_' ~ c.id] %} + {{ column.value }} + {% endfor %} +
+ {% endif %} + {% endfor %} +
+

+ {% endif %} + {% if entry.comments|length > 0 %}

Description:

diff --git a/cps/templates/edit_book.html b/cps/templates/edit_book.html index b4ec3661..a3746e4e 100644 --- a/cps/templates/edit_book.html +++ b/cps/templates/edit_book.html @@ -43,6 +43,25 @@ + {% if cc|length > 0 %} + {% for c in cc %} +
+ + 0 %} + {% for column in book['custom_column_' ~ c.id] %} + value="{{ column.value }} {% if not loop.last %}, {% endif %} + {% endfor %} + " + {% endif %} + > +
+ {% endfor %} +
+

+ {% endif %} + +
-

{% endif %} diff --git a/cps/web.py b/cps/web.py index 08c4636f..eb855ae4 100755 --- a/cps/web.py +++ b/cps/web.py @@ -316,7 +316,9 @@ def discover(page): @app.route("/book/") def show_book(id): entries = db.session.query(db.Books).filter(db.Books.id == id).first() - cc = db.session.query(db.Custom_Columns).all() + cc = db.session.query(db.Custom_Columns).filter(db.Custom_Columns.datatype.notin_(db.cc_exceptions)).all() + for c in cc: + print c.name #print entries.custom_column_1 #helper.get_custom_columns(entries.id) book_in_shelfs = [] @@ -697,7 +699,9 @@ def edit_user(user_id): def edit_book(book_id): ## create the function for sorting... db.session.connection().connection.connection.create_function("title_sort",1,db.title_sort) - cc = db.session.query(db.Custom_Columns).all() + cc = db.session.query(db.Custom_Columns).filter(db.Custom_Columns.datatype.notin_(db.cc_exceptions)).all() + for c in cc: + print c.name book = db.session.query(db.Books).filter(db.Books.id == book_id).first() author_names = [] for author in book.authors: @@ -744,12 +748,12 @@ def edit_book(book_id): if len(add_authors) > 0: for add_author in add_authors: # check if an author with that name exists - t_author = db.session.query(db.Authors).filter(db.Authors.name == add_author).first(); + t_author = db.session.query(db.Authors).filter(db.Authors.name == add_author).first() # if no author is found add it if t_author == None: new_author = db.Authors(add_author, add_author, "") db.session.add(new_author) - t_author = db.session.query(db.Authors).filter(db.Authors.name == add_author).first(); + t_author = db.session.query(db.Authors).filter(db.Authors.name == add_author).first() # add author to book book.authors.append(t_author) if author0_before_edit != book.authors[0].name: @@ -803,14 +807,14 @@ def edit_book(book_id): if len(add_tags) > 0: for add_tag in add_tags: # check if a tag with that name exists - new_tag = db.session.query(db.Tags).filter(db.Tags.name == add_tag).first(); + new_tag = db.session.query(db.Tags).filter(db.Tags.name == add_tag).first() # if no tag is found add it if new_tag == None: new_tag = db.Tags(add_tag) db.session.add(new_tag) - new_tag = db.session.query(db.Tags).filter(db.Tags.name == add_tag).first(); + new_tag = db.session.query(db.Tags).filter(db.Tags.name == add_tag).first() # add tag to book - book.tags.append(new_tag) + book.tags.append(new_tag) if to_save["series"].strip(): is_series = db.session.query(db.Series).filter(db.Series.name.like('%' + to_save["series"].strip() + '%')).first() @@ -826,6 +830,38 @@ def edit_book(book_id): else: new_rating = db.Ratings(rating=int(to_save["rating"].strip())) book.ratings[0] = new_rating + + for c in cc: + cc_string = "custom_column_" + str(c.id) + if len(getattr(book, cc_string)) > 0: + cc_db_value = getattr(book, cc_string)[0].value + else: + cc_db_value = None + if to_save[cc_string].strip(): + if to_save[cc_string].strip() != cc_db_value: + if cc_db_value != None: + #remove old cc_val + del_cc = getattr(book, cc_string)[0] + getattr(book, cc_string).remove(del_cc) + if len(del_cc.books) == 0: + db.session.delete(del_cc) + cc_class = db.cc_classes[c.id] + new_cc = db.session.query(cc_class).filter(cc_class.value == to_save[cc_string].strip()).first() + # if no cc val is found add it + if new_cc == None: + new_cc = cc_class(value=to_save[cc_string].strip()) + db.session.add(new_cc) + new_cc = db.session.query(cc_class).filter(cc_class.value == to_save[cc_string].strip()).first() + # add cc value to book + getattr(book, cc_string).append(new_cc) + else: + if cc_db_value != None: + #remove old cc_val + del_cc = getattr(book, cc_string)[0] + getattr(book, cc_string).remove(del_cc) + if len(del_cc.books) == 0: + db.session.delete(del_cc) + db.session.commit() author_names = [] for author in book.authors: @@ -905,5 +941,5 @@ def upload(): author_names = [] for author in db_book.authors: author_names.append(author.name) - - return render_template('edit_book.html', book=db_book, authors=author_names) + cc = db.session.query(db.Custom_Columns).filter(db.Custom_Columns.datatype.notin_(db.cc_exceptions)).all() + return render_template('edit_book.html', book=db_book, authors=author_names, cc=cc) From 9a1f48967c731f1d8b2b6661e406820a021fa184 Mon Sep 17 00:00:00 2001 From: Cervinko Cera Date: Wed, 20 Apr 2016 19:10:01 +0200 Subject: [PATCH 12/23] support for custom columns --- config.ini_example | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.ini_example b/config.ini_example index d35aa258..f1b18a87 100644 --- a/config.ini_example +++ b/config.ini_example @@ -7,6 +7,6 @@ PORT = 8083 NEWEST_BOOKS = 60 [Advanced] TITLE_REGEX = ^(A|The|An|Der|Die|Das|Den|Ein|Eine|Einen|Dem|Des|Einem|Eines)\s+ -DEVELOPMENT = 0 +DEVELOPMENT = 1 PUBLIC_REG = 0 -UPLOADING = 0 +UPLOADING = 1 From 9324c554bfed3b7a3dcdb3c132a51f52a4bb549e Mon Sep 17 00:00:00 2001 From: Cervinko Cera Date: Wed, 20 Apr 2016 19:12:18 +0200 Subject: [PATCH 13/23] support for custom columns --- config.ini | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 config.ini diff --git a/config.ini b/config.ini new file mode 100644 index 00000000..e69de29b From 6a3115ebd53b24e45580cf5fe4425fe3340f91a8 Mon Sep 17 00:00:00 2001 From: Cervinko Cera Date: Wed, 20 Apr 2016 19:19:44 +0200 Subject: [PATCH 14/23] support for custom columns --- config.ini | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/config.ini b/config.ini index e69de29b..d35aa258 100644 --- a/config.ini +++ b/config.ini @@ -0,0 +1,12 @@ +[General] +DB_ROOT = +APP_DB_ROOT = +MAIN_DIR = +LOG_DIR = +PORT = 8083 +NEWEST_BOOKS = 60 +[Advanced] +TITLE_REGEX = ^(A|The|An|Der|Die|Das|Den|Ein|Eine|Einen|Dem|Des|Einem|Eines)\s+ +DEVELOPMENT = 0 +PUBLIC_REG = 0 +UPLOADING = 0 From 27d5a79efb35de79e1dc98fa6b2c7e0d8bd4a608 Mon Sep 17 00:00:00 2001 From: Cervinko Cera Date: Wed, 20 Apr 2016 19:42:24 +0200 Subject: [PATCH 15/23] remove some commented code and debug prints --- cps/helper.py | 5 ----- cps/web.py | 8 -------- 2 files changed, 13 deletions(-) diff --git a/cps/helper.py b/cps/helper.py index 4bd9d952..a101778f 100755 --- a/cps/helper.py +++ b/cps/helper.py @@ -200,8 +200,3 @@ def update_dir_stucture(book_id): book.path = new_authordir + "/" + book.path.split("/")[1] db.session.commit() -#def get_custom_columns(id): -# cc = db.session.query(db.Custom_Columns).all() -# for c in cc: -# print c.name - diff --git a/cps/web.py b/cps/web.py index eb855ae4..b355441d 100755 --- a/cps/web.py +++ b/cps/web.py @@ -317,10 +317,6 @@ def discover(page): def show_book(id): entries = db.session.query(db.Books).filter(db.Books.id == id).first() cc = db.session.query(db.Custom_Columns).filter(db.Custom_Columns.datatype.notin_(db.cc_exceptions)).all() - for c in cc: - print c.name - #print entries.custom_column_1 - #helper.get_custom_columns(entries.id) book_in_shelfs = [] shelfs = ub.session.query(ub.BookShelf).filter(ub.BookShelf.book_id == id).all() for entry in shelfs: @@ -700,8 +696,6 @@ def edit_book(book_id): ## create the function for sorting... db.session.connection().connection.connection.create_function("title_sort",1,db.title_sort) cc = db.session.query(db.Custom_Columns).filter(db.Custom_Columns.datatype.notin_(db.cc_exceptions)).all() - for c in cc: - print c.name book = db.session.query(db.Books).filter(db.Books.id == book_id).first() author_names = [] for author in book.authors: @@ -923,9 +917,7 @@ def upload(): img.save(filename=os.path.join(filepath, "cover.jpg")) has_cover = 1 is_author = db.session.query(db.Authors).filter(db.Authors.name == author).first() - print is_author if is_author: - print 'Unknown is known Author' db_author = is_author else: db_author = db.Authors(author, "", "") From f57c9c5951bb87dea634715619af5144882b06c7 Mon Sep 17 00:00:00 2001 From: Cervinko Cera Date: Wed, 20 Apr 2016 23:53:55 +0200 Subject: [PATCH 16/23] remove if clauses for int and float in edit_book.html --- config.ini | 12 ++++++------ cps/templates/edit_book.html | 15 +++++---------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/config.ini b/config.ini index d35aa258..8f265869 100644 --- a/config.ini +++ b/config.ini @@ -1,12 +1,12 @@ [General] -DB_ROOT = -APP_DB_ROOT = -MAIN_DIR = -LOG_DIR = +DB_ROOT = /home/christoph/Calibre-Bibliothek_test +APP_DB_ROOT = /home/christoph/computer/calibre-web +MAIN_DIR = /home/christoph/computer/calibre-web +LOG_DIR = /home/christoph/computer/calibre-web PORT = 8083 NEWEST_BOOKS = 60 [Advanced] TITLE_REGEX = ^(A|The|An|Der|Die|Das|Den|Ein|Eine|Einen|Dem|Des|Einem|Eines)\s+ -DEVELOPMENT = 0 +DEVELOPMENT = 1 PUBLIC_REG = 0 -UPLOADING = 0 +UPLOADING = 1 diff --git a/cps/templates/edit_book.html b/cps/templates/edit_book.html index 846175ee..bdbc2272 100644 --- a/cps/templates/edit_book.html +++ b/cps/templates/edit_book.html @@ -67,18 +67,13 @@ {% endif %} - {% if c.datatype == ('rating' or 'float' or 'int') %} - 0 %} {% for column in book['custom_column_' ~ c.id] %} - value="{{ column.value }}{% if not loop.last %}, {% endif %}{% endfor %}"{% endif %}> + value="{{ column.value }}{% if not loop.last %}, {% endif %} + {% endfor %}" + {% endif %}> {% endif %} {% endfor %} From a21a9d6510e2255bdbc12e08ff1246ace5757d99 Mon Sep 17 00:00:00 2001 From: Cervinko Cera Date: Thu, 21 Apr 2016 09:04:08 +0200 Subject: [PATCH 17/23] save rating as rating*2 in db and show rating/2 in interface --- cps/templates/edit_book.html | 2 +- cps/web.py | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/cps/templates/edit_book.html b/cps/templates/edit_book.html index bdbc2272..cd8b2aa1 100644 --- a/cps/templates/edit_book.html +++ b/cps/templates/edit_book.html @@ -37,7 +37,7 @@
- +
diff --git a/cps/web.py b/cps/web.py index b355441d..27fb8713 100755 --- a/cps/web.py +++ b/cps/web.py @@ -817,13 +817,25 @@ def edit_book(book_id): else: new_series = db.Series(name=to_save["series"].strip(), sort=to_save["series"].strip()) book.series.append(new_series) + if to_save["rating"].strip(): - is_rating = db.session.query(db.Ratings).filter(db.Ratings.rating == int(to_save["rating"].strip())).first() - if is_rating: - book.ratings[0] = is_rating - else: - new_rating = db.Ratings(rating=int(to_save["rating"].strip())) - book.ratings[0] = new_rating + old_rating = False + if len(book.ratings) > 0: + old_rating = book.ratings[0].rating + ratingx2 = int(to_save["rating"]) *2 + if ratingx2 != old_rating: + is_rating = db.session.query(db.Ratings).filter(db.Ratings.rating == ratingx2).first() + if is_rating: + book.ratings.append(is_rating) + else: + new_rating = db.Ratings(rating=ratingx2) + book.ratings.append(new_rating) + if old_rating: + book.ratings.remove(book.ratings[0]) + else: + if len(book.ratings) > 0: + book.ratings.remove(book.ratings[0]) + for c in cc: cc_string = "custom_column_" + str(c.id) From 931981a37aec9192136b3c003a40198d812bd27b Mon Sep 17 00:00:00 2001 From: Cervinko Cera Date: Thu, 21 Apr 2016 12:46:26 +0200 Subject: [PATCH 18/23] fix for custom column 'rating' --- cps/templates/edit_book.html | 4 +--- cps/web.py | 6 +++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cps/templates/edit_book.html b/cps/templates/edit_book.html index cd8b2aa1..7b74d7e2 100644 --- a/cps/templates/edit_book.html +++ b/cps/templates/edit_book.html @@ -70,9 +70,7 @@ {% if c.datatype == 'rating' %} 0 %} - {% for column in book['custom_column_' ~ c.id] %} - value="{{ column.value }}{% if not loop.last %}, {% endif %} - {% endfor %}" + value="{{ book['custom_column_' ~ c.id][0].value / 2 }}" {% endif %}> {% endif %}
diff --git a/cps/web.py b/cps/web.py index 27fb8713..9ac0441a 100755 --- a/cps/web.py +++ b/cps/web.py @@ -822,7 +822,8 @@ def edit_book(book_id): old_rating = False if len(book.ratings) > 0: old_rating = book.ratings[0].rating - ratingx2 = int(to_save["rating"]) *2 + ratingx2 = int(float(to_save["rating"]) *2) + print ratingx2 if ratingx2 != old_rating: is_rating = db.session.query(db.Ratings).filter(db.Ratings.rating == ratingx2).first() if is_rating: @@ -844,6 +845,9 @@ def edit_book(book_id): else: cc_db_value = None if to_save[cc_string].strip(): + if c.datatype == 'rating': + to_save[cc_string] = str(int(float(to_save[cc_string]) *2)) + print to_save[cc_string] if to_save[cc_string].strip() != cc_db_value: if cc_db_value != None: #remove old cc_val From b7f71e563e0033095bdf0a2e5b3cf3059b363aad Mon Sep 17 00:00:00 2001 From: Cervinko Cera Date: Thu, 21 Apr 2016 12:59:49 +0200 Subject: [PATCH 19/23] fix for custom column 'rating' --- cps/templates/detail.html | 6 +++++- cps/templates/edit_book.html | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cps/templates/detail.html b/cps/templates/detail.html index 5cf9d5e2..3fa85b52 100644 --- a/cps/templates/detail.html +++ b/cps/templates/detail.html @@ -66,7 +66,11 @@ {% if entry['custom_column_' ~ c.id]|length > 0 %} {{ c.name }}: {% for column in entry['custom_column_' ~ c.id] %} - {{ column.value }} + {% if c.datatype == 'rating' %} + {{ '%d' % (column.value / 2) }} + {% else %} + {{ '%d' % (column.value / 2) }} + {% endif %} {% endfor %}
{% endif %} diff --git a/cps/templates/edit_book.html b/cps/templates/edit_book.html index 7b74d7e2..b553db18 100644 --- a/cps/templates/edit_book.html +++ b/cps/templates/edit_book.html @@ -70,7 +70,7 @@ {% if c.datatype == 'rating' %} 0 %} - value="{{ book['custom_column_' ~ c.id][0].value / 2 }}" + value="{{ '%d' % (book['custom_column_' ~ c.id][0].value / 2) }}" {% endif %}> {% endif %} From 6359ab73a70c0fed8fc55a9fcec1d64f17759a2f Mon Sep 17 00:00:00 2001 From: Cervinko Cera Date: Thu, 21 Apr 2016 14:42:30 +0200 Subject: [PATCH 20/23] remove config.ini --- config.ini | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 config.ini diff --git a/config.ini b/config.ini deleted file mode 100644 index 8f265869..00000000 --- a/config.ini +++ /dev/null @@ -1,12 +0,0 @@ -[General] -DB_ROOT = /home/christoph/Calibre-Bibliothek_test -APP_DB_ROOT = /home/christoph/computer/calibre-web -MAIN_DIR = /home/christoph/computer/calibre-web -LOG_DIR = /home/christoph/computer/calibre-web -PORT = 8083 -NEWEST_BOOKS = 60 -[Advanced] -TITLE_REGEX = ^(A|The|An|Der|Die|Das|Den|Ein|Eine|Einen|Dem|Des|Einem|Eines)\s+ -DEVELOPMENT = 1 -PUBLIC_REG = 0 -UPLOADING = 1 From 3f1a54ea591ed9e340b2eb361e3111f7a100f05b Mon Sep 17 00:00:00 2001 From: Cervinko Cera Date: Thu, 21 Apr 2016 14:46:19 +0200 Subject: [PATCH 21/23] fix typo in detail.html --- cps/templates/detail.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cps/templates/detail.html b/cps/templates/detail.html index 3fa85b52..b6d5018b 100644 --- a/cps/templates/detail.html +++ b/cps/templates/detail.html @@ -69,7 +69,7 @@ {% if c.datatype == 'rating' %} {{ '%d' % (column.value / 2) }} {% else %} - {{ '%d' % (column.value / 2) }} + {{ column.value }} {% endif %} {% endfor %}
From b2146ba4b993df47bcdaca9bdc3a26df46d3bcf2 Mon Sep 17 00:00:00 2001 From: Cervinko Cera Date: Thu, 21 Apr 2016 19:18:52 +0200 Subject: [PATCH 22/23] add support for is_multiple custom columns --- cps/templates/edit_book.html | 12 +++-- cps/web.py | 94 +++++++++++++++++++++++++++--------- 2 files changed, 79 insertions(+), 27 deletions(-) diff --git a/cps/templates/edit_book.html b/cps/templates/edit_book.html index b553db18..2c7b8a37 100644 --- a/cps/templates/edit_book.html +++ b/cps/templates/edit_book.html @@ -47,11 +47,17 @@ {% for c in cc %}
- {% if c.datatype in ['text', 'series'] %} + {% if c.datatype in ['text', 'series'] and not c.is_multiple %} 0 %} - {% for column in book['custom_column_' ~ c.id] %} - value="{{ column.value }}{% if not loop.last %}, {% endif %}{% endfor %}"{% endif %}> + value="{{ book['custom_column_' ~ c.id][0].value }}" + {% endif %}> + {% endif %} + + {% if c.datatype in ['text', 'series'] and c.is_multiple %} + 0 %} + value="{% for column in book['custom_column_' ~ c.id] %}{{ column.value.strip() }}{% if not loop.last %}, {% endif %}{% endfor %}"{% endif %}> {% endif %} {% if c.datatype == 'enumeration' %} diff --git a/cps/web.py b/cps/web.py index 9ac0441a..05a94793 100755 --- a/cps/web.py +++ b/cps/web.py @@ -840,37 +840,83 @@ def edit_book(book_id): for c in cc: cc_string = "custom_column_" + str(c.id) - if len(getattr(book, cc_string)) > 0: - cc_db_value = getattr(book, cc_string)[0].value - else: - cc_db_value = None - if to_save[cc_string].strip(): - if c.datatype == 'rating': - to_save[cc_string] = str(int(float(to_save[cc_string]) *2)) - print to_save[cc_string] - if to_save[cc_string].strip() != cc_db_value: + if not c.is_multiple: + if len(getattr(book, cc_string)) > 0: + cc_db_value = getattr(book, cc_string)[0].value + else: + cc_db_value = None + if to_save[cc_string].strip(): + if c.datatype == 'rating': + to_save[cc_string] = str(int(float(to_save[cc_string]) *2)) + print to_save[cc_string] + if to_save[cc_string].strip() != cc_db_value: + if cc_db_value != None: + #remove old cc_val + del_cc = getattr(book, cc_string)[0] + getattr(book, cc_string).remove(del_cc) + if len(del_cc.books) == 0: + db.session.delete(del_cc) + cc_class = db.cc_classes[c.id] + new_cc = db.session.query(cc_class).filter(cc_class.value == to_save[cc_string].strip()).first() + # if no cc val is found add it + if new_cc == None: + new_cc = cc_class(value=to_save[cc_string].strip()) + db.session.add(new_cc) + new_cc = db.session.query(cc_class).filter(cc_class.value == to_save[cc_string].strip()).first() + # add cc value to book + getattr(book, cc_string).append(new_cc) + else: if cc_db_value != None: #remove old cc_val del_cc = getattr(book, cc_string)[0] getattr(book, cc_string).remove(del_cc) if len(del_cc.books) == 0: db.session.delete(del_cc) - cc_class = db.cc_classes[c.id] - new_cc = db.session.query(cc_class).filter(cc_class.value == to_save[cc_string].strip()).first() - # if no cc val is found add it - if new_cc == None: - new_cc = cc_class(value=to_save[cc_string].strip()) - db.session.add(new_cc) - new_cc = db.session.query(cc_class).filter(cc_class.value == to_save[cc_string].strip()).first() - # add cc value to book - getattr(book, cc_string).append(new_cc) else: - if cc_db_value != None: - #remove old cc_val - del_cc = getattr(book, cc_string)[0] - getattr(book, cc_string).remove(del_cc) - if len(del_cc.books) == 0: - db.session.delete(del_cc) + input_tags = to_save[cc_string].split(',') + input_tags = map(lambda it: it.strip(), input_tags) + input_tags = [x for x in input_tags if x != ''] + # we have all author names now + # 1. search for tags to remove + del_tags = [] + for c_tag in getattr(book, cc_string): + found = False + for inp_tag in input_tags: + if inp_tag == c_tag.value: + found = True + break; + # if the tag was not found in the new list, add him to remove list + if not found: + del_tags.append(c_tag) + # 2. search for tags that need to be added + add_tags = [] + for inp_tag in input_tags: + found = False + for c_tag in getattr(book, cc_string): + if inp_tag == c_tag.value: + found = True + break; + if not found: + add_tags.append(inp_tag) + # if there are tags to remove, we remove them now + if len(del_tags) > 0: + for del_tag in del_tags: + getattr(book, cc_string).remove(del_tag) + if len(del_tag.books) == 0: + db.session.delete(del_tag) + # if there are tags to add, we add them now! + if len(add_tags) > 0: + for add_tag in add_tags: + # check if a tag with that name exists + new_tag = db.session.query(db.cc_classes[c.id]).filter(db.cc_classes[c.id].value == add_tag).first() + # if no tag is found add it + if new_tag == None: + print add_tag + new_tag = db.cc_classes[c.id](value=add_tag) + db.session.add(new_tag) + new_tag = db.session.query(db.cc_classes[c.id]).filter(db.cc_classes[c.id].value == add_tag).first() + # add tag to book + getattr(book, cc_string).append(new_tag) db.session.commit() author_names = [] From 0e4574da911e9f277c17f5be1118f19c365bbb82 Mon Sep 17 00:00:00 2001 From: Cervinko Cera Date: Thu, 21 Apr 2016 20:55:08 +0200 Subject: [PATCH 23/23] revert config.ini --- config.ini | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 config.ini diff --git a/config.ini b/config.ini new file mode 100644 index 00000000..d35aa258 --- /dev/null +++ b/config.ini @@ -0,0 +1,12 @@ +[General] +DB_ROOT = +APP_DB_ROOT = +MAIN_DIR = +LOG_DIR = +PORT = 8083 +NEWEST_BOOKS = 60 +[Advanced] +TITLE_REGEX = ^(A|The|An|Der|Die|Das|Den|Ein|Eine|Einen|Dem|Des|Einem|Eines)\s+ +DEVELOPMENT = 0 +PUBLIC_REG = 0 +UPLOADING = 0