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"): 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] 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 -