Added the ability to save sketches

Implemented by exposing an RPC method to save the sketch and calling
from JS using `frappe.call`. Any logged-in user can create new sketches
and the owner can edit his/her own sketches.
This commit is contained in:
Anand Chitipothu
2021-03-10 12:25:14 +00:00
parent 936a3fcfff
commit 406244ff69
4 changed files with 112 additions and 14 deletions

View File

@@ -5,6 +5,15 @@ def get_context(context):
course_name = get_queryparam("sketch", '/sketches')
context.sketch = get_sketch(course_name)
context.livecode_url = get_livecode_url()
context.editable = is_editable(context.sketch, frappe.sesson.user)
def is_editable(sketch, user):
if sketch.name == "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")
@@ -20,15 +29,13 @@ def get_queryparam(name, redirect_when_not_found):
def get_sketch(name):
if name == 'new':
sketch = frappe.new_doc('LMS Sketch')
sketch.name = "new"
sketch.title = "New Sketch"
sketch.code = "circle(100, 100, 50)"
sketch.owner = frappe.session.user.split("@")[0]
return sketch
try:
sketch = frappe.get_doc('LMS Sketch', name)
return frappe.get_doc('LMS Sketch', name)
except frappe.exceptions.DoesNotExistError:
raise frappe.NotFound
sketch.owner = sketch.owner.split("@")[0]
return sketch