feat: community member for profile and edit profile form

This commit is contained in:
pateljannat
2021-03-12 12:22:12 +05:30
parent b7602d6d2b
commit 25a0dd02ac
14 changed files with 124 additions and 38 deletions

View File

@@ -69,7 +69,7 @@
"index_web_pages_for_search": 1,
"is_published_field": "enabled",
"links": [],
"modified": "2021-03-03 15:00:46.298535",
"modified": "2021-03-09 11:17:40.842666",
"modified_by": "Administrator",
"module": "Community",
"name": "Community Course Member",
@@ -89,7 +89,6 @@
}
],
"quick_entry": 1,
"route": "me",
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1

View File

@@ -17,7 +17,7 @@ class CommunityCourseMember(WebsiteGenerator):
def validate(self):
self.validate_user_name()
if not self.route:
self.route = "me/" + self.user_name
self.route = self.user_name
def validate_user_name(self):
if len(self.user_name) < 4:
@@ -60,7 +60,7 @@ class CommunityCourseMember(WebsiteGenerator):
"username": self.user_name,
"send_welcome_email": 0,
"user_type": 'Website User',
"redirect_url": "me/" + self.name
"redirect_url": self.name
})
user.save(ignore_permissions=True)
update_password_link = user.reset_password()

View File

@@ -1,6 +1,6 @@
{
"actions": [],
"autoname": "field:user_name",
"allow_guest_to_view": 1,
"creation": "2021-02-12 15:47:23.591567",
"doctype": "DocType",
"editable_grid": 1,
@@ -8,6 +8,7 @@
"field_order": [
"enabled",
"full_name",
"email",
"role",
"photo",
"short_intro",
@@ -64,11 +65,20 @@
"fieldname": "route",
"fieldtype": "Data",
"label": "Route"
},
{
"fieldname": "email",
"fieldtype": "Data",
"label": "Email",
"options": "Email",
"reqd": 1,
"unique": 1
}
],
"has_web_view": 1,
"index_web_pages_for_search": 1,
"links": [],
"modified": "2021-03-02 11:24:28.763348",
"modified": "2021-03-12 10:23:09.709669",
"modified_by": "Administrator",
"module": "Community",
"name": "Community Member",

View File

@@ -3,8 +3,39 @@
# For license information, please see license.txt
from __future__ import unicode_literals
# import frappe
import frappe
from frappe.website.website_generator import WebsiteGenerator
import re
from frappe import _
class CommunityMember(WebsiteGenerator):
pass
def get_context(self, context):
context.abbr = ("").join([ s[0] for s in self.full_name.split() ])
return context
def validate(self):
self.validate_user_name()
if self.route != self.user_name:
self.route = self.user_name
def validate_user_name(self):
if self.user_name:
if len(self.user_name) < 4:
frappe.throw(_("Username must be atleast 4 characters long."))
if not re.match("^[A-Za-z0-9]*$", self.user_name):
frappe.throw(_("Username can only contain alphabets, and numbers."))
self.user_name = self.user_name.lower()
def autoname(self):
self.name = self.user_name
def create_member_from_user(doc, method):
member = frappe.get_doc({
"doctype": "Community Member",
"full_name": doc.full_name,
"user_name": doc.username,
"email": doc.email,
"route": doc.username,
"owner": doc.email
})
member.save(ignore_permissions=True)

View File

@@ -1,17 +1,23 @@
{% extends "templates/web.html" %}
{% block page_content %}
<div class="py-20 row">
{% if photo %}
<div class="col-sm-2 border border-dark">
<img src="{{ photo }}" alt="{{ full_name }}">
</div>
{% else %}
<div class="col-sm-2">
<div class="standard-image" style="font-size: 30px;">{{ abbr }}</div>
</div>
{% endif %}
<div class="col">
<h1>{{ full_name }}</h1>
<p class="lead"> {{ short_intro }}</p>
<div class="mt-4">
<div>Role: <strong>{{ role }}</strong></div>
</div>
<p class="markdown-style">{{ frappe.utils.md_to_html(bio) }}</p>
{% if short_intro %}
<p class="lead"> {{ short_intro }} </p>
{% endif %}
{% if bio %}
<p class="markdown-style"> {{ frappe.utils.md_to_html(bio) }} </p>
{% endif %}
</div>
</div>
{% endblock %}

View File

@@ -2,37 +2,39 @@
"accept_payment": 0,
"allow_comments": 0,
"allow_delete": 0,
"allow_edit": 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,
"button_label": "Submit",
"creation": "2021-03-02 11:31:39.072501",
"doc_type": "Community Course Member",
"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": 0,
"login_required": 1,
"max_attachment_size": 0,
"modified": "2021-03-03 11:02:33.907687",
"modified": "2021-03-12 10:23:37.625177",
"modified_by": "Administrator",
"module": "Community",
"name": "community-course-membership",
"name": "update-profile",
"owner": "Administrator",
"payment_button_label": "Buy Now",
"published": 1,
"route": "community-course-membership",
"route": "edit-profile",
"route_to_success_link": 0,
"show_attachments": 0,
"show_in_grid": 0,
"show_sidebar": 0,
"sidebar_items": [],
"success_url": "/community-course-membership",
"title": "Community Course Membership",
"success_message": "Profile updated successfully.",
"success_url": "/",
"title": "Update Profile",
"web_form_fields": [
{
"allow_read_on_all_link_options": 0,
@@ -55,7 +57,7 @@
"max_length": 0,
"max_value": 0,
"read_only": 0,
"reqd": 1,
"reqd": 0,
"show_in_filter": 0
},
{
@@ -70,6 +72,42 @@
"read_only": 0,
"reqd": 0,
"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
}
]
}