Skip to content

Commit

Permalink
Merge pull request #66 from NatLibFi/feature/simplye-322/dynamic-facets
Browse files Browse the repository at this point in the history
Allow disabling dynamic facets
  • Loading branch information
attemoi authored Apr 25, 2024
2 parents 7199d77 + 4136656 commit aba44fc
Show file tree
Hide file tree
Showing 3 changed files with 27 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
1 change: 1 addition & 0 deletions tests/core/models/test_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def test_explain(self, db: DatabaseTransactionFixture):
facets_default_collection='full'
facets_enabled_language='['all', 'fin', 'swe', 'eng', 'others']'
facets_default_language='all'
facets_enabled_dynamic='['distributor', 'collectionName']'
help_web='http://library.com/support'
default_notification_email_address='[email protected]'
color_scheme='blue'
Expand Down

0 comments on commit aba44fc

Please sign in to comment.