Skip to content

Commit

Permalink
Allow disabling dynamic facets
Browse files Browse the repository at this point in the history
Add a new setting for the default library which allows hiding
the dynamic "Collection Name" and "Distributor" facets from OPDS
feeds.
  • Loading branch information
attemoi committed Apr 25, 2024
1 parent 7199d77 commit 2ae32f1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions core/configuration/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 10 additions & 0 deletions core/model/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit 2ae32f1

Please sign in to comment.