-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PP-1509] Add support for default facet #2142
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2142 +/- ##
=======================================
Coverage 90.78% 90.78%
=======================================
Files 350 350
Lines 40608 40691 +83
Branches 8796 8822 +26
=======================================
+ Hits 36864 36940 +76
- Misses 2439 2441 +2
- Partials 1305 1310 +5 ☔ View full report in Codecov by Sentry. |
292d66b
to
8ff807c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few comments to look at before this one goes in.
Can you also update the PR with a small example of what these links look like in the different feed versions?
# TODO: When we remove the facet-based sort links [PP-1814], | ||
# this code path will be removed and we'll want to pull the sort | ||
# link data from the feed.sort_links once that is in place. | ||
link_data["links"].append(self._serialize_sort_link(link)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this TODO
get relocated rather then removed?
serialized.append(link) | ||
|
||
for link in self._serialize_sort_links(feed.facet_links): | ||
serialized.append(link) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like it would be good to have a test that covers this line, to make sure we are getting the expected sort links in the OPDS1Version2 feed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still doesn't look like there is any coverage here?
@jonathangreen : thanks for the review. All your suggests look reasonable to me. I'll update the PR today. |
e03180c
to
a23686b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple more comments here that would be nice to get resolved before merging @dbernstein.
class OPDS1Serializer(SerializerInterface[etree._Element], OPDSFeed): | ||
"""An OPDS 1.2 Atom feed serializer""" | ||
|
||
class BaseOPDS1Serializer(SerializerInterface[etree._Element], OPDSFeed): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You also need to inherent from ABC in order to make this an abstract base class.
@@ -79,7 +84,7 @@ def _tag( | |||
|
|||
def _attr_name(self, attr_name: str, mapping: dict[str, str] | None = None) -> str: | |||
if not mapping: | |||
mapping = ATTRIBUTE_MAPPING | |||
mapping = V1_ATTRIBUTE_MAPPING |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we defined _get_attribute_mapping
, shouldn't this be calling that function?
serialized.append(link) | ||
|
||
for link in self._serialize_sort_links(feed.facet_links): | ||
serialized.append(link) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still doesn't look like there is any coverage here?
value if value is not None else "", | ||
) | ||
return entry | ||
|
||
@abc.abstractmethod | ||
def _get_attribute_mapping(self) -> dict[str, str]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Since subclasses are expected to implement these, its would be nice to have a doc comment with a small bit of explanation of what an implementation should provide for this function.
@@ -405,13 +413,95 @@ def _serialize_data_entry(self, entry: DataEntry) -> etree._Element: | |||
def to_string(cls, element: etree._Element) -> str: | |||
return cast(str, etree.tostring(element, encoding="unicode")) | |||
|
|||
@abc.abstractmethod | |||
def content_type(self) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Since subclasses are expected to implement these, its would be nice to have a doc comment with a small bit of explanation of what an implementation should provide for this function.
pass | ||
|
||
@abc.abstractmethod | ||
def _serialize_facet_links(self, feed: FeedData) -> list[Link]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Since subclasses are expected to implement these, its would be nice to have a doc comment with a small bit of explanation of what an implementation should provide for this function.
pass | ||
|
||
@abc.abstractmethod | ||
def _serialize_sort_links(self, feed: FeedData) -> list[Link]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Since subclasses are expected to implement these, its would be nice to have a doc comment with a small bit of explanation of what an implementation should provide for this function.
# select only the sort facets for serialization | ||
if is_sort_facet(link): | ||
links.append(self._serialize_sort_link(link)) | ||
return links | ||
|
||
def _serialize_sort_link(self, link: Link) -> etree._Element: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We aren't using the @override
decorator anywhere else in the codebase currently. I think if we're going to apply it in these classes we should apply it consistently, so it should get added to this method as well.
tests/manager/feed/test_opds_base.py
Outdated
], | ||
) | ||
def test_get_serializer1(self, accept_header: str, serializer): | ||
# The q-value should take priority |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Seems like this comment is outdated.
( | ||
OPDS2Serializer.CONTENT_TYPE, | ||
OPDS2Serializer.CONTENT_TYPE, | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
( | |
OPDS2Serializer.CONTENT_TYPE, | |
OPDS2Serializer.CONTENT_TYPE, | |
), | |
(OPDS2Serializer.CONTENT_TYPE, OPDS2Serializer.CONTENT_TYPE), |
Minor: This change seems unnecessary. Its nice to have these be consistent, instead of having this one entry on multiple lines.
…when retrieving opds1 and opds2 client feeds.
…mat. Move support for sort links to OPD1Version2 and OPDS2Version2.
…erty on the sort and facet relations in OPDS1V2 and OPDS2V2 feeds.
2bce84e
to
dfa6472
Compare
Description
With this update, the "default" facet or sort link will have a http://palaceproject.io/terms/properties/default property to indicate that it is a default property. This default property will be present in both OPDS1 and OPDS2 feeds. However in order to see them, clients must specify an api-version of 2 in the mimetype.
For OPDS 1:
application/atom+xml;api-version=2
For OPDS 2:
application/opds+json;api-version=2
Otherwise version 1 of both formats will be delivered. Version 1 is what is currently deployed in production.
Here is an update to the documentation that covers these updates.
I do have an open question about whether or not a default facet that happens to be active should have an "activeFacet" or "active-sort" set to true.
Motivation and Context
https://ebce-lyrasis.atlassian.net/browse/PP-1506
How Has This Been Tested?
Checklist