diff --git a/community/lms/web_form/profile/profile.json b/community/lms/web_form/profile/profile.json index 4c3fcc7d..bcea7451 100644 --- a/community/lms/web_form/profile/profile.json +++ b/community/lms/web_form/profile/profile.json @@ -20,7 +20,7 @@ "is_standard": 1, "login_required": 1, "max_attachment_size": 0, - "modified": "2021-07-14 17:15:15.424855", + "modified": "2021-08-05 10:27:15.727657", "modified_by": "Administrator", "module": "LMS", "name": "profile", @@ -72,6 +72,18 @@ "reqd": 0, "show_in_filter": 0 }, + { + "allow_read_on_all_link_options": 0, + "fieldname": "username", + "fieldtype": "Data", + "hidden": 0, + "label": "Username", + "max_length": 0, + "max_value": 0, + "read_only": 0, + "reqd": 0, + "show_in_filter": 0 + }, { "allow_read_on_all_link_options": 0, "description": "Get your globally recognized avatar from Gravatar.com", diff --git a/community/overrides/user.py b/community/overrides/user.py index bcb1496a..78839e82 100644 --- a/community/overrides/user.py +++ b/community/overrides/user.py @@ -2,9 +2,28 @@ import frappe from frappe.core.doctype.user.user import User from frappe.utils import cint import hashlib +import random +import re +from frappe import _ class CustomUser(User): + """ def validate(self): + super(CustomUser, self).validate() + self.validate_username() """ + + """ def validate_username(self): + if self.is_new(): + if self.username.find(" "): + self.username.replace(" ", "") + if not self.username: + self.username = frappe.scrub(self.first_name) + random.randint() + + elif not re.match("^[A-Za-z0-9_]*$", self.username): + frappe.throw(_("Username can only contain alphabets, numbers and underscore.")) """ + + + def get_authored_courses(self) -> int: """Returns the number of courses authored by this user. """