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

@@ -3,8 +3,37 @@
# For license information, please see license.txt
from __future__ import unicode_literals
# import frappe
import frappe
from frappe.model.document import Document
class LMSSketch(Document):
pass
def get_owner_name(self):
return self.owner.split("@")[0]
@frappe.whitelist()
def save_sketch(name, title, code):
if not name or name == "new":
doc = frappe.new_doc('LMS Sketch')
doc.title = title
doc.code = code
doc.runtime = 'python-canvas'
doc.insert()
status = "created"
else:
doc = frappe.get_doc("LMS Sketch", name)
if doc.owner != frappe.session.user:
return {
"ok": False,
"error": "Permission Denied"
}
doc.title = title
doc.code = code
doc.save()
status = "updated"
return {
"ok": True,
"status": status,
"name": doc.name,
}