From fc1c393f15e038eda5f68d70e9c44d9d25e91576 Mon Sep 17 00:00:00 2001 From: Anand Chitipothu Date: Tue, 22 Jun 2021 18:09:21 +0530 Subject: [PATCH 1/4] feat: allow a student to be mentor of another batch This is a requirement for mon.school. The students are of the first batch are now mentors of new batches. --- .../lms_batch_membership.py | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/community/lms/doctype/lms_batch_membership/lms_batch_membership.py b/community/lms/doctype/lms_batch_membership/lms_batch_membership.py index 5dd33f09..5e975ce0 100644 --- a/community/lms/doctype/lms_batch_membership/lms_batch_membership.py +++ b/community/lms/doctype/lms_batch_membership/lms_batch_membership.py @@ -32,20 +32,28 @@ class LMSBatchMembership(Document): frappe.throw(_("{0} is already a {1} of the course {2}").format(member_name, previous_membership.member_type, course_title)) def validate_membership_in_different_batch_same_course(self): - course = frappe.db.get_value("LMS Batch", self.batch, "course") - previous_membership = frappe.get_all("LMS Batch Membership", - filters={ - "member": self.member, - "name": ["!=", self.name] - }, - fields=["batch", "member_type", "name"] - ) + """Ensures that a studnet is only part of one batch. + """ + # nothing to worry if the member is not a student + if self.member_type != "Student": + return - for membership in previous_membership: - batch_course = frappe.db.get_value("LMS Batch", membership.batch, "course") - if batch_course == course and (membership.member_type == "Student" or self.member_type == "Student"): - member_name = frappe.db.get_value("User", self.member, "full_name") - frappe.throw(_("{0} is already a {1} of {2} course through {3} batch").format(member_name, membership.member_type, course, membership.batch)) + course = frappe.db.get_value("LMS Batch", self.batch, "course") + memberships = frappe.get_all( + "LMS Batch Membership", + filters={ + "member": self.member, + "name": ["!=", self.name], + "member_type": "Student", + "course": self.course + }, + fields=["batch", "member_type", "name"] + ) + + if memberships: + membership = memberships[0] + member_name = frappe.db.get_value("User", self.member, "full_name") + frappe.throw(_("{0} is already a Student of {1} course through {2} batch").format(member_name, course, membership.batch)) @frappe.whitelist() def create_membership(course, batch=None, member=None, member_type="Student", role="Member"): From f303be4db5ff69c4975ae38ab6655ccf525eb103 Mon Sep 17 00:00:00 2001 From: Anand Chitipothu Date: Tue, 22 Jun 2021 18:12:31 +0530 Subject: [PATCH 2/4] fix: error in find_macros when the input is empty Added a special case to handle this issue. --- community/lms/md.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/community/lms/md.py b/community/lms/md.py index b256eb72..0658ca82 100644 --- a/community/lms/md.py +++ b/community/lms/md.py @@ -36,6 +36,8 @@ def find_macros(text): ('Exercise', 'four-circles') ] """ + if not text: + return [] macros = re.findall(MACRO_RE, text) # remove the quotes around the argument return [(name, _remove_quotes(arg)) for name, arg in macros] From 20b3ae7d768eeaa9ba2553fb3176ba66d68448d2 Mon Sep 17 00:00:00 2001 From: Anand Chitipothu Date: Wed, 23 Jun 2021 10:27:01 +0530 Subject: [PATCH 3/4] fix: error in linking lessons on course page The course was adding `{{ no such element: community.lms.doctype.lms_course.lms_course.LMSCourse object['query_parameter'] }}` to the lesson links. Fixed it by setting query_parameter to "". --- community/www/courses/course.py | 1 + 1 file changed, 1 insertion(+) diff --git a/community/www/courses/course.py b/community/www/courses/course.py index 3bc2f50f..eda11084 100644 --- a/community/www/courses/course.py +++ b/community/www/courses/course.py @@ -16,6 +16,7 @@ def get_context(context): raise frappe.Redirect context.course = course + context.course.query_parameter = "" if not course.is_mentor(frappe.session.user): batch = course.get_membership(frappe.session.user) if batch: From 9f50af4ebdf867102852708d0517d9c649b8202d Mon Sep 17 00:00:00 2001 From: Anand Chitipothu Date: Sat, 12 Jun 2021 21:42:57 +0530 Subject: [PATCH 4/4] refactor: removed the portal pages for showing sketches Moved them to mon_school. --- community/www/sketches/index.html | 28 -------- community/www/sketches/index.py | 7 -- community/www/sketches/sketch.html | 112 ----------------------------- community/www/sketches/sketch.py | 46 ------------ 4 files changed, 193 deletions(-) delete mode 100644 community/www/sketches/index.html delete mode 100644 community/www/sketches/index.py delete mode 100644 community/www/sketches/sketch.html delete mode 100644 community/www/sketches/sketch.py diff --git a/community/www/sketches/index.html b/community/www/sketches/index.html deleted file mode 100644 index 074a8d1c..00000000 --- a/community/www/sketches/index.html +++ /dev/null @@ -1,28 +0,0 @@ -{% extends "templates/base.html" %} -{% from "www/macros/livecode.html" import LiveCodeEditor, LiveCodeEditorJS %} - -{% block title %}Sketches{% endblock %} -{% block head_include %} - - - -{% endblock %} - -{% block content %} -
-
-

Recent Sketches

- - Create a New Sketch -
-
-
- {% for sketch in sketches %} -
- {{ widgets.SketchTeaser(sketch=sketch) }} -
- {% endfor %} -
-
-
-{% endblock %} diff --git a/community/www/sketches/index.py b/community/www/sketches/index.py deleted file mode 100644 index 88bcd47e..00000000 --- a/community/www/sketches/index.py +++ /dev/null @@ -1,7 +0,0 @@ -import frappe -from community.lms.models import Sketch - -def get_context(context): - context.no_cache = 1 - context.sketches = Sketch.get_recent_sketches() - diff --git a/community/www/sketches/sketch.html b/community/www/sketches/sketch.html deleted file mode 100644 index 44191b78..00000000 --- a/community/www/sketches/sketch.html +++ /dev/null @@ -1,112 +0,0 @@ -{% extends "templates/base.html" %} -{% from "www/macros/livecode.html" import LiveCodeEditorLarge, LiveCodeEditorJS with context %} - -{% block title %}{{sketch.title}}{% endblock %} -{% block head_include %} - - - - - - - - - - - - - -{% endblock %} - -{% block content %} -
-
- - -
- {% if editable %} -
-
- -
-
- -
-
- {% else %} -

{{sketch.title}}

-
By {{sketch.get_owner_name()}}
- {% endif %} -
- - {% if sketch.is_new() and not editable %} -
- Please login to save this sketch. -
- {% endif %} - -
- {{LiveCodeEditorLarge(sketch.name, sketch.code) }} -
-{% endblock %} - -{%- block script %} - {{ super() }} - {{ LiveCodeEditorJS() }} - - -{%- endblock %} - diff --git a/community/www/sketches/sketch.py b/community/www/sketches/sketch.py deleted file mode 100644 index ef88d7a0..00000000 --- a/community/www/sketches/sketch.py +++ /dev/null @@ -1,46 +0,0 @@ -import frappe - -def get_context(context): - context.no_cache = 1 - - try: - sketch_id = frappe.form_dict["sketch"] - except KeyError: - context.template = "www/404.html" - return - - sketch = get_sketch(sketch_id) - if not sketch: - context.template = "www/404.html" - return - - context.sketch = sketch - context.livecode_url = get_livecode_url() - context.editable = is_editable(context.sketch, frappe.session.user) - -def is_editable(sketch, user): - if sketch.is_new(): - # new sketches can be editable by any logged in user - return user != "Guest" - else: - # existing sketches are editable by the owner - return sketch.owner == user - -def get_livecode_url(): - doc = frappe.get_doc("LMS Settings") - return doc.livecode_url - -def get_sketch(sketch_id): - if sketch_id == 'new': - sketch = frappe.new_doc('LMS Sketch') - sketch.name = "new" - sketch.title = "New Sketch" - sketch.code = "circle(100, 100, 50)" - return sketch - - try: - name = "SKETCH-" + sketch_id - return frappe.get_doc('LMS Sketch', name) - except frappe.exceptions.DoesNotExistError: - return -