Merge branch 'main' into course-page
This commit is contained in:
@@ -8,6 +8,8 @@ import re
|
|||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
import random
|
import random
|
||||||
|
from frappe.utils import cint
|
||||||
|
import hashlib
|
||||||
|
|
||||||
class CommunityMember(Document):
|
class CommunityMember(Document):
|
||||||
|
|
||||||
@@ -45,6 +47,24 @@ class CommunityMember(Document):
|
|||||||
'member_type': 'Mentor'
|
'member_type': 'Mentor'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def get_palette(self):
|
||||||
|
palette = [
|
||||||
|
['--orange-avatar-bg', '--orange-avatar-color'],
|
||||||
|
['--pink-avatar-bg', '--pink-avatar-color'],
|
||||||
|
['--blue-avatar-bg', '--blue-avatar-color'],
|
||||||
|
['--green-avatar-bg', '--green-avatar-color'],
|
||||||
|
['--dark-green-avatar-bg', '--dark-green-avatar-color'],
|
||||||
|
['--red-avatar-bg', '--red-avatar-color'],
|
||||||
|
['--yellow-avatar-bg', '--yellow-avatar-color'],
|
||||||
|
['--purple-avatar-bg', '--purple-avatar-color'],
|
||||||
|
['--gray-avatar-bg', '--gray-avatar-color0']
|
||||||
|
]
|
||||||
|
|
||||||
|
encoded_name = str(self.full_name).encode("utf-8")
|
||||||
|
hash_name = hashlib.md5(encoded_name).hexdigest()
|
||||||
|
idx = cint((int(hash_name[4:6], 16) + 1) / 5.33)
|
||||||
|
return palette[idx % 8]
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<CommunityMember: {self.email}>"
|
return f"<CommunityMember: {self.email}>"
|
||||||
|
|
||||||
|
|||||||
12
community/community/widgets/Avatar.html
Normal file
12
community/community/widgets/Avatar.html
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{% set color = member.get_palette() %}
|
||||||
|
<span class="avatar {{ avatar_class }}" title="{{ member.full_name }}">
|
||||||
|
{% if member.photo %}
|
||||||
|
<img class="avatar-frame standard-image" src="{{ member.photo }}" title="{{ member.full_name }}">
|
||||||
|
</img>
|
||||||
|
{% else %}
|
||||||
|
<span class="avatar-frame standard-image" title="{{ member.full_name }}"
|
||||||
|
style="background-color: var({{color[0]}}); color: var({{color[1]}});">
|
||||||
|
{{ member.abbr }}
|
||||||
|
</span>
|
||||||
|
{% endif %}
|
||||||
|
</span>
|
||||||
@@ -14,7 +14,8 @@ from frappe.utils.jinja import get_jenv
|
|||||||
# When {{widgets.SomeWidget()}} is called, it looks for
|
# When {{widgets.SomeWidget()}} is called, it looks for
|
||||||
# widgets/SomeWidgets.html in each of these modules.
|
# widgets/SomeWidgets.html in each of these modules.
|
||||||
MODULES = [
|
MODULES = [
|
||||||
"lms"
|
"lms",
|
||||||
|
"community"
|
||||||
]
|
]
|
||||||
|
|
||||||
def update_website_context(context):
|
def update_website_context(context):
|
||||||
|
|||||||
@@ -78,9 +78,7 @@
|
|||||||
|
|
||||||
{% for m in batch.get_mentors() %}
|
{% for m in batch.get_mentors() %}
|
||||||
<div>
|
<div>
|
||||||
{% if m.photo_url %}
|
{{ widgets.Avatar(member=m, avatar_class="avatar-medium" ) }}
|
||||||
<img class="profile-photo" src="{{m.photo_url}}">
|
|
||||||
{% endif %}
|
|
||||||
<span class="instructor-title">{{m.full_name}}</span>
|
<span class="instructor-title">{{m.full_name}}</span>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
Reference in New Issue
Block a user