|
|
@ -32,39 +32,73 @@ class SpecialToolInformation(Document): |
|
|
|
|
|
|
|
|
|
|
|
@frappe.whitelist() |
|
|
|
def file_validation(image, name, value=None): |
|
|
|
from smart_service.apis.utils import check_png_ext, check_img_ext, check_zip_ext, check_pdf_ext, checking_image, details_of_image, check_mp4_ext, get_file_size |
|
|
|
def file_validation(image, name): |
|
|
|
from smart_service.apis.utils import check_png_ext, check_img_ext, check_zip_ext, check_pdf_ext, details_of_image, checking_image |
|
|
|
if image: |
|
|
|
res = check_img_ext(image) |
|
|
|
res1 = check_png_ext(image) |
|
|
|
if res == True: |
|
|
|
(width, height, size) = details_of_image(image) |
|
|
|
if value == 'image': |
|
|
|
if width > 1280 or height > 720 or size > 1*1024 and image: |
|
|
|
val = checking_image(image, 'Special Tool Information', |
|
|
|
value, name) |
|
|
|
if val == True: |
|
|
|
return (False, 2) |
|
|
|
else: |
|
|
|
return True |
|
|
|
if res == True or res1 == True: |
|
|
|
width, height, size = details_of_image(image) |
|
|
|
if width > 1280 or height > 720 or size > 1*1024 and image: |
|
|
|
val = checking_image(image, "Special Tool Information", "image", name) |
|
|
|
if val == True: |
|
|
|
return False, 2 |
|
|
|
else: |
|
|
|
return True |
|
|
|
else: |
|
|
|
val = checking_image(image, "Special Tool Information", "image", name) |
|
|
|
if res == False: |
|
|
|
ret = res |
|
|
|
else: |
|
|
|
ret = res1 |
|
|
|
return ret, 1 |
|
|
|
|
|
|
|
if value == 'aggregate_image': |
|
|
|
if width > 1280 or height > 720 or size > 1*1024 and image: |
|
|
|
val = checking_image(image, 'Special Tool Information', |
|
|
|
value, name) |
|
|
|
if val == True: |
|
|
|
return (False, 2) |
|
|
|
else: |
|
|
|
return True |
|
|
|
@frappe.whitelist() |
|
|
|
def file_validation1(image, name): |
|
|
|
from smart_service.apis.utils import check_png_ext, check_img_ext, check_zip_ext, check_pdf_ext, details_of_image, checking_image |
|
|
|
if image: |
|
|
|
res = check_img_ext(image) |
|
|
|
res1 = check_png_ext(image) |
|
|
|
if res == True or res1 == True: |
|
|
|
width, height, size = details_of_image(image) |
|
|
|
if width > 1280 or height > 720 or size > 1*1024 and image: |
|
|
|
val = checking_image(image, "Special Tool Information", "aggregate_image", name) |
|
|
|
if val == True: |
|
|
|
return False, 2 |
|
|
|
else: |
|
|
|
return True |
|
|
|
else: |
|
|
|
val = checking_image( |
|
|
|
image, 'Special Tool Information', value, name) |
|
|
|
val = checking_image(image, "Special Tool Information", "aggregate_image", name) |
|
|
|
if res == False: |
|
|
|
ret = res |
|
|
|
else: |
|
|
|
ret = res1 |
|
|
|
return ret, 1 |
|
|
|
|
|
|
|
@frappe.whitelist() |
|
|
|
def file_validation2(pdf = None): |
|
|
|
from smart_service.apis.utils import check_png_ext, check_img_ext, check_zip_ext, check_pdf_ext, get_file_size |
|
|
|
if pdf: |
|
|
|
res = check_pdf_ext(pdf) |
|
|
|
if res == True: |
|
|
|
size = get_file_size(pdf) |
|
|
|
if size > 1*1024 and pdf: |
|
|
|
return True, 1 |
|
|
|
else: |
|
|
|
return False, 2 |
|
|
|
|
|
|
|
@frappe.whitelist() |
|
|
|
def file_validation3(video=None): |
|
|
|
from smart_service.apis.utils import check_pdf_ext, details_of_image, checking_image, get_file_size,check_mp4_ext |
|
|
|
if video: |
|
|
|
res = check_mp4_ext(video) |
|
|
|
if res == True: |
|
|
|
size = get_file_size(video) |
|
|
|
if size > 100*1024 and video: |
|
|
|
return True, 1 |
|
|
|
else: |
|
|
|
return False, 2 |
|
|
|
|
|
|
|
|
|
|
|
@frappe.whitelist() |
|
|
|
def file_validation_child(name, value=None): |
|
|
@ -120,46 +154,11 @@ def file_validation_child(name, value=None): |
|
|
|
return (ret, d['idx']) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@frappe.whitelist() |
|
|
|
def file_validation1(image,video, name, value=None): |
|
|
|
from smart_service.apis.utils import check_pdf_ext,details_of_image,check_mp4_ext,get_file_size |
|
|
|
if image: |
|
|
|
res = check_pdf_ext(image) |
|
|
|
if res == True: |
|
|
|
(width,height,size) = details_of_image(image) |
|
|
|
|
|
|
|
if size > 1*1024 and image: |
|
|
|
val = delete_file(image) |
|
|
|
if val == True: |
|
|
|
return (False, 2) |
|
|
|
else: |
|
|
|
return True |
|
|
|
else: |
|
|
|
val = delete_file(image, 'Special Tool Information', |
|
|
|
"pdf", name) |
|
|
|
if res == False: |
|
|
|
ret = res |
|
|
|
return ret, 1 |
|
|
|
if video: |
|
|
|
res1=check_mp4_ext(video) |
|
|
|
if res1== True: |
|
|
|
video_size_mb = get_file_size(video) |
|
|
|
if video_size_mb > 100: |
|
|
|
val= delete_file(video) |
|
|
|
return (False,2) |
|
|
|
else: |
|
|
|
val = delete_file(video, 'Special Tool Information', |
|
|
|
"video", name) |
|
|
|
if res == False: |
|
|
|
ret = res1 |
|
|
|
return ret, 1 |
|
|
|
|
|
|
|
def delete_file(file_url, attached_to_doctype, attached_to_field, docname, is_child=None): |
|
|
|
image_name = frappe.db.get_list("File", fields={"name"}, filters={"file_url": file_url, |
|
|
|
"attached_to_doctype": attached_to_doctype, |
|
|
|
"attached_to_field": attached_to_field, |
|
|
|
"attached_to_name": docname}) |
|
|
|
if len(image_name) > 0: |
|
|
|
frappe.delete_doc('File', image_name[0]['name']) |
|
|
|
return True |
|
|
|
# def delete_file(file_url, attached_to_doctype, attached_to_field, docname, is_child=None): |
|
|
|
# image_name = frappe.db.get_list("File", fields={"name"}, filters={"file_url": file_url, |
|
|
|
# "attached_to_doctype": attached_to_doctype, |
|
|
|
# "attached_to_field": attached_to_field, |
|
|
|
# "attached_to_name": docname}) |
|
|
|
# if len(image_name) > 0: |
|
|
|
# frappe.delete_doc('File', image_name[0]['name']) |
|
|
|
# return True |