Merge branch 'main' into course-page

This commit is contained in:
Anand Chitipothu
2021-05-06 13:50:12 +05:30
committed by GitHub
4 changed files with 35 additions and 4 deletions

View File

@@ -8,6 +8,8 @@ import re
from frappe import _
from frappe.model.document import Document
import random
from frappe.utils import cint
import hashlib
class CommunityMember(Document):
@@ -45,6 +47,24 @@ class CommunityMember(Document):
'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):
return f"<CommunityMember: {self.email}>"

View 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>

View File

@@ -14,7 +14,8 @@ from frappe.utils.jinja import get_jenv
# When {{widgets.SomeWidget()}} is called, it looks for
# widgets/SomeWidgets.html in each of these modules.
MODULES = [
"lms"
"lms",
"community"
]
def update_website_context(context):

View File

@@ -78,9 +78,7 @@
{% for m in batch.get_mentors() %}
<div>
{% if m.photo_url %}
<img class="profile-photo" src="{{m.photo_url}}">
{% endif %}
{{ widgets.Avatar(member=m, avatar_class="avatar-medium" ) }}
<span class="instructor-title">{{m.full_name}}</span>
</div>
{% endfor %}