Skip to content

Commit

Permalink
PP-149 Refactor Acquisition feeds and Annotators (#1308)
Browse files Browse the repository at this point in the history
* OPDS 1.2 and 2.0 refactor

With an acquisition page feed
This aims to remove all XML directives from within the feed and annotator workflows
And also to simplify the workflow making it more linear and less circular
Only a Serializer should write XML to the feed

Serializers are picked up the the basis of the Accept header sent to the endpoint.
Currently only the /feed, /group and /loans endpoints react to the Accept headers, the rest are still OPDS 1.2
  • Loading branch information
RishiDiwanTT authored Sep 15, 2023
1 parent 4cfb3be commit 202a1ab
Show file tree
Hide file tree
Showing 44 changed files with 9,684 additions and 149 deletions.
12 changes: 5 additions & 7 deletions api/admin/controller/custom_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from api.controller import CirculationManagerController
from api.problem_details import CANNOT_DELETE_SHARED_LIST
from core.app_server import load_pagination_from_request
from core.feed.acquisition import OPDSAcquisitionFeed
from core.lane import Lane, WorkList
from core.model import (
Collection,
Expand All @@ -36,10 +37,8 @@
create,
get_one,
)
from core.opds import AcquisitionFeed
from core.problem_details import INVALID_INPUT, METHOD_NOT_ALLOWED
from core.query.customlist import CustomListQueries
from core.util.flask_util import OPDSFeedResponse
from core.util.problem_detail import ProblemDetail


Expand Down Expand Up @@ -351,12 +350,11 @@ def custom_list(

annotator = self.manager.annotator(worklist)
url_fn = self.url_for_custom_list(library, list)
feed = AcquisitionFeed.from_query(
query, self._db, list.name, url, pagination, url_fn, annotator
feed = OPDSAcquisitionFeed.from_query(
query, self._db, list.name or "", url, pagination, url_fn, annotator
)
annotator.annotate_feed(feed, worklist)

return OPDSFeedResponse(str(feed), max_age=0)
annotator.annotate_feed(feed)
return feed.as_response(max_age=0)

elif flask.request.method == "POST":
ctx: Context = flask.request.context.body # type: ignore
Expand Down
8 changes: 5 additions & 3 deletions api/admin/controller/work_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
from flask_babel import lazy_gettext as _
from PIL import Image, ImageDraw, ImageFont

from api.admin.opds import AdminAnnotator
from api.admin.problem_details import *
from api.admin.validator import Validator
from core.classifier import NO_NUMBER, NO_VALUE, SimplifiedGenreClassifier, genres
from core.feed.acquisition import OPDSAcquisitionFeed
from core.feed.annotator.admin import AdminAnnotator
from core.lane import Lane
from core.metadata_layer import LinkData, Metadata, ReplacementPolicy
from core.mirror import MirrorUploader
Expand All @@ -37,7 +38,6 @@
get_one_or_create,
)
from core.model.configuration import ExternalIntegrationLink
from core.opds import AcquisitionFeed
from core.util import LanguageCodes
from core.util.datetime_helpers import strptime_utc, utc_now
from core.util.problem_detail import ProblemDetail
Expand Down Expand Up @@ -68,7 +68,9 @@ def details(self, identifier_type, identifier):
# single_entry returns an OPDSEntryResponse that will not be
# cached, which is perfect. We want the admin interface
# to update immediately when an admin makes a change.
return AcquisitionFeed.single_entry(self._db, work, annotator)
return OPDSAcquisitionFeed.entry_as_response(
OPDSAcquisitionFeed.single_entry(work, annotator)
)

def roles(self):
"""Return a mapping from MARC codes to contributor roles."""
Expand Down
2 changes: 1 addition & 1 deletion api/annotations.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import json
import os

from flask import url_for
from pyld import jsonld

from core.app_server import url_for
from core.model import Annotation, Identifier
from core.util.datetime_helpers import utc_now

Expand Down
5 changes: 0 additions & 5 deletions api/circulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1354,11 +1354,6 @@ def enforce_limits(self, patron: Patron, pool: LicensePool) -> None:
if api is not None:
api.update_availability(pool)

if pool.licenses_available is None:
# We don't know how many licenses are available, so we
# can't tell whether the patron is at their limit.
self.log.warning(f"License pool {pool} has unknown availability.")
return
currently_available = pool.licenses_available > 0
if currently_available and at_loan_limit:
raise PatronLoanLimitReached(limit=patron.library.settings.loan_limit)
Expand Down
Loading

0 comments on commit 202a1ab

Please sign in to comment.