diff --git a/.gitignore b/.gitignore index 0ce14757..f06dcd44 100644 --- a/.gitignore +++ b/.gitignore @@ -7,9 +7,11 @@ __pycache__/ # Distribution / packaging .Python env/ +venv/ eggs/ dist/ build/ +vendor/ .eggs/ *.egg-info/ .installed.cfg @@ -19,16 +21,12 @@ build/ # calibre-web *.db *.log -config.ini -cps/static/[0-9]* .idea/ *.bak *.log.* -tags settings.yaml gdrive_credentials - -vendor client_secrets.json + diff --git a/cps/admin.py b/cps/admin.py index 50e0589d..c7f790ae 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -144,7 +144,10 @@ def configuration(): def view_configuration(): readColumn = db.session.query(db.Custom_Columns)\ .filter(and_(db.Custom_Columns.datatype == 'bool',db.Custom_Columns.mark_for_delete == 0)).all() + restrictColumns= db.session.query(db.Custom_Columns)\ + .filter(and_(db.Custom_Columns.datatype == 'text',db.Custom_Columns.mark_for_delete == 0)).all() return render_title_template("config_view_edit.html", conf=config, readColumns=readColumn, + restrictColumns=restrictColumns, title=_(u"UI Configuration"), page="uiconfig") @@ -160,7 +163,7 @@ def update_view_configuration(): _config_string("config_calibre_web_title") _config_string("config_columns_to_ignore") - _config_string("config_mature_content_tags") + # _config_string("config_mature_content_tags") reboot_required |= _config_string("config_title_regex") _config_int("config_read_column") @@ -169,6 +172,10 @@ def update_view_configuration(): _config_int("config_books_per_page") _config_int("config_authors_max") + _config_string("config_restricted_tags") + _config_int("config_restricted_column") + _config_string("config_restricted_column_value") + if config.config_google_drive_watch_changes_response: config.config_google_drive_watch_changes_response = json.dumps(config.config_google_drive_watch_changes_response) @@ -176,8 +183,8 @@ def update_view_configuration(): config.config_default_role &= ~constants.ROLE_ANONYMOUS config.config_default_show = sum(int(k[5:]) for k in to_save if k.startswith('show_')) - if "Show_mature_content" in to_save: - config.config_default_show |= constants.MATURE_CONTENT + '''if "Show_mature_content" in to_save: + config.config_default_show |= constants.MATURE_CONTENT''' config.save() flash(_(u"Calibre-Web configuration updated"), category="success") @@ -448,7 +455,7 @@ def new_user(): if request.method == "POST": to_save = request.form.to_dict() content.default_language = to_save["default_language"] - content.mature_content = "Show_mature_content" in to_save + # content.mature_content = "Show_mature_content" in to_save content.locale = to_save.get("locale", content.locale) content.sidebar_view = sum(int(key[5:]) for key in to_save if key.startswith('show_')) @@ -490,7 +497,10 @@ def new_user(): else: content.role = config.config_default_role content.sidebar_view = config.config_default_show - content.mature_content = bool(config.config_default_show & constants.MATURE_CONTENT) + content.restricted_tags = config.config_restricted_tags + content.restricted_column = config.config_restricted_column + content.restricted_column_value = config.config_restricted_column_value + # content.mature_content = bool(config.config_default_show & constants.MATURE_CONTENT) return render_title_template("user_edit.html", new_user=1, content=content, translations=translations, languages=languages, title=_(u"Add new user"), page="newuser", registered_oauth=oauth_check) @@ -593,7 +603,13 @@ def edit_user(user_id): else: content.sidebar_view &= ~constants.DETAIL_RANDOM - content.mature_content = "Show_mature_content" in to_save + # content.mature_content = "Show_mature_content" in to_save + if "restricted_tags" in to_save: + content.restricted_tags = to_save["restricted_tags"] + if "config_restricted_column" in to_save: + content.restricted_tags = to_save["config_restricted_column"] + if "config_restricted_column_value" in to_save: + content.restricted_tags = to_save["config_restricted_column_value"] if "default_language" in to_save: content.default_language = to_save["default_language"] diff --git a/cps/config_sql.py b/cps/config_sql.py index 8ea8b978..cc1e09ec 100644 --- a/cps/config_sql.py +++ b/cps/config_sql.py @@ -57,7 +57,7 @@ class _Settings(_Base): config_authors_max = Column(Integer, default=0) config_read_column = Column(Integer, default=0) config_title_regex = Column(String, default=u'^(A|The|An|Der|Die|Das|Den|Ein|Eine|Einen|Dem|Des|Einem|Eines)\s+') - config_mature_content_tags = Column(String, default='') + # config_mature_content_tags = Column(String, default='') config_theme = Column(Integer, default=0) config_log_level = Column(SmallInteger, default=logger.DEFAULT_LOG_LEVEL) @@ -70,10 +70,13 @@ class _Settings(_Base): config_public_reg = Column(SmallInteger, default=0) config_remote_login = Column(Boolean, default=False) - config_default_role = Column(SmallInteger, default=0) config_default_show = Column(SmallInteger, default=6143) config_columns_to_ignore = Column(String) + config_restricted_tags = Column(String) + config_restricted_column = Column(SmallInteger, default=0) + config_restricted_column_value = Column(String) + config_allowed_column_value = Column(String) config_use_google_drive = Column(Boolean, default=False) config_google_drive_folder = Column(String) @@ -177,12 +180,12 @@ class _ConfigSQL(object): def show_detail_random(self): return self.show_element_new_user(constants.DETAIL_RANDOM) - def show_mature_content(self): - return self.show_element_new_user(constants.MATURE_CONTENT) + '''def show_mature_content(self): + return self.show_element_new_user(constants.MATURE_CONTENT)''' - def mature_content_tags(self): + '''def mature_content_tags(self): mct = self.config_mature_content_tags.split(",") - return [t.strip() for t in mct] + return [t.strip() for t in mct]''' def get_log_level(self): return logger.get_level_name(self.config_log_level) diff --git a/cps/helper.py b/cps/helper.py index e5e616d5..82322470 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -686,14 +686,36 @@ def common_filters(): lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language()) else: lang_filter = true() - content_rating_filter = false() if current_user.mature_content else \ - db.Books.tags.any(db.Tags.name.in_(config.mature_content_tags())) - return and_(lang_filter, ~content_rating_filter) + negtags_list = current_user.list_restricted_tags() + postags_list = current_user.list_allowed_tags() + neg_content_tags_filter = false() if negtags_list == [''] else db.Books.tags.any(db.Tags.name.in_(negtags_list)) + pos_content_tags_filter = true() if postags_list == [''] else db.Books.tags.any(db.Tags.name.in_(postags_list)) + # db.session.query(db.Books).filter(db.Books.custom_column_5.any(db.cc_classes[5].value == 'nikto')).first() + # db.session.query(db.Books).filter( + # getattr(db.Books, 'custom_column_' + str(5)).any(db.cc_classes[5].value == 'nikto').first()) + if config.config_restricted_column: + pos_cc_list = current_user.allowed_column_value.split(',') + pos_content_cc_filter = true() if pos_cc_list == [''] else \ + getattr(db.Books, 'custom_column_' + str(config.config_restricted_column)).\ + any(db.cc_classes[config.config_restricted_column].value.in_(pos_cc_list)) + neg_cc_list = current_user.restricted_column_value.split(',') + neg_content_cc_filter = true() if neg_cc_list == [''] else \ + getattr(db.Books, 'custom_column_' + str(config.config_restricted_column)).\ + any(db.cc_classes[config.config_restricted_column].value.in_(neg_cc_list)) + else: + pos_content_cc_filter = true() + neg_content_cc_filter = false() + return and_(lang_filter, pos_content_tags_filter, ~neg_content_tags_filter, + pos_content_cc_filter, ~neg_content_cc_filter) + def tags_filters(): - return ~(false() if current_user.mature_content else \ - db.Tags.name.in_(config.mature_content_tags())) - # return db.session.query(db.Tags).filter(~content_rating_filter).order_by(db.Tags.name).all() + negtags_list = current_user.list_restricted_tags() + postags_list = current_user.list_allowed_tags() + neg_content_tags_filter = false() if negtags_list == [''] else db.Tags.name.in_(negtags_list) + pos_content_tags_filter = true() if postags_list == [''] else db.Tags.name.in_(postags_list) + return and_(pos_content_tags_filter, ~neg_content_tags_filter) + # return ~(false()) if postags_list == [''] else db.Tags.in_(postags_list) # Creates for all stored languages a translated speaking name in the array for the UI diff --git a/cps/templates/config_edit.html b/cps/templates/config_edit.html index 9556eef4..311d4a16 100644 --- a/cps/templates/config_edit.html +++ b/cps/templates/config_edit.html @@ -71,7 +71,7 @@ - + {% if show_back_button %}