Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 650f95d

Browse files
committed
Fix: handle completion data requests for PreTeXt
1 parent a4795a3 commit 650f95d

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

bookserver/routers/rslogging.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
EVENT2TABLE,
4848
delete_one_user_topic_practice,
4949
fetch_last_page,
50+
fetch_chapter_for_subchapter,
5051
fetch_course,
5152
fetch_course_practice,
5253
fetch_one_user_topic_practice,
@@ -291,16 +292,30 @@ async def updatelastpage(
291292
# last_page_url is going to be .../ns/books/published/course/chapter/subchapter.html
292293
# We will treat the second to last element as the chapter and the final element
293294
# minus the .html as the subchapter
294-
# TODO: PreTeXt books will nothave this url format!
295295
parts = request_data.last_page_url.split("/")
296296
if len(parts) < 2:
297297
rslogger.error(f"Unparseable page: {request_data.last_page_url}")
298298
return make_json_response(
299299
status=status.HTTP_422_UNPROCESSABLE_ENTITY,
300300
detail=f"Unparseable page: {request_data.last_page_url}",
301301
)
302-
lpd["last_page_chapter"] = parts[-2]
303-
lpd["last_page_subchapter"] = ".".join(parts[-1].split(".")[:-1])
302+
303+
subchapter = ".".join(parts[-1].split(".")[:-1])
304+
# if it is a PreTeXt book then the subchapter is a unique id with the whole book
305+
# we can look it up from the chapter and subchapter tables.
306+
if request_data.is_ptx_book:
307+
course_row = await fetch_course(user.course_name)
308+
chapter = await fetch_chapter_for_subchapter(
309+
subchapter, course_row.base_course
310+
)
311+
rslogger.debug(
312+
f"Got Chapter {chapter} for {subchapter} in {course_row.base_course}"
313+
)
314+
lpd["last_page_chapter"] = chapter
315+
else:
316+
lpd["last_page_chapter"] = parts[-2]
317+
318+
lpd["last_page_subchapter"] = subchapter
304319
lpd["last_page_accessed_on"] = datetime.utcnow()
305320
lpd["user_id"] = request.state.user.id
306321

@@ -372,10 +387,17 @@ async def add_flashcard(
372387
# _getCompletionStatus
373388
# --------------------
374389
@router.get("/getCompletionStatus")
375-
async def getCompletionStatus(request: Request, lastPageUrl: str):
390+
async def getCompletionStatus(request: Request, lastPageUrl: str, isPtxBook: bool):
376391
if request.state.user:
377-
last_page_chapter = lastPageUrl.split("/")[-2]
378392
last_page_subchapter = ".".join(lastPageUrl.split("/")[-1].split(".")[:-1])
393+
if isPtxBook:
394+
rslogger.debug(f"completion status for PTX book {lastPageUrl}")
395+
course_row = await fetch_course(request.state.user.course_name)
396+
last_page_chapter = await fetch_chapter_for_subchapter(
397+
last_page_subchapter, course_row.base_course
398+
)
399+
else:
400+
last_page_chapter = lastPageUrl.split("/")[-2]
379401
result = await fetch_user_sub_chapter_progress(
380402
request.state.user, last_page_chapter, last_page_subchapter
381403
)

bookserver/schemas.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ class LastPageDataIncoming(BaseModelNone):
183183
course_id: str = Field(alias="course")
184184
completion_flag: int
185185
last_page_scroll_location: int
186+
is_ptx_book: bool
186187
# todo: this should really be an int
187188

188189
# We can automatically create the aliases!

0 commit comments

Comments
 (0)