Skip to content

Commit

Permalink
WIP - Forward chapter/page range from VitalSource assignment URLs to …
Browse files Browse the repository at this point in the history
…client
  • Loading branch information
robertknight committed Nov 13, 2023
1 parent 898ffe8 commit 088307a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lms/resources/_js_config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import functools
from enum import Enum
from typing import Any, Dict, List, Optional
from urllib.parse import parse_qs, urlparse

from pyramid.httpexceptions import HTTPClientError

Expand Down Expand Up @@ -112,6 +113,26 @@ def add_document_url(self, document_url):
document_url=document_url
)

# If this assignment was configured with a chapter and/or page
# range, pass that on to the client.
parsed_url = urlparse(document_url)
query = parse_qs(parsed_url.query)

location_params = {
# query param => Hypothesis client config key
"start_page": "startPage",
"end_page": "endPage",
"end_chapter": "endChapter",
}

for (param, config_property) in location_params.items():
if param in query:
val = query[param][-1]
content_range = self._hypothesis_client.setdefault(
"contentRange", {}
)
content_range[config_property] = val

elif jstor_service.enabled and document_url.startswith("jstor://"):
self._config["viaUrl"] = jstor_service.via_url(self._request, document_url)
self._config["contentBanner"] = {
Expand Down

0 comments on commit 088307a

Please sign in to comment.