|
9 | 9 | from frappe.model.document import Document |
10 | 10 | from frappe.utils import cint, today |
11 | 11 |
|
12 | | -from lms.lms.utils import get_chapters |
13 | | - |
14 | 12 | from ...utils import generate_slug, update_payment_record, validate_image |
15 | 13 |
|
16 | 14 |
|
@@ -133,58 +131,3 @@ def autoname(self): |
133 | 131 |
|
134 | 132 | def __repr__(self): |
135 | 133 | return f"<Course#{self.name}>" |
136 | | - |
137 | | - def has_mentor(self, email): |
138 | | - """Checks if this course has a mentor with given email.""" |
139 | | - if not email or email == "Guest": |
140 | | - return False |
141 | | - |
142 | | - mapping = frappe.get_all("LMS Course Mentor Mapping", {"course": self.name, "mentor": email}) |
143 | | - return mapping != [] |
144 | | - |
145 | | - def add_mentor(self, email): |
146 | | - """Adds a new mentor to the course.""" |
147 | | - if not email: |
148 | | - raise ValueError("Invalid email") |
149 | | - if email == "Guest": |
150 | | - raise ValueError("Guest user can not be added as a mentor") |
151 | | - |
152 | | - # given user is already a mentor |
153 | | - if self.has_mentor(email): |
154 | | - return |
155 | | - |
156 | | - doc = frappe.get_doc({"doctype": "LMS Course Mentor Mapping", "course": self.name, "mentor": email}) |
157 | | - doc.insert() |
158 | | - |
159 | | - def get_cohorts(self): |
160 | | - return frappe.get_all( |
161 | | - "Cohort", |
162 | | - {"course": self.name}, |
163 | | - ["name", "slug", "title", "begin_date", "end_date"], |
164 | | - order_by="creation", |
165 | | - ) |
166 | | - |
167 | | - def get_cohort(self, cohort_slug): |
168 | | - name = frappe.get_value("Cohort", {"course": self.name, "slug": cohort_slug}) |
169 | | - return name and frappe.get_doc("Cohort", name) |
170 | | - |
171 | | - def reindex_exercises(self): |
172 | | - for i, c in enumerate(get_chapters(self.name), start=1): |
173 | | - self._reindex_exercises_in_chapter(c, i) |
174 | | - |
175 | | - def _reindex_exercises_in_chapter(self, c, index): |
176 | | - i = 1 |
177 | | - for lesson in self.get_lessons(c): |
178 | | - for exercise in lesson.get_exercises(): |
179 | | - exercise.index_ = i |
180 | | - exercise.index_label = f"{index}.{i}" |
181 | | - exercise.save() |
182 | | - i += 1 |
183 | | - |
184 | | - |
185 | | -@frappe.whitelist() |
186 | | -def reindex_exercises(doc): |
187 | | - course_data = json.loads(doc) |
188 | | - course = frappe.get_doc("LMS Course", course_data["name"]) |
189 | | - course.reindex_exercises() |
190 | | - frappe.msgprint("All exercises in this course have been re-indexed.") |
0 commit comments