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:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user