Skip to content

Commit

Permalink
Merge branch 'main' into chore/update-sqlalchemy-types
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathangreen authored Dec 4, 2024
2 parents 0d48d10 + e7ae364 commit 8c6add1
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 374 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Remove unsafe characters summary
Revision ID: c3458e1ef9aa
Revises: 272da5f400de
Create Date: 2024-11-27 20:32:41.431147+00:00
"""

from alembic import op

# revision identifiers, used by Alembic.
revision = "c3458e1ef9aa"
down_revision = "272da5f400de"
branch_labels = None
depends_on = None


def upgrade() -> None:
# Remove any characters that are not XML safe from the summary_text field. The code has been
# updated to filter out these characters, but this cleans up any existing data.
# https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-POSIX-REGEXP
op.execute(
"UPDATE works SET summary_text = regexp_replace("
" summary_text, '[^\u0020-\uD7FF\u0009\u000A\u000D\uE000-\uFFFD\U00010000-\U0010FFFF]+', '', 'g'"
") WHERE "
"summary_text ~ '[^\u0020-\uD7FF\u0009\u000A\u000D\uE000-\uFFFD\U00010000-\U0010FFFF]'"
)


def downgrade() -> None:
# No need to do anything on downgrade.
pass
12 changes: 6 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/palace/manager/api/controller/opds_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
SearchFacets,
WorkList,
)
from palace.manager.util.flask_util import OPDSFeedResponse
from palace.manager.util.problem_detail import ProblemDetail


Expand Down Expand Up @@ -243,7 +244,7 @@ def crawlable_list_feed(self, list_name):

def _crawlable_feed(
self, title, url, worklist, annotator=None, feed_class=OPDSAcquisitionFeed
):
) -> OPDSFeedResponse | ProblemDetail:
"""Helper method to create a crawlable feed.
:param title: The title to use for the feed.
Expand All @@ -270,6 +271,8 @@ def _crawlable_feed(
worklist=worklist,
base_class=CrawlableFacets,
)
if isinstance(facets, ProblemDetail):
return facets
annotator = annotator or self.manager.annotator(worklist, facets=facets)

return feed_class.page(
Expand Down
4 changes: 0 additions & 4 deletions src/palace/manager/api/lanes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,6 @@ def overview_facets(self, _db, facets):
# the best recommendations are in the front.
return Facets.default(
self.get_library(_db),
collection=facets.COLLECTION_FULL,
availability=facets.AVAILABLE_ALL,
entrypoint=facets.entrypoint,
)
Expand Down Expand Up @@ -1157,7 +1156,6 @@ def overview_facets(self, _db, facets):
"""
return SeriesFacets.default(
self.get_library(_db),
collection=facets.COLLECTION_FULL,
availability=facets.AVAILABLE_ALL,
entrypoint=facets.entrypoint,
)
Expand Down Expand Up @@ -1225,7 +1223,6 @@ def overview_facets(self, _db, facets):
"""
return ContributorFacets.default(
self.get_library(_db),
collection=facets.COLLECTION_FULL,
availability=facets.AVAILABLE_ALL,
entrypoint=facets.entrypoint,
)
Expand Down Expand Up @@ -1354,7 +1351,6 @@ class CrawlableFacets(Facets):
SETTINGS = {
Facets.ORDER_FACET_GROUP_NAME: Facets.ORDER_LAST_UPDATE,
Facets.AVAILABILITY_FACET_GROUP_NAME: Facets.AVAILABLE_ALL,
Facets.COLLECTION_FACET_GROUP_NAME: Facets.COLLECTION_FULL,
Facets.DISTRIBUTOR_FACETS_GROUP_NAME: Facets.DISTRIBUTOR_ALL,
Facets.COLLECTION_NAME_FACETS_GROUP_NAME: Facets.COLLECTION_NAME_ALL,
}
Expand Down
16 changes: 0 additions & 16 deletions src/palace/manager/core/facets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ class FacetConstants:
ENTRY_POINT_REL = "http://librarysimplified.org/terms/rel/entrypoint"
ENTRY_POINT_FACET_GROUP_NAME = "entrypoint"

# Subset the collection, roughly, by quality.
COLLECTION_FACET_GROUP_NAME = "collection"
COLLECTION_FULL = "full"
COLLECTION_FEATURED = "featured"
COLLECTION_FACETS = [
COLLECTION_FULL,
COLLECTION_FEATURED,
]

# Subset the collection by availability.
AVAILABILITY_FACET_GROUP_NAME = "available"
AVAILABLE_NOW = "now"
Expand Down Expand Up @@ -63,23 +54,20 @@ class FacetConstants:
COLLECTION_NAME_ALL = "All"

FACETS_BY_GROUP = {
COLLECTION_FACET_GROUP_NAME: COLLECTION_FACETS,
AVAILABILITY_FACET_GROUP_NAME: AVAILABILITY_FACETS,
ORDER_FACET_GROUP_NAME: ORDER_FACETS,
}

GROUP_DISPLAY_TITLES = {
ORDER_FACET_GROUP_NAME: _("Sort by"),
AVAILABILITY_FACET_GROUP_NAME: _("Availability"),
COLLECTION_FACET_GROUP_NAME: _("Collection"),
DISTRIBUTOR_FACETS_GROUP_NAME: _("Distributor"),
COLLECTION_NAME_FACETS_GROUP_NAME: _("Collection Name"),
}

GROUP_DESCRIPTIONS = {
ORDER_FACET_GROUP_NAME: _("Allow patrons to sort by"),
AVAILABILITY_FACET_GROUP_NAME: _("Allow patrons to filter availability to"),
COLLECTION_FACET_GROUP_NAME: _("Allow patrons to filter collection to"),
DISTRIBUTOR_FACETS_GROUP_NAME: _("Allow patrons to filter by distributor"),
COLLECTION_NAME_FACETS_GROUP_NAME: _(
"Allow patrons to filter by collection name"
Expand All @@ -96,8 +84,6 @@ class FacetConstants:
AVAILABLE_NOW: _("Available now"),
AVAILABLE_ALL: _("All"),
AVAILABLE_OPEN_ACCESS: _("Yours to keep"),
COLLECTION_FULL: _("Everything"),
COLLECTION_FEATURED: _("Popular Books"),
}

# For titles generated based on some runtime value
Expand All @@ -115,7 +101,6 @@ class FacetConstants:
AVAILABLE_NOW,
AVAILABLE_OPEN_ACCESS,
],
COLLECTION_FACET_GROUP_NAME: [COLLECTION_FULL, COLLECTION_FEATURED],
DISTRIBUTOR_FACETS_GROUP_NAME: [DISTRIBUTOR_ALL],
COLLECTION_NAME_FACETS_GROUP_NAME: [COLLECTION_NAME_ALL],
}
Expand All @@ -125,7 +110,6 @@ class FacetConstants:
DEFAULT_FACET = {
ORDER_FACET_GROUP_NAME: ORDER_AUTHOR,
AVAILABILITY_FACET_GROUP_NAME: AVAILABLE_ALL,
COLLECTION_FACET_GROUP_NAME: COLLECTION_FULL,
DISTRIBUTOR_FACETS_GROUP_NAME: DISTRIBUTOR_ALL,
COLLECTION_NAME_FACETS_GROUP_NAME: COLLECTION_NAME_ALL,
}
Expand Down
30 changes: 1 addition & 29 deletions src/palace/manager/integration/configuration/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,35 +234,7 @@ class LibrarySettings(BaseSettings):
skip=True,
),
)
facets_enabled_collection: list[str] = FormField(
FacetConstants.DEFAULT_ENABLED_FACETS[
FacetConstants.COLLECTION_FACET_GROUP_NAME
],
form=LibraryConfFormItem(
label="Allow patrons to filter collection to",
type=ConfigurationFormItemType.MENU,
options={
facet: FacetConstants.FACET_DISPLAY_TITLES[facet]
for facet in FacetConstants.COLLECTION_FACETS
},
category="Lanes & Filters",
paired="facets_default_collection",
level=Level.SYS_ADMIN_OR_MANAGER,
),
)
facets_default_collection: str = FormField(
FacetConstants.COLLECTION_FULL,
form=LibraryConfFormItem(
label="Default Collection",
type=ConfigurationFormItemType.SELECT,
options={
facet: FacetConstants.FACET_DISPLAY_TITLES[facet]
for facet in FacetConstants.COLLECTION_FACETS
},
category="Lanes & Filters",
skip=True,
),
)

library_description: str | None = FormField(
None,
form=LibraryConfFormItem(
Expand Down
8 changes: 0 additions & 8 deletions src/palace/manager/search/external_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -1829,14 +1829,6 @@ def build(self, _chain_filters=None):
Bool(must=[not_open_access, licensed, not_available])
)

if self.subcollection == FacetConstants.COLLECTION_FEATURED:
# Exclude books with a quality of less than the library's
# minimum featured quality.
range_query = self._match_range(
"quality", "gte", self.minimum_featured_quality
)
f = chain(f, Bool(must=range_query))

if self.identifiers:
# Check every identifier for a match.
clauses = []
Expand Down
Loading

0 comments on commit 8c6add1

Please sign in to comment.