Compare commits
2 Commits
sketch-red
...
username-f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66aace247c | ||
|
|
bc3db06960 |
16
community/lms/widgets/SketchTeaser.html
Normal file
16
community/lms/widgets/SketchTeaser.html
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<div class="sketch-teaser">
|
||||||
|
<div class="sketch-image">
|
||||||
|
<a href="/sketches/{{sketch.sketch_id}}">
|
||||||
|
{{ sketch.to_svg() }}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="sketch-footer">
|
||||||
|
<div class="sketch-title">
|
||||||
|
<a href="sketches/{{sketch.sketch_id}}">{{sketch.title}}</a>
|
||||||
|
</div>
|
||||||
|
<div class="sketch-author">
|
||||||
|
{% set owner = sketch.get_owner() %}
|
||||||
|
by <a href="/{{owner.username}}">{{owner.full_name}}</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -34,14 +34,22 @@ class TestCustomUser(unittest.TestCase):
|
|||||||
}).insert()
|
}).insert()
|
||||||
self.assertEqual(new_user.username[:8], "username")
|
self.assertEqual(new_user.username[:8], "username")
|
||||||
|
|
||||||
def test_with_hyphen_at_end(self):
|
def test_with_underscore_at_end(self):
|
||||||
new_user = frappe.get_doc({
|
new_user = frappe.get_doc({
|
||||||
"doctype": "User",
|
"doctype": "User",
|
||||||
"email": "test_with_hyphen_at_end@example.com",
|
"email": "test_with_underscore_at_end@example.com",
|
||||||
"first_name": "Username---"
|
"first_name": "Username___"
|
||||||
}).insert()
|
}).insert()
|
||||||
length = len(new_user.username)
|
self.assertNotEqual(new_user.username[-1], "_")
|
||||||
self.assertNotEqual(new_user.username[length-1], "-")
|
|
||||||
|
|
||||||
|
def test_with_short_first_name(self):
|
||||||
|
new_user = frappe.get_doc({
|
||||||
|
"doctype": "User",
|
||||||
|
"email": "test_with_short_first_name@example.com",
|
||||||
|
"first_name": "USN"
|
||||||
|
}).insert()
|
||||||
|
self.assertGreaterEqual(len(new_user.username), 4)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls) -> None:
|
def tearDownClass(cls) -> None:
|
||||||
@@ -49,6 +57,7 @@ class TestCustomUser(unittest.TestCase):
|
|||||||
"test_with_basic_username@example.com",
|
"test_with_basic_username@example.com",
|
||||||
"test-without-username@example.com",
|
"test-without-username@example.com",
|
||||||
"test_with_illegal_characters@example.com",
|
"test_with_illegal_characters@example.com",
|
||||||
"test_with_hyphen_at_end@example.com"
|
"test_with_underscore_at_end@example.com",
|
||||||
|
"test_with_short_first_name@example.com"
|
||||||
]
|
]
|
||||||
frappe.db.delete("User", {"name": ["in", users]})
|
frappe.db.delete("User", {"name": ["in", users]})
|
||||||
|
|||||||
@@ -13,38 +13,45 @@ class CustomUser(User):
|
|||||||
self.validate_username_characters()
|
self.validate_username_characters()
|
||||||
|
|
||||||
def validate_username_characters(self):
|
def validate_username_characters(self):
|
||||||
|
if len(self.username):
|
||||||
|
underscore_condition = self.username[0] == "_" or self.username[-1] == "_"
|
||||||
|
else:
|
||||||
|
underscore_condition = ''
|
||||||
|
|
||||||
if self.is_new():
|
if self.is_new():
|
||||||
|
if not self.username:
|
||||||
|
self.username = self.get_username_from_first_name()
|
||||||
|
|
||||||
if self.username.find(" "):
|
if self.username.find(" "):
|
||||||
self.username.replace(" ", "")
|
self.username.replace(" ", "")
|
||||||
|
|
||||||
if not re.match("^[A-Za-z0-9_]*$", self.username):
|
if not re.match("^[A-Za-z0-9_]*$", self.username) or underscore_condition:
|
||||||
self.username = self.remove_illegal_characters()
|
self.username = self.remove_illegal_characters()
|
||||||
|
|
||||||
if not self.username:
|
if len(self.username) < 4:
|
||||||
self.username = self.get_username_from_first_name()
|
self.username = self.email.replace("@", "").replace(".", "")
|
||||||
|
|
||||||
if self.username_exists():
|
while self.username_exists():
|
||||||
self.username = self.remove_illegal_characters() + str(random.randint(0, 99))
|
self.username = self.remove_illegal_characters() + str(random.randint(0, 99))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if not re.match("^[A-Za-z0-9_-]*$", self.username):
|
if not self.username:
|
||||||
frappe.throw(_("Username can only contain alphabets, numbers, hyphen and underscore."))
|
frappe.throw(_("Username already exists."))
|
||||||
|
|
||||||
if self.username[0] == "-" or self.username[len(self.username) - 1] == "-":
|
if not re.match("^[A-Za-z0-9_]*$", self.username):
|
||||||
frappe.throw(_("First and Last character of username cannot be Hyphen(-)."))
|
frappe.throw(_("Username can only contain alphabets, numbers and unedrscore."))
|
||||||
|
|
||||||
|
if underscore_condition:
|
||||||
|
frappe.throw(_("First and Last character of username cannot be Underscore(_)."))
|
||||||
|
|
||||||
|
if len(self.username) < 4:
|
||||||
|
frappe.throw(_("Username cannot be less than 4 characters"))
|
||||||
|
|
||||||
def get_username_from_first_name(self):
|
def get_username_from_first_name(self):
|
||||||
return frappe.scrub(self.first_name) + str(random.randint(0, 99))
|
return frappe.scrub(self.first_name) + str(random.randint(0, 99))
|
||||||
|
|
||||||
def remove_illegal_characters(self):
|
def remove_illegal_characters(self):
|
||||||
username = ''.join([c for c in self.username if c.isalnum() or c in ['-', '_']])
|
return re.sub("[^\w]+", "", self.username).strip("_")
|
||||||
while username[0] == "-" or username[len(username) - 1] == "-":
|
|
||||||
if username[0] == "-":
|
|
||||||
username = username[1:]
|
|
||||||
if username[len(username) - 1]:
|
|
||||||
username = username[:1]
|
|
||||||
return username
|
|
||||||
|
|
||||||
def get_authored_courses(self) -> int:
|
def get_authored_courses(self) -> int:
|
||||||
"""Returns the number of courses authored by this user.
|
"""Returns the number of courses authored by this user.
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<path d="M13.0746 3.60967C12.7814 3.31071 12.4333 3.07355 12.0501 2.91174C11.6669 2.74994 11.2562 2.66666 10.8415 2.66666C10.4267 2.66666 10.016 2.74994 9.63283 2.91174C9.24966 3.07355 8.90152 3.31071 8.60831 3.60967L7.99979 4.22983L7.39126 3.60967C6.79899 3.00607 5.9957 2.66697 5.1581 2.66697C4.32051 2.66697 3.51721 3.00607 2.92494 3.60967C2.33267 4.21327 1.99994 5.03192 1.99994 5.88554C1.99994 6.73916 2.33267 7.55782 2.92494 8.16142L3.53347 8.78158L7.99979 13.3333L12.4661 8.78158L13.0746 8.16142C13.368 7.86259 13.6007 7.5078 13.7595 7.11729C13.9182 6.72679 13.9999 6.30824 13.9999 5.88554C13.9999 5.46284 13.9182 5.04429 13.7595 4.65379C13.6007 4.26329 13.368 3.90849 13.0746 3.60967V3.60967Z" stroke="#4C5A67" stroke-linecap="round" stroke-linejoin="round"/>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 871 B |
Reference in New Issue
Block a user