|
@ -6,6 +6,7 @@ from frappe.model.document import Document |
|
|
|
|
|
|
|
|
class SpecialToolInformation(Document): |
|
|
class SpecialToolInformation(Document): |
|
|
def validate(self): |
|
|
def validate(self): |
|
|
|
|
|
# self.name="" |
|
|
if self.is_new(): |
|
|
if self.is_new(): |
|
|
count = frappe.db.sql('''select max(my_id) as max_count from `tabSpecial Tool Information`;''') |
|
|
count = frappe.db.sql('''select max(my_id) as max_count from `tabSpecial Tool Information`;''') |
|
|
if count[0][0] is not None: |
|
|
if count[0][0] is not None: |
|
@ -14,12 +15,71 @@ class SpecialToolInformation(Document): |
|
|
self.my_id = 1 |
|
|
self.my_id = 1 |
|
|
if self.keywords: |
|
|
if self.keywords: |
|
|
self.keywords=self.keywords.strip() |
|
|
self.keywords=self.keywords.strip() |
|
|
if self.aggregate_name: |
|
|
|
|
|
self.aggregate_name=self.aggregate_name.strip() |
|
|
|
|
|
if self.tool_name: |
|
|
if self.tool_name: |
|
|
self.tool_name=self.tool_name.strip() |
|
|
self.tool_name=self.tool_name.strip() |
|
|
|
|
|
if self.aggregate_name: |
|
|
|
|
|
self.aggregate_name=self.aggregate_name.strip() |
|
|
|
|
|
self.name = self.vehicle + '-' + \ |
|
|
|
|
|
self.tool_type + '-' + self.category + '-' + self.aggregate_name |
|
|
|
|
|
else: |
|
|
|
|
|
self.name = self.vehicle + '-' + self.tool_type + '-' + self.category |
|
|
|
|
|
|
|
|
if not self.is_new() and self.published == 1: |
|
|
if not self.is_new() and self.published == 1: |
|
|
self.published = 0 |
|
|
self.published = 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@frappe.whitelist() |
|
|
|
|
|
def file_validation_child(name, value=None): |
|
|
|
|
|
from smart_service.apis.utils import check_png_ext, check_img_ext, check_zip_ext, check_pdf_ext, details_of_image, checking_image, check_mp4_ext, get_file_size |
|
|
|
|
|
if name: |
|
|
|
|
|
child_data = frappe.db.sql( |
|
|
|
|
|
"""select * from `tabtabInstructions` where parent='%s'"""%(name), as_dict=1) |
|
|
|
|
|
for d in child_data: |
|
|
|
|
|
if d['attach_file']: |
|
|
|
|
|
res = False |
|
|
|
|
|
res1 = False |
|
|
|
|
|
res2 = False |
|
|
|
|
|
res3 = False |
|
|
|
|
|
if d['content_type'] == "Image": |
|
|
|
|
|
res = check_img_ext(d['attach_file']) |
|
|
|
|
|
res1 = check_png_ext(d['attach_file']) |
|
|
|
|
|
elif d['content_type'] == "PDF": |
|
|
|
|
|
res3 = check_pdf_ext(d['attach_file']) |
|
|
|
|
|
else: |
|
|
|
|
|
res2 = check_mp4_ext(d['attach_file']) |
|
|
|
|
|
|
|
|
|
|
|
if res == True or res1 == True: |
|
|
|
|
|
width, height, size = details_of_image( |
|
|
|
|
|
d['attach_file']) |
|
|
|
|
|
if width > 1280 or height > 720 or size > 1*1024 and d['attach_file']: |
|
|
|
|
|
val = checking_image( |
|
|
|
|
|
d['attach_file'], "Special Tool Information", value, name, 1) |
|
|
|
|
|
frappe.delete_doc("Instructions", d['name']) |
|
|
|
|
|
if val == True: |
|
|
|
|
|
return False, d['idx'] |
|
|
|
|
|
else: |
|
|
|
|
|
return True |
|
|
|
|
|
elif res2 == True: |
|
|
|
|
|
video_size_mb = get_file_size(d['attach_file']) |
|
|
|
|
|
if video_size_mb > 10: |
|
|
|
|
|
frappe.delete_doc('Instructions', d['name']) |
|
|
|
|
|
return (False, d['idx']) |
|
|
|
|
|
elif res3 == True: |
|
|
|
|
|
pdf_size_mb = get_file_size(d['attach_file']) |
|
|
|
|
|
if pdf_size_mb > 1: |
|
|
|
|
|
frappe.delete_doc('Instructions',d['name']) |
|
|
|
|
|
return (False, d['idx']) |
|
|
|
|
|
else: |
|
|
|
|
|
if res == False and res1==False: |
|
|
|
|
|
ret = res |
|
|
|
|
|
elif res2 == False: |
|
|
|
|
|
ret = res2 |
|
|
|
|
|
else: |
|
|
|
|
|
ret = res3 |
|
|
|
|
|
val = checking_image( |
|
|
|
|
|
d['attach_file'], 'Special Tool Information', value, name, 1) |
|
|
|
|
|
frappe.delete_doc('Instructions', d['name']) |
|
|
|
|
|
return (ret, d['idx']) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|