Browse Source

MST File validation

version2
venkataakhil 1 year ago
parent
commit
ffa5051eca
  1. 6
      smart_service/phase_2/doctype/instructions/instructions.json
  2. 41
      smart_service/phase_2/doctype/special_tool_information/special_tool_information.js
  3. 13
      smart_service/phase_2/doctype/special_tool_information/special_tool_information.json
  4. 64
      smart_service/phase_2/doctype/special_tool_information/special_tool_information.py
  5. 28
      smart_service/phase_2/doctype/training_information/training_information.js

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

@ -32,9 +32,11 @@
"fieldname": "content", "fieldname": "content",
"fieldtype": "Small Text", "fieldtype": "Small Text",
"in_list_view": 1, "in_list_view": 1,
"label": "Content" "label": "Content",
"read_only_depends_on": "// eval:doc.content_type=='Image'"
}, },
{ {
"depends_on": "// eval:doc.content_type == 'Image'",
"fieldname": "attach_file", "fieldname": "attach_file",
"fieldtype": "Attach", "fieldtype": "Attach",
"in_list_view": 1, "in_list_view": 1,
@ -51,7 +53,7 @@
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"istable": 1, "istable": 1,
"links": [], "links": [],
"modified": "2023-10-04 11:06:07.232457", "modified": "2023-10-05 09:59:05.591167",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Phase-2", "module": "Phase-2",
"name": "Instructions", "name": "Instructions",

41
smart_service/phase_2/doctype/special_tool_information/special_tool_information.js

@ -73,6 +73,25 @@ frappe.ui.form.on('Special Tool Information', {
if (!frm.is_new()){ if (!frm.is_new()){
teb_validation(frm) teb_validation(frm)
} }
if (frm.doc.instructions) {
frappe.call({
method: "smart_service.phase_2.doctype.special_tool_information.special_tool_information.file_validation_child",
args: {
name: frm.doc.name,
value:"instructions"
},
callback: function (r) {
console.log(r.message, "----file validation size-------")
if (r.message && r.message[0] == false) {
if (r.message[1]) {
frappe.validated = false;
frm.reload_doc()
frappe.throw("In Special Tool information content " + r.message[1] + " row was invalid file type")
}
}
}
})
}
}, },
}); });
function teb_validation(frm){ function teb_validation(frm){
@ -158,4 +177,26 @@ frappe.ui.form.on('Instructions', {
} }
refresh_field("instructions"); refresh_field("instructions");
}, },
content_type: function (frm, cdt, cdn) {
// refresh_field("instructions")
var select_value = locals[cdt][cdn];
var x = select_value.idx - 1;
// let my_row = frm.fields_dict.content.grid.grid_rows[x];
if (select_value.content_type == 'Image' || select_value.content_type == 'Video' || select_value.content_type == 'PDF'){
cur_frm.get_field("instructions").grid.grid_rows[x].columns.content.df.read_only = 1;
cur_frm.get_field("instructions").grid.grid_rows[x].columns.attach_file.df.read_only = 0;
cur_frm.get_field("instructions").grid.grid_rows[x].columns.step_name.df.read_only = 0;
cur_frm.get_field("instructions").grid.grid_rows[x].columns.title.df.read_only = 0;
cur_frm.refresh_field("content_type")
}
else {
cur_frm.get_field("instructions").grid.grid_rows[x].columns.attach_file.df.read_only = 1;
cur_frm.get_field("instructions").grid.grid_rows[x].columns.content.df.read_only = 0;
cur_frm.get_field("instructions").grid.grid_rows[x].columns.step_name.df.read_only = 0;
cur_frm.get_field("instructions").grid.grid_rows[x].columns.title.df.read_only = 0;
cur_frm.refresh_fields("content_type")
}
cur_frm.refresh_fields("content_type")
refresh_field("instructions");
},
}) })

13
smart_service/phase_2/doctype/special_tool_information/special_tool_information.json

@ -11,9 +11,10 @@
"column_break_cyo0a", "column_break_cyo0a",
"vehicle", "vehicle",
"tool_type", "tool_type",
"keywords",
"image", "image",
"image_preview",
"aggregate_image", "aggregate_image",
"aggregate_image_preview",
"column_break_m3p9i", "column_break_m3p9i",
"category", "category",
"aggregate_name", "aggregate_name",
@ -26,7 +27,7 @@
"my_id", "my_id",
"section_break_e91wx", "section_break_e91wx",
"instructions", "instructions",
"image_preview" "keywords"
], ],
"fields": [ "fields": [
{ {
@ -43,7 +44,8 @@
"fieldname": "display_order", "fieldname": "display_order",
"fieldtype": "Int", "fieldtype": "Int",
"in_list_view": 1, "in_list_view": 1,
"label": "Display Order" "label": "Display Order",
"reqd": 1
}, },
{ {
"fieldname": "my_id", "fieldname": "my_id",
@ -89,6 +91,8 @@
"depends_on": "eval:doc.category !='TEB';", "depends_on": "eval:doc.category !='TEB';",
"fieldname": "aggregate_name", "fieldname": "aggregate_name",
"fieldtype": "Data", "fieldtype": "Data",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Aggregate Name", "label": "Aggregate Name",
"reqd": 1, "reqd": 1,
"set_only_once": 1 "set_only_once": 1
@ -123,6 +127,8 @@
{ {
"fieldname": "tool_type", "fieldname": "tool_type",
"fieldtype": "Select", "fieldtype": "Select",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Tool Type", "label": "Tool Type",
"options": "New Tool\nCarry Over", "options": "New Tool\nCarry Over",
"set_only_once": 1 "set_only_once": 1
@ -146,6 +152,7 @@
"fieldtype": "Column Break" "fieldtype": "Column Break"
}, },
{ {
"depends_on": "eval:doc.image;",
"fieldname": "image_preview", "fieldname": "image_preview",
"fieldtype": "Image", "fieldtype": "Image",
"label": "Image Preview", "label": "Image Preview",

64
smart_service/phase_2/doctype/special_tool_information/special_tool_information.py

@ -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'])

28
smart_service/phase_2/doctype/training_information/training_information.js

@ -22,7 +22,7 @@ frappe.ui.form.on('Training Information', {
}, },
after_save: function (frm) { after_save: function (frm) {
if (frm.doc.content) { if (frm.doc.content) {
frappe.call({ frappe.call({
method: "smart_service.phase_2.doctype.training_information.training_information.file_validation_child", method: "smart_service.phase_2.doctype.training_information.training_information.file_validation_child",
args: { args: {
name: frm.doc.name, name: frm.doc.name,
@ -82,18 +82,18 @@ frappe.ui.form.on('Training Information Content Reference',{
cur_frm.refresh_field("content"); cur_frm.refresh_field("content");
cur_frm.refresh_field(); cur_frm.refresh_field();
}, },
validate:function(frm){ // validate:function(frm){
let task_index = row.docfields.findIndex(x => x.fieldname === "content"); // let task_index = row.docfields.findIndex(x => x.fieldname === "content");
if (row.doc.asset_type == 'Image' || row.doc.asset_type == 'Video') { // if (row.doc.asset_type == 'Image' || row.doc.asset_type == 'Video') {
row.docfields[task_index].read_only = 0; // row.docfields[task_index].read_only = 0;
// cur_frm.get_field("tool_usage_content").grid.grid_rows[x].columns.content.df.set=[]; // // cur_frm.get_field("tool_usage_content").grid.grid_rows[x].columns.content.df.set=[];
} else { // } else {
row.docfields[task_index].read_only = 1; // row.docfields[task_index].read_only = 1;
} // }
row.toggle_editable_row(true); // row.toggle_editable_row(true);
refresh_field("content"); // refresh_field("content");
cur_frm.refresh_field("content"); // cur_frm.refresh_field("content");
refresh_field(); // refresh_field();
} // }
}) })
Loading…
Cancel
Save