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
}

View File

@@ -20,7 +20,7 @@
<div class="sketch-preview mb-5">
<span class="sketch-ts">{{ sketch.modified }}</span>
<a href="/sketches/sketch?sketch={{sketch.name}}">{{sketch.title}}</a>
By {{sketch.owner}}
By {{sketch.owner_name}}
</div>
{% endfor %}
</div>

View File

@@ -1,16 +1,7 @@
import frappe
from ...lms.doctype.lms_sketch.lms_sketch import get_recent_sketches
def get_context(context):
context.no_cache = 1
context.sketches = get_sketches()
context.sketches = get_recent_sketches()
def get_sketches():
sketches = frappe.get_all(
"LMS Sketch",
fields=['name', 'title', 'owner', 'modified'],
order_by='modified desc',
page_length=100
)
for s in sketches:
s['owner'] = s['owner'].split("@")[0]
return sketches