diff --git a/community/community/doctype/community_event_volunteer/community_event_volunteer.json b/community/community/doctype/community_event_volunteer/community_event_volunteer.json index ff60d161..8c6f2d3d 100644 --- a/community/community/doctype/community_event_volunteer/community_event_volunteer.json +++ b/community/community/doctype/community_event_volunteer/community_event_volunteer.json @@ -13,13 +13,13 @@ "fieldtype": "Link", "in_list_view": 1, "label": "Member", - "options": "Community Member" + "options": "User" } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-02-15 12:03:31.153575", + "modified": "2021-05-21 12:15:51.286478", "modified_by": "Administrator", "module": "Community", "name": "Community Event Volunteer", diff --git a/community/community/doctype/community_member/__init__.py b/community/community/doctype/community_member/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/community/community/doctype/community_member/community_member.js b/community/community/doctype/community_member/community_member.js deleted file mode 100644 index e22285e5..00000000 --- a/community/community/doctype/community_member/community_member.js +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) 2021, Frappe and contributors -// For license information, please see license.txt - -frappe.ui.form.on('Community Member', { - // refresh: function(frm) { - - // } -}); diff --git a/community/community/doctype/community_member/community_member.json b/community/community/doctype/community_member/community_member.json deleted file mode 100644 index 5047e257..00000000 --- a/community/community/doctype/community_member/community_member.json +++ /dev/null @@ -1,155 +0,0 @@ -{ - "actions": [], - "allow_guest_to_view": 1, - "allow_rename": 1, - "creation": "2021-02-12 15:47:23.591567", - "doctype": "DocType", - "editable_grid": 1, - "engine": "InnoDB", - "field_order": [ - "full_name", - "email", - "enabled", - "column_break_4", - "username", - "email_preference", - "section_break_7", - "bio", - "section_break_9", - "role", - "photo", - "column_break_12", - "short_intro", - "route", - "abbr" - ], - "fields": [ - { - "default": "1", - "fieldname": "enabled", - "fieldtype": "Check", - "label": "Enabled" - }, - { - "fieldname": "full_name", - "fieldtype": "Data", - "in_list_view": 1, - "in_standard_filter": 1, - "label": "Full Name", - "reqd": 1 - }, - { - "allow_in_quick_entry": 1, - "fieldname": "role", - "fieldtype": "Select", - "label": "Role", - "options": "\nBoard\nDirector\nVolunteer\nSpeaker" - }, - { - "allow_in_quick_entry": 1, - "fieldname": "photo", - "fieldtype": "Attach Image", - "label": "Photo" - }, - { - "fieldname": "short_intro", - "fieldtype": "Data", - "label": "Short Intro" - }, - { - "allow_in_quick_entry": 1, - "fieldname": "bio", - "fieldtype": "Markdown Editor", - "label": "Bio" - }, - { - "fieldname": "route", - "fieldtype": "Data", - "label": "Route" - }, - { - "fieldname": "email", - "fieldtype": "Data", - "in_standard_filter": 1, - "label": "Email", - "options": "Email", - "reqd": 1, - "unique": 1 - }, - { - "allow_in_quick_entry": 1, - "fieldname": "username", - "fieldtype": "Data", - "in_list_view": 1, - "label": "User Name", - "unique": 1 - }, - { - "fieldname": "email_preference", - "fieldtype": "Select", - "label": "Email preference", - "options": "Email on every Message\nOne Digest Mail per day\nNever" - }, - { - "fieldname": "column_break_4", - "fieldtype": "Column Break" - }, - { - "fieldname": "section_break_7", - "fieldtype": "Section Break" - }, - { - "fieldname": "section_break_9", - "fieldtype": "Section Break" - }, - { - "fieldname": "column_break_12", - "fieldtype": "Column Break" - }, - { - "fieldname": "abbr", - "fieldtype": "Data", - "label": "Abbr", - "read_only": 1 - } - ], - "index_web_pages_for_search": 1, - "links": [], - "modified": "2021-04-28 11:22:35.402217", - "modified_by": "Administrator", - "module": "Community", - "name": "Community Member", - "owner": "Administrator", - "permissions": [ - { - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "print": 1, - "read": 1, - "report": 1, - "role": "System Manager", - "share": 1, - "write": 1 - }, - { - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "print": 1, - "read": 1, - "report": 1, - "role": "Website Manager", - "share": 1, - "write": 1 - } - ], - "quick_entry": 1, - "search_fields": "full_name", - "sort_field": "modified", - "sort_order": "DESC", - "title_field": "full_name", - "track_changes": 1 -} \ No newline at end of file diff --git a/community/community/doctype/community_member/community_member.py b/community/community/doctype/community_member/community_member.py deleted file mode 100644 index 0c1ecdb3..00000000 --- a/community/community/doctype/community_member/community_member.py +++ /dev/null @@ -1,104 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (c) 2021, Frappe and contributors -# For license information, please see license.txt - -from __future__ import unicode_literals -import frappe -import re -from frappe import _ -from frappe.model.document import Document -import random -from frappe.utils import cint -import hashlib - -class CommunityMember(Document): - - def validate(self): - self.validate_username() - self.abbr = ("").join([ s[0] for s in self.full_name.split() ]) - if self.route != self.username: - self.route = self.username - - def validate_username(self): - if not self.username: - self.username = create_username_from_email(self.email) - - if self.username: - if len(self.username) < 4: - frappe.throw(_("Username must be atleast 4 characters long.")) - if not re.match("^[A-Za-z0-9_]*$", self.username): - frappe.throw(_("Username can only contain alphabets, numbers and underscore.")) - self.username = self.username.lower() - - def get_course_count(self) -> int: - """Returns the number of courses authored by this user. - """ - return frappe.db.count( - 'LMS Course', { - 'owner': self.email - }) - - def get_batch_count(self) -> int: - """Returns the number of batches authored by this user. - """ - return frappe.db.count( - 'LMS Batch Membership', { - 'member': self.name, - 'member_type': 'Mentor' - }) - - def get_photo_url(self): - return frappe.db.get_value("User", self.email, ["user_image"]) - - 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"" - -def create_member_from_user(doc, method): - username = doc.username - - if ( doc.username and username_exists(doc.username)) or not doc.username: - username = create_username_from_email(doc.email) - - elif len(doc.username) < 4 and doc.send_welcome_email == 1: - username = adjust_username(doc.username) - - if username_exists(username): - username = username + str(random.randint(0,9)) - - member = frappe.get_doc({ - "doctype": "Community Member", - "full_name": doc.full_name, - "username": username, - "email": doc.email, - "route": doc.username, - "owner": doc.email - }) - member.save(ignore_permissions=True) - -def username_exists(username): - return frappe.db.exists("Community Member", dict(username=username)) - -def create_username_from_email(email): - string = email.split("@")[0] - return ''.join(e for e in string if e.isalnum()) - -def adjust_username(username): - return username.ljust(4, str(random.randint(0,9))) diff --git a/community/community/doctype/community_member/templates/community_member.html b/community/community/doctype/community_member/templates/community_member.html deleted file mode 100644 index fabec4d2..00000000 --- a/community/community/doctype/community_member/templates/community_member.html +++ /dev/null @@ -1,25 +0,0 @@ -{% extends "templates/web.html" %} -{% block page_content %} -
- {% if photo %} -
- {{ full_name }} -
- {% else %} -
-
{{ abbr }}
-
- {% endif %} -
-

{{ full_name }}

- {% if short_intro %} -

{{ short_intro }}

- {% endif %} - {% if bio %} -

{{ frappe.utils.md_to_html(bio) }}

- {% endif %} -
-
-{% endblock %} - - \ No newline at end of file diff --git a/community/community/doctype/community_member/templates/community_member_row.html b/community/community/doctype/community_member/templates/community_member_row.html deleted file mode 100644 index d7014b45..00000000 --- a/community/community/doctype/community_member/templates/community_member_row.html +++ /dev/null @@ -1,4 +0,0 @@ -
- {{ doc.title or doc.name }} -
- diff --git a/community/community/doctype/community_member/test_community_member.py b/community/community/doctype/community_member/test_community_member.py deleted file mode 100644 index 4cde095c..00000000 --- a/community/community/doctype/community_member/test_community_member.py +++ /dev/null @@ -1,92 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (c) 2021, Frappe and Contributors -# See license.txt -from __future__ import unicode_literals -from community.lms.doctype.lms_course.test_lms_course import new_user -import frappe -import unittest - -class TestCommunityMember(unittest.TestCase): - - @classmethod - def setUpClass(self): - users = ["test_user@example.com","test_user1@example.com"] - - for user in users: - if not frappe.db.exists("User", user): - new_user("Test User", user) - - def test_member_created_from_user(self): - user = frappe.db.get_value("User","test_user@example.com", ["full_name", "email", "username"], as_dict=True) - self.assertTrue(frappe.db.exists("Community Member", {"username":user.username})) - - member = frappe.db.get_value("Community Member", - filters={"email": user.email}, - fieldname=["full_name", "email", "owner", "username", "route"], - as_dict=True - ) - - self.assertEqual(user.full_name, member.full_name) - self.assertEqual(member.owner, user.email) - self.assertEqual(user.username, member.username) - self.assertEqual(member.username, member.route) - - def test_members_with_same_name(self): - user1 = frappe.db.get_value("User","test_user@example.com", ["email"], as_dict=True) - user2 = frappe.get_doc("User","test_user1@example.com", ["email"], as_dict=True) - - self.assertTrue(frappe.db.exists("Community Member", {"email": user1.email} )) - self.assertTrue(frappe.db.exists("Community Member", {"email": user2.email })) - - member1 = frappe.db.get_value("Community Member", - filters={"email": user1.email}, - fieldname=["full_name", "email", "owner", "username", "route"], - as_dict=True - ) - member2 = frappe.db.get_value("Community Member", - filters={"email": user2.email}, - fieldname=["full_name", "email", "owner", "username", "route"], - as_dict=True - ) - - self.assertEqual(member1.full_name, member2.full_name) - self.assertEqual(member1.email, user1.email) - self.assertEqual(member2.email, user2.email) - self.assertNotEqual(member1.username, member2.username) - - def test_username_validations(self): - user = new_user("Tst", "tst@example.com") - self.assertTrue(frappe.db.exists("Community Member", {"email":user.email} )) - - member = frappe.db.get_value("Community Member", - filters={"email": user.email}, - fieldname=["username"], - as_dict=True - ) - - self.assertEqual(len(member.username), 4) - frappe.delete_doc("User", user.email) - - def test_user_without_username(self): - user = new_user("Test User", "test_user2@example.com") - self.assertTrue(frappe.db.exists("Community Member", {"email":user.email} )) - - member = frappe.db.get_value("Community Member", - filters={"email": user.email}, - fieldname=["username"], - as_dict=True - ) - - self.assertTrue(member.username) - frappe.delete_doc("User", user.email) - - @classmethod - def tearDownClass(self): - users = ["test_user@example.com","test_user1@example.com"] - - for user in users: - if frappe.db.exists("User", user): - frappe.delete_doc("User", user) - - if frappe.db.exists("Community Member", {"email": user}): - frappe.delete_doc("Community Member", {"email": user}) \ No newline at end of file diff --git a/community/community/utils.py b/community/community/utils.py index ccc3ad48..cf189e48 100644 --- a/community/community/utils.py +++ b/community/community/utils.py @@ -1,16 +1 @@ import frappe - -def create_members_from_users(): - users = frappe.get_all("User", {"enabled": 1}, ["email"]) - for user in users: - if not frappe.db.get_value("Community Member", {"email": user.email}, "name"): - doc = frappe.get_doc("User", {"email": user.email}) - username = doc.username if doc.username and len(doc.username) > 3 else ("").join([ s for s in doc.full_name.split() ]) - if not frappe.db.exists("Community Member", username): - member = frappe.new_doc("Community Member") - member.full_name = doc.full_name - member.username = username - member.email = doc.email - member.route = username - member.owner = doc.email - member.insert(ignore_permissions=True) \ No newline at end of file diff --git a/community/community/web_form/update_profile/__init__.py b/community/community/web_form/update_profile/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/community/community/web_form/update_profile/update_profile.js b/community/community/web_form/update_profile/update_profile.js deleted file mode 100644 index b62f9465..00000000 --- a/community/community/web_form/update_profile/update_profile.js +++ /dev/null @@ -1,5 +0,0 @@ -frappe.ready(function() { - frappe.web_form.after_save = () => { - window.location.href = frappe.web_form.get_value("username") - } -}) \ No newline at end of file diff --git a/community/community/web_form/update_profile/update_profile.json b/community/community/web_form/update_profile/update_profile.json deleted file mode 100644 index 6b693e6b..00000000 --- a/community/community/web_form/update_profile/update_profile.json +++ /dev/null @@ -1,100 +0,0 @@ -{ - "accept_payment": 0, - "allow_comments": 0, - "allow_delete": 0, - "allow_edit": 1, - "allow_incomplete": 0, - "allow_multiple": 0, - "allow_print": 0, - "amount": 0.0, - "amount_based_on_field": 0, - "apply_document_permissions": 0, - "breadcrumbs": "", - "button_label": "Save", - "creation": "2021-03-09 17:34:03.394301", - "doc_type": "Community Member", - "docstatus": 0, - "doctype": "Web Form", - "idx": 0, - "is_standard": 1, - "login_required": 1, - "max_attachment_size": 0, - "modified": "2021-03-22 12:04:22.571655", - "modified_by": "Administrator", - "module": "Community", - "name": "update-profile", - "owner": "Administrator", - "payment_button_label": "Buy Now", - "published": 1, - "route": "edit-profile", - "route_to_success_link": 0, - "show_attachments": 0, - "show_in_grid": 0, - "show_sidebar": 0, - "sidebar_items": [], - "success_message": "Profile updated successfully.", - "success_url": "/", - "title": "Update Profile", - "web_form_fields": [ - { - "allow_read_on_all_link_options": 0, - "fieldname": "full_name", - "fieldtype": "Data", - "hidden": 0, - "label": "Full Name", - "max_length": 0, - "max_value": 0, - "read_only": 0, - "reqd": 1, - "show_in_filter": 0 - }, - { - "allow_read_on_all_link_options": 0, - "fieldname": "username", - "fieldtype": "Data", - "hidden": 0, - "label": "User Name", - "max_length": 0, - "max_value": 0, - "read_only": 0, - "reqd": 1, - "show_in_filter": 0 - }, - { - "allow_read_on_all_link_options": 0, - "fieldname": "short_intro", - "fieldtype": "Data", - "hidden": 0, - "label": "Short Intro", - "max_length": 0, - "max_value": 0, - "read_only": 0, - "reqd": 0, - "show_in_filter": 0 - }, - { - "allow_read_on_all_link_options": 0, - "fieldname": "bio", - "fieldtype": "Data", - "hidden": 0, - "label": "Bio", - "max_length": 0, - "max_value": 0, - "read_only": 0, - "reqd": 0, - "show_in_filter": 0 - }, - { - "allow_read_on_all_link_options": 0, - "fieldname": "photo", - "fieldtype": "Attach Image", - "hidden": 0, - "label": "Photo", - "max_length": 0, - "max_value": 0, - "read_only": 0, - "reqd": 0, - "show_in_filter": 0 - } - ] -} \ No newline at end of file diff --git a/community/community/web_form/update_profile/update_profile.py b/community/community/web_form/update_profile/update_profile.py deleted file mode 100644 index 2334f8b2..00000000 --- a/community/community/web_form/update_profile/update_profile.py +++ /dev/null @@ -1,7 +0,0 @@ -from __future__ import unicode_literals - -import frappe - -def get_context(context): - # do your magic here - pass diff --git a/community/community/widgets/Avatar.html b/community/community/widgets/Avatar.html index fac236df..4cb65da6 100644 --- a/community/community/widgets/Avatar.html +++ b/community/community/widgets/Avatar.html @@ -1,8 +1,8 @@ {% set color = member.get_palette() %} - {% if member.get_photo_url() %} - + {% if member.user_image %} + {% else %} int: + """Returns the number of courses authored by this user. + """ + return frappe.db.count( + 'LMS Course', { + 'owner': self.email + }) + + 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] + diff --git a/community/patches.txt b/community/patches.txt index 5b1b2f97..e18c7fd7 100644 --- a/community/patches.txt +++ b/community/patches.txt @@ -2,3 +2,4 @@ community.patches.set_email_preferences community.patches.change_name_for_community_members community.patches.save_abbr_for_community_members community.patches.create_mentor_request_email_templates +community.patches.replace_member_with_user_in_batch_membership diff --git a/community/patches/replace_member_with_user_in_batch_membership.py b/community/patches/replace_member_with_user_in_batch_membership.py new file mode 100644 index 00000000..e8e04748 --- /dev/null +++ b/community/patches/replace_member_with_user_in_batch_membership.py @@ -0,0 +1,10 @@ +from __future__ import unicode_literals +import frappe +from frappe import _ + +def execute(): + frappe.reload_doc("lms", "doctype", "lms_batch_membership") + memberships = frappe.get_all("LMS Batch Membership", ["member", "name"]) + for membership in memberships: + email = frappe.db.get_value("Community Member", membership.member, "email") + frappe.db.set_value("LMS Batch Membership", membership.name, "member", email) diff --git a/community/www/courses/course.py b/community/www/courses/course.py index a397ab26..69957fb3 100644 --- a/community/www/courses/course.py +++ b/community/www/courses/course.py @@ -1,6 +1,4 @@ import frappe -from community.www.courses.utils import get_instructor -from frappe.utils import nowdate, getdate from community.lms.models import Course def get_context(context): diff --git a/community/www/courses/utils.py b/community/www/courses/utils.py index 63dfdb6e..189a0f46 100644 --- a/community/www/courses/utils.py +++ b/community/www/courses/utils.py @@ -37,16 +37,6 @@ def get_course(name): except frappe.DoesNotExistError: return -def get_instructor(owner): - instructor = frappe._dict() - try: - instructor = frappe.get_doc("Community Member", {"email": owner}) - except frappe.DoesNotExistError: - instructor.full_name = owner - instructor.abbr = ("").join([ s[0] for s in owner.split() ]) - instructor.course_count = len(frappe.get_all("LMS Course", {"owner": owner})) - return instructor - def get_batch_members(batch): members = [] memberships = frappe.get_all("LMS Batch Membership", {"batch": batch}, ["member", "member_type"])