Compare commits
4 Commits
username-f
...
sketch-red
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7017382451 | ||
|
|
3e2c6b3343 | ||
|
|
5ea744de5c | ||
|
|
aedb3d3d45 |
@@ -1,16 +0,0 @@
|
||||
<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,22 +34,14 @@ class TestCustomUser(unittest.TestCase):
|
||||
}).insert()
|
||||
self.assertEqual(new_user.username[:8], "username")
|
||||
|
||||
def test_with_underscore_at_end(self):
|
||||
def test_with_hyphen_at_end(self):
|
||||
new_user = frappe.get_doc({
|
||||
"doctype": "User",
|
||||
"email": "test_with_underscore_at_end@example.com",
|
||||
"first_name": "Username___"
|
||||
"email": "test_with_hyphen_at_end@example.com",
|
||||
"first_name": "Username---"
|
||||
}).insert()
|
||||
self.assertNotEqual(new_user.username[-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)
|
||||
length = len(new_user.username)
|
||||
self.assertNotEqual(new_user.username[length-1], "-")
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls) -> None:
|
||||
@@ -57,7 +49,6 @@ class TestCustomUser(unittest.TestCase):
|
||||
"test_with_basic_username@example.com",
|
||||
"test-without-username@example.com",
|
||||
"test_with_illegal_characters@example.com",
|
||||
"test_with_underscore_at_end@example.com",
|
||||
"test_with_short_first_name@example.com"
|
||||
"test_with_hyphen_at_end@example.com"
|
||||
]
|
||||
frappe.db.delete("User", {"name": ["in", users]})
|
||||
|
||||
@@ -13,45 +13,38 @@ class CustomUser(User):
|
||||
self.validate_username_characters()
|
||||
|
||||
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 not self.username:
|
||||
self.username = self.get_username_from_first_name()
|
||||
|
||||
if self.username.find(" "):
|
||||
self.username.replace(" ", "")
|
||||
|
||||
if not re.match("^[A-Za-z0-9_]*$", self.username) or underscore_condition:
|
||||
if not re.match("^[A-Za-z0-9_]*$", self.username):
|
||||
self.username = self.remove_illegal_characters()
|
||||
|
||||
if len(self.username) < 4:
|
||||
self.username = self.email.replace("@", "").replace(".", "")
|
||||
if not self.username:
|
||||
self.username = self.get_username_from_first_name()
|
||||
|
||||
while self.username_exists():
|
||||
if self.username_exists():
|
||||
self.username = self.remove_illegal_characters() + str(random.randint(0, 99))
|
||||
|
||||
else:
|
||||
if not self.username:
|
||||
frappe.throw(_("Username already exists."))
|
||||
if not re.match("^[A-Za-z0-9_-]*$", self.username):
|
||||
frappe.throw(_("Username can only contain alphabets, numbers, hyphen and underscore."))
|
||||
|
||||
if not re.match("^[A-Za-z0-9_]*$", self.username):
|
||||
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"))
|
||||
if self.username[0] == "-" or self.username[len(self.username) - 1] == "-":
|
||||
frappe.throw(_("First and Last character of username cannot be Hyphen(-)."))
|
||||
|
||||
def get_username_from_first_name(self):
|
||||
return frappe.scrub(self.first_name) + str(random.randint(0, 99))
|
||||
|
||||
def remove_illegal_characters(self):
|
||||
return re.sub("[^\w]+", "", self.username).strip("_")
|
||||
username = ''.join([c for c in self.username if c.isalnum() or c in ['-', '_']])
|
||||
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:
|
||||
"""Returns the number of courses authored by this user.
|
||||
|
||||
3
community/public/icons/like.svg
Normal file
3
community/public/icons/like.svg
Normal file
@@ -0,0 +1,3 @@
|
||||
<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>
|
||||
|
After Width: | Height: | Size: 871 B |
Reference in New Issue
Block a user