Using the user fullname when rendering a sketch.

Also refactored the portal page for sketches and moved the common code
to the lms_sketch doctype module.
This commit is contained in:
Anand Chitipothu
2021-03-11 11:53:06 +00:00
parent 4fe91422f4
commit 5f8de7612b
3 changed files with 36 additions and 13 deletions

View File

@@ -8,7 +8,7 @@ from frappe.model.document import Document
class LMSSketch(Document):
def get_owner_name(self):
return self.owner.split("@")[0]
return get_userinfo(self.owner)['full_name']
@frappe.whitelist()
def save_sketch(name, title, code):
@@ -37,3 +37,35 @@ def save_sketch(name, title, code):
"name": doc.name,
}
def get_recent_sketches():
"""Returns the recent sketches.
The return value will be a list of dicts with each entry containing
the following fields:
- name
- title
- owner
- owner_name
- modified
"""
sketches = frappe.get_all(
"LMS Sketch",
fields=['name', 'title', 'owner', 'modified'],
order_by='modified desc',
page_length=100
)
for s in sketches:
s['owner_name'] = get_userinfo(s['owner'])['full_name']
return sketches
def get_userinfo(email):
"""Returns the username and fullname of a user.
Please note that the email could be "Administrator" or "Guest"
as a special case to denote the system admin and guest user respectively.
"""
user = frappe.get_doc("User", email)
return {
"full_name": user.full_name,
"username": user.username
}