canvaslms 5.4__py3-none-any.whl → 5.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- canvaslms/cli/modules.nw +22 -7
- canvaslms/cli/modules.py +19 -4
- canvaslms/cli/quizzes.nw +767 -31
- canvaslms/cli/quizzes.py +621 -25
- {canvaslms-5.4.dist-info → canvaslms-5.6.dist-info}/METADATA +1 -1
- {canvaslms-5.4.dist-info → canvaslms-5.6.dist-info}/RECORD +9 -9
- {canvaslms-5.4.dist-info → canvaslms-5.6.dist-info}/WHEEL +0 -0
- {canvaslms-5.4.dist-info → canvaslms-5.6.dist-info}/entry_points.txt +0 -0
- {canvaslms-5.4.dist-info → canvaslms-5.6.dist-info}/licenses/LICENSE +0 -0
canvaslms/cli/modules.nw
CHANGED
|
@@ -486,6 +486,14 @@ def get_item_modules(course, item_type, item_id):
|
|
|
486
486
|
Returns:
|
|
487
487
|
List of module names containing this item
|
|
488
488
|
"""
|
|
489
|
+
target_url = None
|
|
490
|
+
if item_type == 'Page':
|
|
491
|
+
try:
|
|
492
|
+
target_url = course.get_page(item_id).url
|
|
493
|
+
except Exception:
|
|
494
|
+
# If we can't resolve the target page, fall back to raw comparisons.
|
|
495
|
+
target_url = item_id
|
|
496
|
+
|
|
489
497
|
modules = []
|
|
490
498
|
for module in course.get_modules():
|
|
491
499
|
try:
|
|
@@ -514,10 +522,10 @@ elif item_type == 'Page':
|
|
|
514
522
|
if item.page_url == item_id:
|
|
515
523
|
modules.append(module.name)
|
|
516
524
|
break
|
|
517
|
-
#
|
|
525
|
+
# Compare canonical URLs to avoid duplicates when Canvas redirects old slugs.
|
|
518
526
|
try:
|
|
519
527
|
resolved_page = course.get_page(item.page_url)
|
|
520
|
-
if resolved_page.url ==
|
|
528
|
+
if resolved_page.url == target_url:
|
|
521
529
|
modules.append(module.name)
|
|
522
530
|
break
|
|
523
531
|
except Exception:
|
|
@@ -598,11 +606,18 @@ with its new canonical URL.
|
|
|
598
606
|
Without handling this, the direct comparison [[item.page_url == item_id]] would
|
|
599
607
|
fail, causing the page to be added to the module again (creating duplicates).
|
|
600
608
|
|
|
601
|
-
To detect this, we fetch
|
|
602
|
-
|
|
603
|
-
|
|
609
|
+
To detect this, we fetch both the target page ([[item_id]]) and the module
|
|
610
|
+
item's page ([[item.page_url]]) and compare canonical [[url]] values. This adds
|
|
611
|
+
API calls, but only when the direct comparison fails.
|
|
604
612
|
<<find current module item if present>>=
|
|
605
613
|
current_item = None
|
|
614
|
+
canonical_page_url = None
|
|
615
|
+
if item_type == 'Page':
|
|
616
|
+
try:
|
|
617
|
+
canonical_page_url = course.get_page(item_id).url
|
|
618
|
+
except Exception:
|
|
619
|
+
canonical_page_url = item_id
|
|
620
|
+
|
|
606
621
|
try:
|
|
607
622
|
for item in module.get_module_items():
|
|
608
623
|
if not hasattr(item, 'type') or item.type != item_type:
|
|
@@ -625,10 +640,10 @@ Canvas has created a redirect from an old URL to a new one.
|
|
|
625
640
|
if item.page_url == item_id:
|
|
626
641
|
current_item = item
|
|
627
642
|
break
|
|
628
|
-
# URLs don't match directly;
|
|
643
|
+
# URLs don't match directly; compare canonical URLs to avoid duplicates.
|
|
629
644
|
try:
|
|
630
645
|
resolved_page = course.get_page(item.page_url)
|
|
631
|
-
if resolved_page.url ==
|
|
646
|
+
if resolved_page.url == canonical_page_url:
|
|
632
647
|
current_item = item
|
|
633
648
|
break
|
|
634
649
|
except Exception:
|
canvaslms/cli/modules.py
CHANGED
|
@@ -198,6 +198,14 @@ def get_item_modules(course, item_type, item_id):
|
|
|
198
198
|
Returns:
|
|
199
199
|
List of module names containing this item
|
|
200
200
|
"""
|
|
201
|
+
target_url = None
|
|
202
|
+
if item_type == "Page":
|
|
203
|
+
try:
|
|
204
|
+
target_url = course.get_page(item_id).url
|
|
205
|
+
except Exception:
|
|
206
|
+
# If we can't resolve the target page, fall back to raw comparisons.
|
|
207
|
+
target_url = item_id
|
|
208
|
+
|
|
201
209
|
modules = []
|
|
202
210
|
for module in course.get_modules():
|
|
203
211
|
try:
|
|
@@ -213,10 +221,10 @@ def get_item_modules(course, item_type, item_id):
|
|
|
213
221
|
if item.page_url == item_id:
|
|
214
222
|
modules.append(module.name)
|
|
215
223
|
break
|
|
216
|
-
#
|
|
224
|
+
# Compare canonical URLs to avoid duplicates when Canvas redirects old slugs.
|
|
217
225
|
try:
|
|
218
226
|
resolved_page = course.get_page(item.page_url)
|
|
219
|
-
if resolved_page.url ==
|
|
227
|
+
if resolved_page.url == target_url:
|
|
220
228
|
modules.append(module.name)
|
|
221
229
|
break
|
|
222
230
|
except Exception:
|
|
@@ -254,6 +262,13 @@ def update_item_modules(course, item_type, item_id, module_regexes):
|
|
|
254
262
|
|
|
255
263
|
for module in all_modules:
|
|
256
264
|
current_item = None
|
|
265
|
+
canonical_page_url = None
|
|
266
|
+
if item_type == "Page":
|
|
267
|
+
try:
|
|
268
|
+
canonical_page_url = course.get_page(item_id).url
|
|
269
|
+
except Exception:
|
|
270
|
+
canonical_page_url = item_id
|
|
271
|
+
|
|
257
272
|
try:
|
|
258
273
|
for item in module.get_module_items():
|
|
259
274
|
if not hasattr(item, "type") or item.type != item_type:
|
|
@@ -267,10 +282,10 @@ def update_item_modules(course, item_type, item_id, module_regexes):
|
|
|
267
282
|
if item.page_url == item_id:
|
|
268
283
|
current_item = item
|
|
269
284
|
break
|
|
270
|
-
# URLs don't match directly;
|
|
285
|
+
# URLs don't match directly; compare canonical URLs to avoid duplicates.
|
|
271
286
|
try:
|
|
272
287
|
resolved_page = course.get_page(item.page_url)
|
|
273
|
-
if resolved_page.url ==
|
|
288
|
+
if resolved_page.url == canonical_page_url:
|
|
274
289
|
current_item = item
|
|
275
290
|
break
|
|
276
291
|
except Exception:
|