otterden-lms-interface 0.7.3__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.
@@ -0,0 +1,13 @@
1
+ try:
2
+ from importlib.metadata import PackageNotFoundError, version
3
+ except Exception: # pragma: no cover - fallback for older Python
4
+ PackageNotFoundError = Exception # type: ignore
5
+ version = None # type: ignore
6
+
7
+ if "__version__" not in globals():
8
+ try:
9
+ if version is None:
10
+ raise PackageNotFoundError
11
+ __version__ = version("lms-interface")
12
+ except PackageNotFoundError:
13
+ __version__ = "vendored"
@@ -0,0 +1,95 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+
5
+ from .canvas_interface import CanvasAssignment, CanvasCourse, CanvasInterface
6
+ from .interfaces import LMSAssignment, LMSBackend, LMSCourse, RubricAssessment
7
+
8
+
9
+ class CanvasBackend(LMSBackend):
10
+ def __init__(
11
+ self,
12
+ *,
13
+ prod: bool = False,
14
+ env_path: str | None = None,
15
+ canvas_url: str | None = None,
16
+ canvas_key: str | None = None,
17
+ privacy_mode: str | None = None,
18
+ reveal_identity: bool = False,
19
+ blind_id_map_path: str | None = None
20
+ ):
21
+ self._interface = CanvasInterface(
22
+ prod=prod,
23
+ env_path=env_path,
24
+ canvas_url=canvas_url,
25
+ canvas_key=canvas_key,
26
+ privacy_mode=privacy_mode,
27
+ reveal_identity=reveal_identity,
28
+ blind_id_map_path=blind_id_map_path
29
+ )
30
+
31
+ def get_course(self, course_id: int) -> LMSCourse:
32
+ return CanvasCourseAdapter(self._interface.get_course(course_id))
33
+
34
+
35
+ @dataclass
36
+ class CanvasCourseAdapter(LMSCourse):
37
+ _course: CanvasCourse
38
+
39
+ @property
40
+ def id(self):
41
+ return self._course.course.id
42
+
43
+ @property
44
+ def name(self):
45
+ return getattr(self._course.course, "name", None)
46
+
47
+ def get_assignment(self, assignment_id: int) -> LMSAssignment | None:
48
+ assignment = self._course.get_assignment(assignment_id)
49
+ if assignment is None:
50
+ return None
51
+ return CanvasAssignmentAdapter(assignment)
52
+
53
+ def get_assignments(self, **kwargs) -> list[LMSAssignment]:
54
+ return [CanvasAssignmentAdapter(a) for a in self._course.get_assignments(**kwargs)]
55
+
56
+ def get_students(self):
57
+ return self._course.get_students()
58
+
59
+
60
+ @dataclass
61
+ class CanvasAssignmentAdapter(LMSAssignment):
62
+ _assignment: CanvasAssignment
63
+
64
+ @property
65
+ def id(self):
66
+ return self._assignment.assignment.id
67
+
68
+ @property
69
+ def name(self):
70
+ return getattr(self._assignment.assignment, "name", None)
71
+
72
+ def get_submissions(self, **kwargs):
73
+ return self._assignment.get_submissions(**kwargs)
74
+
75
+ def push_feedback(
76
+ self,
77
+ user_id,
78
+ score: float | None,
79
+ comments: str,
80
+ attachments=None,
81
+ keep_previous_best: bool = True,
82
+ clobber_feedback: bool = False,
83
+ seconds_late: int | None = None,
84
+ rubric_assessment: RubricAssessment | None = None,
85
+ ) -> bool | None:
86
+ return self._assignment.push_feedback(
87
+ user_id=user_id,
88
+ score=score,
89
+ comments=comments,
90
+ attachments=attachments,
91
+ keep_previous_best=keep_previous_best,
92
+ clobber_feedback=clobber_feedback,
93
+ seconds_late=seconds_late,
94
+ rubric_assessment=rubric_assessment,
95
+ )