Browse Source

File validation for MST

version2
venkataakhil 12 months ago
parent
commit
33b925e8f3
  1. 2
      smart_service/apis/v2/master.py
  2. 6
      smart_service/phase_2/doctype/instructions/instructions.json
  3. 8
      smart_service/phase_2/doctype/qwik_service_content/qwik_service_content.py
  4. 52
      smart_service/phase_2/doctype/special_tool_information/special_tool_information.js
  5. 40
      smart_service/phase_2/doctype/special_tool_information/special_tool_information.json
  6. 36
      smart_service/phase_2/doctype/special_tool_information/special_tool_information.py

2
smart_service/apis/v2/master.py

@ -270,7 +270,7 @@ def get_special_tool_information(vehicle):
pdf,image,video,keywords,display_order,my_id,active_status from `tabSpecial Tool Information`
where vehicle= '%s' ;''' % (vehicle), as_dict=1)
for s in special_tool_information:
s['instructions'] = frappe.db.sql('''select idx as 'display_order',step_name,content_type,content,attach_file,title
s['instructions'] = frappe.db.sql('''select idx as 'display_order',step_name, content_type, content,attach_file,title
from `tabInstructions` where parent = '%s' order by display_order;''' % (s['name']), as_dict=1)
return True, special_tool_information
except Exception as e:

6
smart_service/phase_2/doctype/instructions/instructions.json

@ -8,9 +8,9 @@
"field_order": [
"step_name",
"content_type",
"title",
"content",
"attach_file",
"title"
"attach_file"
],
"fields": [
{
@ -53,7 +53,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2023-10-05 09:59:05.591167",
"modified": "2023-10-05 17:29:43.636314",
"modified_by": "Administrator",
"module": "Phase-2",
"name": "Instructions",

8
smart_service/phase_2/doctype/qwik_service_content/qwik_service_content.py

@ -5,4 +5,10 @@
from frappe.model.document import Document
class QwikServiceContent(Document):
pass
def validate(self):
try:
if self.is_new():
if self.content:
self.content=self.content.strip()
except Exception as e:
raise e

52
smart_service/phase_2/doctype/special_tool_information/special_tool_information.js

@ -44,6 +44,7 @@ frappe.ui.form.on('Special Tool Information', {
}
}).then(records => {
if (records.length) {
console.log(records[0].name)
frappe.db.set_value('Special Tool Information', records[0].name, {
display_order: original_display_order
}).then(r => {
@ -64,6 +65,57 @@ frappe.ui.form.on('Special Tool Information', {
}
frm.doc.name = frm.doc.vehicle + "-" + frm.doc.tool_type + "-" + frm.doc.category + "-" + frm.doc.aggregate_name
if (frm.doc.image) {
frappe.call({
method: "smart_service.phase_2.doctype.special_tool_information.special_tool_information.file_validation",
args: {
image: frm.doc.image,
name: frm.doc.name,
value: "image"
},
callback: function (r) {
console.log(r.message, "r.message")
if (r.message && r.message[0] == false) {
frm.doc.upload_file = ""
frm.refresh_fields("image")
if (r.message[1] == 1) {
frappe.validated = false;
frappe.msgprint("Invalid file type")
}
if (r.message[1] == 2) {
frappe.validated = false;
frappe.msgprint("Invalid file size")
}
}
}
})
}
if (frm.doc.aggregate_image) {
frappe.call({
method: "smart_service.phase_2.doctype.special_tool_information.special_tool_information.file_validation",
args: {
image: frm.doc.aggregate_image,
name: frm.doc.name,
value: "aggregate_image"
},
callback: function (r) {
console.log(r.message, "r.message")
if (r.message && r.message[0] == false) {
frm.doc.upload_file = ""
frm.refresh_fields("aggregate_image")
if (r.message[1] == 1) {
frappe.validated = false;
frappe.msgprint("Invalid file type")
}
if (r.message[1] == 2) {
frappe.validated = false;
frappe.msgprint("Invalid file size")
}
}
}
})
}
},
category: function (frm, cdt, cdn) {
teb_validation(frm)

40
smart_service/phase_2/doctype/special_tool_information/special_tool_information.json

@ -11,23 +11,24 @@
"column_break_cyo0a",
"vehicle",
"tool_type",
"image",
"image_preview",
"aggregate_image",
"aggregate_image_preview",
"tool_name",
"keywords",
"column_break_m3p9i",
"category",
"aggregate_name",
"tool_name",
"pdf",
"aggregate_image",
"aggregate_image_preview",
"column_break_wvkn2",
"active_status",
"display_order",
"video",
"pdf",
"image",
"image_preview",
"my_id",
"section_break_e91wx",
"instructions",
"keywords"
"image_preview"
],
"fields": [
{
@ -45,6 +46,7 @@
"fieldtype": "Int",
"in_list_view": 1,
"label": "Display Order",
"non_negative": 1,
"reqd": 1
},
{
@ -52,7 +54,8 @@
"fieldtype": "Int",
"hidden": 1,
"in_list_view": 1,
"label": "My ID"
"label": "My ID",
"non_negative": 1
},
{
"default": "0",
@ -72,6 +75,8 @@
{
"fieldname": "active_status",
"fieldtype": "Select",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Active Status",
"options": "Active\nInactive"
},
@ -104,6 +109,7 @@
"in_standard_filter": 1,
"label": "Category",
"options": "Maintenance Service Category(MS)\nRepair Service Category(RS)\nOverhaul Service Category(OS)\nTEB",
"reqd": 1,
"set_only_once": 1
},
{
@ -122,7 +128,8 @@
"fieldname": "instructions",
"fieldtype": "Table",
"label": "Instructions",
"options": "Instructions"
"options": "Instructions",
"reqd": 1
},
{
"fieldname": "tool_type",
@ -131,6 +138,7 @@
"in_standard_filter": 1,
"label": "Tool Type",
"options": "New Tool\nCarry Over",
"reqd": 1,
"set_only_once": 1
},
{
@ -161,12 +169,22 @@
{
"fieldname": "tool_name",
"fieldtype": "Data",
"label": "Tool Name"
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Tool Name",
"reqd": 1
},
{
"depends_on": "eval:doc.aggregate_image;",
"fieldname": "aggregate_image_preview",
"fieldtype": "Image",
"label": "Aggregate Image Preview",
"options": "aggregate_image"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-10-04 12:06:21.324200",
"modified": "2023-10-04 17:45:57.350572",
"modified_by": "Administrator",
"module": "Phase-2",
"name": "Special Tool Information",

36
smart_service/phase_2/doctype/special_tool_information/special_tool_information.py

@ -27,13 +27,45 @@ class SpecialToolInformation(Document):
if not self.is_new() and self.published == 1:
self.published = 0
@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
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 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
else:
val = checking_image(image, 'Special Tool Information', value, name)
if res == False:
ret = res
else:
ret = res1
return ret, 1
@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)
"""select * from `tabInstructions` where parent='%s'"""%(name), as_dict=1)
for d in child_data:
if d['attach_file']:
res = False
@ -80,6 +112,6 @@ def file_validation_child(name, value=None):
d['attach_file'], 'Special Tool Information', value, name, 1)
frappe.delete_doc('Instructions', d['name'])
return (ret, d['idx'])

Loading…
Cancel
Save