From 8745d65ff6bcc8d81302e803ad19345c1abf7bc9 Mon Sep 17 00:00:00 2001 From: Jack Darlington Date: Tue, 28 Feb 2017 23:53:32 +0000 Subject: [PATCH] Merging ignorable columns --- cps/templates/config_edit.html | 5 ++++- cps/ub.py | 9 ++++++++- cps/web.py | 13 ++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/cps/templates/config_edit.html b/cps/templates/config_edit.html index 9d107cb2..1a80dfc1 100644 --- a/cps/templates/config_edit.html +++ b/cps/templates/config_edit.html @@ -62,7 +62,10 @@ - +
+ + +
diff --git a/cps/ub.py b/cps/ub.py index aa064282..d9672b5e 100644 --- a/cps/ub.py +++ b/cps/ub.py @@ -275,6 +275,7 @@ class Settings(Base): config_google_drive_folder = Column(String) config_google_drive_calibre_url_base = Column(String) config_google_drive_watch_changes_response = Column(String) + config_columns_to_ignore = Column(String) def __repr__(self): pass @@ -310,7 +311,7 @@ class Config: self.config_google_drive_watch_changes_response = json.loads(data.config_google_drive_watch_changes_response) else: self.config_google_drive_watch_changes_response=None - + self.config_columns_to_ignore = data.config_columns_to_ignore if (self.config_calibre_dir is not None and not self.config_use_google_drive) or os.path.exists(self.config_calibre_dir + '/metadata.db'): self.db_configured = True else: @@ -406,6 +407,12 @@ def migrate_Database(): conn.execute("ALTER TABLE Settings ADD column `config_google_drive_calibre_url_base` INTEGER DEFAULT 0") conn.execute("ALTER TABLE Settings ADD column `config_google_drive_folder` String DEFAULT ''") conn.execute("ALTER TABLE Settings ADD column `config_google_drive_watch_changes_response` String DEFAULT ''") + try: + session.query(exists().where(Settings.config_columns_to_ignore)).scalar() + except exc.OperationalError: + conn = engine.connect() + conn.execute("ALTER TABLE Settings ADD column `config_columns_to_ignore` String DEFAULT ''") + session.commit() try: session.query(exists().where(Settings.config_default_role)).scalar() session.commit() diff --git a/cps/web.py b/cps/web.py index 6b7a329d..4e48dc4e 100755 --- a/cps/web.py +++ b/cps/web.py @@ -1124,7 +1124,16 @@ def show_book(id): except: entries.languages[index].language_name = _( isoLanguages.get(part3=entries.languages[index].lang_code).name) - cc = db.session.query(db.Custom_Columns).filter(db.Custom_Columns.datatype.notin_(db.cc_exceptions)).all() + tmpcc = db.session.query(db.Custom_Columns).filter(db.Custom_Columns.datatype.notin_(db.cc_exceptions)).all() + + if config.config_columns_to_ignore: + cc=[] + for col in tmpcc: + r= re.compile(config.config_columns_to_ignore) + if r.match(col.label): + c.append(col) + else: + cc=tmpcc book_in_shelfs = [] shelfs = ub.session.query(ub.BookShelf).filter(ub.BookShelf.book_id == id).all() for entry in shelfs: @@ -1964,6 +1973,8 @@ def configuration_helper(origin): reboot_required = True if "config_calibre_web_title" in to_save: content.config_calibre_web_title = to_save["config_calibre_web_title"] + if "config_columns_to_ignore" in to_save: + content.config_columns_to_ignore = to_save["config_columns_to_ignore"] if "config_title_regex" in to_save: if content.config_title_regex != to_save["config_title_regex"]: content.config_title_regex = to_save["config_title_regex"]