From d38c64650ee9ae67d1ddf415ae7bfbf0a596602d Mon Sep 17 00:00:00 2001 From: pateljannat Date: Mon, 12 Apr 2021 18:05:43 +0530 Subject: [PATCH] fix: patch to update name of member --- .../community_member/community_member.json | 3 +- .../community_member/community_member.py | 4 --- community/hooks.py | 2 ++ community/patches.txt | 3 +- .../change_name_for_community_members.py | 12 ++++++++ community/www/dashboard/index.html | 28 ++++++------------- community/www/macros/profile.html | 12 ++++++++ community/www/profiles/profile.html | 26 ++++------------- 8 files changed, 43 insertions(+), 47 deletions(-) create mode 100644 community/patches/change_name_for_community_members.py create mode 100644 community/www/macros/profile.html diff --git a/community/community/doctype/community_member/community_member.json b/community/community/doctype/community_member/community_member.json index 234bcecd..f0cfdf5c 100644 --- a/community/community/doctype/community_member/community_member.json +++ b/community/community/doctype/community_member/community_member.json @@ -2,7 +2,6 @@ "actions": [], "allow_guest_to_view": 1, "allow_rename": 1, - "autoname": "field:email", "creation": "2021-02-12 15:47:23.591567", "doctype": "DocType", "editable_grid": 1, @@ -108,7 +107,7 @@ "has_web_view": 1, "index_web_pages_for_search": 1, "links": [], - "modified": "2021-04-12 13:34:41.573486", + "modified": "2021-04-12 17:32:36.211603", "modified_by": "Administrator", "module": "Community", "name": "Community Member", diff --git a/community/community/doctype/community_member/community_member.py b/community/community/doctype/community_member/community_member.py index 294ca812..4966535a 100644 --- a/community/community/doctype/community_member/community_member.py +++ b/community/community/doctype/community_member/community_member.py @@ -27,10 +27,6 @@ class CommunityMember(WebsiteGenerator): frappe.throw(_("Username can only contain alphabets, numbers and underscore.")) self.username = self.username.lower() - def on_update(self): - if self.username != self.name: - rename_doc(self.doctype, self.name, self.username, force=False, merge=False, ignore_permissions=True, ignore_if_exists=False) - def create_member_from_user(doc, method): member = frappe.get_doc({ "doctype": "Community Member", diff --git a/community/hooks.py b/community/hooks.py index 5a26ac85..75d4d761 100644 --- a/community/hooks.py +++ b/community/hooks.py @@ -149,6 +149,8 @@ whitelist = [ "/sketches", "/admin", "/socket.io", + "/hackathons", + "/dashboard" ] whitelist_rules = [{"from_route": p, "to_route": p[1:]} for p in whitelist] diff --git a/community/patches.txt b/community/patches.txt index 5374512d..fa60560e 100644 --- a/community/patches.txt +++ b/community/patches.txt @@ -1 +1,2 @@ -community.patches.set_email_preferences \ No newline at end of file +community.patches.set_email_preferences +community.patches.change_name_for_community_members \ No newline at end of file diff --git a/community/patches/change_name_for_community_members.py b/community/patches/change_name_for_community_members.py new file mode 100644 index 00000000..5d1b7f51 --- /dev/null +++ b/community/patches/change_name_for_community_members.py @@ -0,0 +1,12 @@ +from __future__ import unicode_literals +import frappe +from frappe.model.naming import make_autoname +from frappe.model.rename_doc import rename_doc + +def execute(): + frappe.reload_doc("community", "doctype", "community_member") + docs = frappe.get_all("Community Member") + for doc in docs: + member = frappe.get_doc("Community Member", doc.name) + name = make_autoname("hash", "Community Member") + rename_doc("Community Member", member.name, name, force=True, merge=False, ignore_permissions=True, ignore_if_exists=False) diff --git a/community/www/dashboard/index.html b/community/www/dashboard/index.html index 2984af66..733dc31f 100644 --- a/community/www/dashboard/index.html +++ b/community/www/dashboard/index.html @@ -1,4 +1,5 @@ {% extends "templates/base.html" %} +{% from "www/macros/profile.html" import profile %} {% block title %}{{ _("Community") }}{% endblock %} {% block head_include %} @@ -86,19 +87,6 @@ {% endblock %} -{% macro profile(photo, full_name, abbr, icon) %} -{% if photo %} -{{ full_name }} -{% else %} -
-
- {{ abbr }} -
-
-{% endif %} -{% endmacro %} - {% block content %}
@@ -159,9 +147,9 @@
Create a New Sketch - {% if sketches %} - {% for sketch in sketches %} -
+
+ {% if sketches %} + {% for sketch in sketches %}
@@ -179,11 +167,11 @@
+ {% endfor %} + {% else %} +

You have not created any sketches.

+ {% endif %}
- {% endfor %} - {% else %} -

You have not created any sketches.

- {% endif %}
diff --git a/community/www/macros/profile.html b/community/www/macros/profile.html new file mode 100644 index 00000000..3e9ff5cb --- /dev/null +++ b/community/www/macros/profile.html @@ -0,0 +1,12 @@ +{% macro profile(photo, full_name, abbr, icon) %} +{% if photo %} +{{ full_name }} +{% else %} +
+
+ {{ abbr }} +
+
+{% endif %} +{% endmacro %} \ No newline at end of file diff --git a/community/www/profiles/profile.html b/community/www/profiles/profile.html index 5a1887b0..e793d529 100644 --- a/community/www/profiles/profile.html +++ b/community/www/profiles/profile.html @@ -1,25 +1,11 @@ {% extends "templates/web.html" %} +{% from "www/macros/profile.html" import profile %} {% block page_content %} -
- {% if user.photo %} -
- {{ user.full_name }} +
+
+ {{ profile(member.photo, member.full_name, abbr, "large")}}
- {% else %} -
-
{{ user.abbr }}
-
- {% endif %} -
-

{{ user.full_name }}

- {% if user.short_intro %} -

{{ user.short_intro }}

- {% endif %} - {% if user.bio %} -

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

- {% endif %} -
-
+
{% endblock %} - + \ No newline at end of file