From 2ae32f10c4e8d068fd429195a798c2b06bee749e Mon Sep 17 00:00:00 2001 From: Atte Moisio Date: Thu, 25 Apr 2024 14:32:45 +0300 Subject: [PATCH] Allow disabling dynamic facets Add a new setting for the default library which allows hiding the dynamic "Collection Name" and "Distributor" facets from OPDS feeds. --- core/configuration/library.py | 16 ++++++++++++++++ core/model/library.py | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/core/configuration/library.py b/core/configuration/library.py index d36f44e7c..125a37c46 100644 --- a/core/configuration/library.py +++ b/core/configuration/library.py @@ -380,6 +380,22 @@ class LibrarySettings(BaseSettings): default_library_only=True, ), ) + facets_enabled_dynamic: list[str] = FormField( + list(FacetConstants.FACET_DISPLAY_TITLES_DYNAMIC.keys()), + form=LibraryConfFormItem( + label="Allow patrons to filter by dynamic facets", + type=ConfigurationFormItemType.MENU, + options={ + facet: FacetConstants.GROUP_DISPLAY_TITLES[facet] + for facet in FacetConstants.FACET_DISPLAY_TITLES_DYNAMIC.keys() + }, + category="Lanes & Filters", + read_only=True, + format="narrow", + level=Level.SYS_ADMIN_ONLY, + default_library_only=True, + ), + ) library_description: str | None = FormField( None, form=LibraryConfFormItem( diff --git a/core/model/library.py b/core/model/library.py index 209c6ee4d..b5ad84179 100644 --- a/core/model/library.py +++ b/core/model/library.py @@ -369,6 +369,10 @@ def entrypoints(self) -> Generator[type[EntryPoint] | None, None, None]: def enabled_facets(self, group_name: str) -> list[str]: """Look up the enabled facets for a given facet group.""" + + if self.is_facet_dynamic_and_disabled(group_name): + return [] + if group_name == FacetConstants.DISTRIBUTOR_FACETS_GROUP_NAME: enabled = [] for collection in self.collections: @@ -385,6 +389,12 @@ def enabled_facets(self, group_name: str) -> list[str]: return getattr(self.settings, f"facets_enabled_{group_name}") # type: ignore[no-any-return] + def is_facet_dynamic_and_disabled(self, facet_group_name: str) -> bool: + return ( + facet_group_name in FacetConstants.FACET_DISPLAY_TITLES_DYNAMIC + and not facet_group_name in self.settings.facets_enabled_dynamic + ) + @property def has_root_lanes(self) -> bool: """Does this library have any lanes that act as the root