diff --git a/community/community/doctype/community_member/community_member.py b/community/community/doctype/community_member/community_member.py index 333771f0..dd7bed8b 100644 --- a/community/community/doctype/community_member/community_member.py +++ b/community/community/doctype/community_member/community_member.py @@ -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"" diff --git a/community/community/widgets/Avatar.html b/community/community/widgets/Avatar.html new file mode 100644 index 00000000..8158f3df --- /dev/null +++ b/community/community/widgets/Avatar.html @@ -0,0 +1,12 @@ +{% set color = member.get_palette() %} + + {% if member.photo %} + + + {% else %} + + {{ member.abbr }} + + {% endif %} + diff --git a/community/widgets.py b/community/widgets.py index b5475ecc..1e135187 100644 --- a/community/widgets.py +++ b/community/widgets.py @@ -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): diff --git a/community/www/courses/course.html b/community/www/courses/course.html index 43614eac..4b1cb29a 100644 --- a/community/www/courses/course.html +++ b/community/www/courses/course.html @@ -78,9 +78,7 @@ {% for m in batch.get_mentors() %}
- {% if m.photo_url %} - - {% endif %} + {{ widgets.Avatar(member=m, avatar_class="avatar-medium" ) }} {{m.full_name}}
{% endfor %}