|
47 | 47 | EVENT2TABLE, |
48 | 48 | delete_one_user_topic_practice, |
49 | 49 | fetch_last_page, |
| 50 | + fetch_chapter_for_subchapter, |
50 | 51 | fetch_course, |
51 | 52 | fetch_course_practice, |
52 | 53 | fetch_one_user_topic_practice, |
@@ -291,16 +292,30 @@ async def updatelastpage( |
291 | 292 | # last_page_url is going to be .../ns/books/published/course/chapter/subchapter.html |
292 | 293 | # We will treat the second to last element as the chapter and the final element |
293 | 294 | # minus the .html as the subchapter |
294 | | - # TODO: PreTeXt books will nothave this url format! |
295 | 295 | parts = request_data.last_page_url.split("/") |
296 | 296 | if len(parts) < 2: |
297 | 297 | rslogger.error(f"Unparseable page: {request_data.last_page_url}") |
298 | 298 | return make_json_response( |
299 | 299 | status=status.HTTP_422_UNPROCESSABLE_ENTITY, |
300 | 300 | detail=f"Unparseable page: {request_data.last_page_url}", |
301 | 301 | ) |
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 |
304 | 319 | lpd["last_page_accessed_on"] = datetime.utcnow() |
305 | 320 | lpd["user_id"] = request.state.user.id |
306 | 321 |
|
@@ -372,10 +387,17 @@ async def add_flashcard( |
372 | 387 | # _getCompletionStatus |
373 | 388 | # -------------------- |
374 | 389 | @router.get("/getCompletionStatus") |
375 | | -async def getCompletionStatus(request: Request, lastPageUrl: str): |
| 390 | +async def getCompletionStatus(request: Request, lastPageUrl: str, isPtxBook: bool): |
376 | 391 | if request.state.user: |
377 | | - last_page_chapter = lastPageUrl.split("/")[-2] |
378 | 392 | 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] |
379 | 401 | result = await fetch_user_sub_chapter_progress( |
380 | 402 | request.state.user, last_page_chapter, last_page_subchapter |
381 | 403 | ) |
|
0 commit comments