fix: Remove duplicate validation function
This commit is contained in:
parent
465708050a
commit
9d4ee238d7
2 changed files with 7 additions and 10 deletions
|
|
@ -55,8 +55,7 @@ class EventProducer(Document):
|
|||
self.reload()
|
||||
|
||||
def check_url(self):
|
||||
if not frappe.utils.validate_url(self.producer_url):
|
||||
frappe.throw(_('Invalid URL'))
|
||||
frappe.utils.validate_url(self.producer_url, throw=True)
|
||||
|
||||
# remove '/' from the end of the url like http://test_site.com/
|
||||
# to prevent mismatch in get_url() results
|
||||
|
|
|
|||
|
|
@ -156,10 +156,16 @@ def split_emails(txt):
|
|||
return email_list
|
||||
|
||||
def validate_url(txt, throw=False):
|
||||
if not url:
|
||||
return True
|
||||
|
||||
try:
|
||||
url = urlparse(txt).netloc
|
||||
if not url:
|
||||
raise frappe.ValidationError
|
||||
else:
|
||||
return True
|
||||
|
||||
except Exception:
|
||||
if throw:
|
||||
frappe.throw(
|
||||
|
|
@ -820,11 +826,3 @@ def groupby_metric(iterable: typing.Dict[str, list], key: str):
|
|||
for item in items:
|
||||
records.setdefault(item[key], {}).setdefault(category, []).append(item)
|
||||
return records
|
||||
|
||||
|
||||
def validate_url(url_string):
|
||||
try:
|
||||
result = urlparse(url_string)
|
||||
return result.scheme and result.scheme in ["http", "https", "ftp", "ftps"]
|
||||
except Exception:
|
||||
return False
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue