@ -16,7 +16,7 @@ site_name = cstr(frappe.local.site)
BASE_URL = os . path . expanduser (
" ~ " ) + " /frappe-bench/sites/ " + site_name + " /public "
# base = os.path.expanduser(
# "~") + "/frappe-bench/sites/" + site_name
# "~") + "/frappe-bench/sites/" + site_name
date_format = " % Y- % m- %d % H: % M: % S. %f "
@ -179,8 +179,8 @@ def get_training_information(vehicle, language):
return False , e
@frappe . whitelist ( methods = [ ' POST ' ] , allow_guest = 1 )
def new_publish ( ) :
@frappe . whitelist ( methods = [ ' POST ' ] , allow_guest = 1 )
def new_publish_old ( ) :
req = json . loads ( frappe . request . data )
try :
module = req [ ' module ' ]
@ -296,25 +296,23 @@ def new_publish():
qp_rhs [ ' content ' ] = cnverted_data
elif module == ' Training Information ' :
base_path = BASE_URL + " / " + " training " + " / " + vehicle
scrom_path = base_path + " / " + " scrom "
base_path = BASE_URL + " / " + " training " + " / " + vehicle
scrom_path = base_path + " / " + " scrom "
# html_path = base_path +"/"+ "/html"
frappe . log_error ( str ( base_path ) )
flag , data = get_training_information ( vehicle , language )
for d in data :
if len ( d [ ' content ' ] ) > 0 :
for ch in d [ ' content ' ] :
if ch [ ' topic ' ] == ' SCROM ' :
scrom_folder_path = base_path + " / " + " scrom " + " / " + ch [ ' content ' ] . split ( " / " ) [ 2 ] . split ( " . " ) [ 0 ]
if not os . path . exists ( scrom_folder_path ) :
os . makedirs ( scrom_folder_path )
if ch [ ' content ' ] :
frappe . log_error ( str ( ch [ ' content ' ] ) )
with zipfile . ZipFile ( BASE_URL + ch [ ' content ' ] , ' r ' ) as zip_ref :
zip_ref . extractall ( path = scrom_folder_path )
ch [ ' content ' ] = scrom_folder_path + ch [ ' content ' ] . split ( " / " ) [ 2 ] . split ( " . " ) [ 0 ]
# cont=frappe.db.sql('''select content from `tabTraining Information Content Reference` where parent = %s and topic = 'SCROM' '''%(d['name']),as_dict=1)
# for d in data:
# if d['content']:
# for ch in d['content']:
# if ch['topic'] == 'SCROM' and ch['content']!=None:
# scrom_folder_path = base_path +"/"+ "scrom" + "/" + ch['content'].split("/")[2].split(".")[0]
# if not os.path.exists(scrom_folder_path):
# os.makedirs(scrom_folder_path)
# if ch['content']:
# frappe.log_error(str(ch['content']))
# with zipfile.ZipFile(BASE_URL+ch['content'], 'r') as zip_ref:
# zip_ref.extractall(path=scrom_folder_path)
# ch['content'] = scrom_folder_path + ch['content'].split("/")[2].split(".")[0]
# cont=frappe.db.sql('''select content from `tabTraining Information Content Reference` where parent = %s and topic = 'SCROM' '''%(d['name']),as_dict=1)
elif module == ' Mahindra Special Tool Information ' :
CLEANR_back_slash = re . compile ( " \" " )
@ -337,7 +335,7 @@ def new_publish():
elif module == ' Torque Information ' :
flag , data = get_torque_information ( variant , language )
else :
flag = False
data = ' No Module found '
@ -355,7 +353,7 @@ def new_publish():
@frappe . whitelist ( methods = [ ' POST ' ] , allow_guest = 1 )
def new_publish1 ( ) :
def new_publish ( ) :
req = json . loads ( frappe . request . data )
try :
module = req [ ' module ' ]
@ -366,8 +364,8 @@ def new_publish1():
val = input_validation ( req )
if val != ' ' or val != " " :
return { " status " : 0 , " error " : " Input parameter Missing: " + val }
# if val != '' or val != "" :
# return {"status": 0, "error": "Input parameter Missing: " + val }
data = [ ]
# Get Publish Type
publish_type = frappe . db . get_list (
@ -377,21 +375,20 @@ def new_publish1():
publish_type = publish_type [ 0 ] [ ' publish_type ' ]
else :
return { " status " : 0 , " error " : " Publish Type Not Set For: " + iid }
BASE_PATH = BASE_URL + " /files/json_files/phase2/ " + \
str ( vehicle ) + ' / ' + str ( language ) + ' / ' + str ( publish_type ) + ' / '
FULL_UPDATE_PATH = BASE_URL + " /files/json_files/phase2/ " + \
str ( vehicle ) + ' / ' + str ( language ) + ' / ' + \
" {} " . format ( publish_type ) + " _Full_Update/ "
str ( vehicle ) + ' / ' + str ( language ) + ' / ' + str ( publish_type ) + ' / '
if module == ' Feature Finder ' :
FULL_UPDATE_PATH = BASE_URL + " /files/json_files/phase2/ " + \
str ( vehicle ) + ' / ' + str ( language ) + ' / ' + \
" {} " . format ( publish_type ) + " _Full_Update/ "
FULL_UPDATE_PATH_FILE = FULL_UPDATE_PATH + \
vehicle . replace ( ' ' , ' - ' ) + ' -feature_finder_full_update ' + ' .json '
LATEST_GLOBAL_PATH = BASE_URL + " /files/json_files/phase2/ " + \
str ( vehicle ) + ' / ' + str ( language ) + ' / ' + " Global_Full_Update/ "
LATEST_GLOBAL_FILE = LATEST_GLOBAL_PATH + \
vehicle . replace ( ' ' , ' - ' ) + ' -feature_finder_full_update ' + ' .json '
FULL_UPDATE_PATH_FILE = FULL_UPDATE_PATH + \
vehicle . replace ( ' ' , ' - ' ) + ' -feature_finder_full_update ' + ' .json '
LATEST_GLOBAL_PATH = BASE_URL + " /files/json_files/phase2/ " + \
str ( vehicle ) + ' / ' + str ( language ) + ' / ' + " Global_Full_Update/ "
LATEST_GLOBAL_FILE = LATEST_GLOBAL_PATH + \
vehicle . replace ( ' ' , ' - ' ) + ' -feature_finder_full_update ' + ' .json '
if module == ' Feature Finder ' :
# if publish_type == 'Internal':
if os . path . isfile ( FULL_UPDATE_PATH_FILE ) :
with open ( FULL_UPDATE_PATH_FILE ) as outfile :
@ -412,50 +409,145 @@ def new_publish1():
data = data . get ( variant )
elif module == ' Repair/Service Check Sheet ' :
with open ( BASE_PATH + str ( vehicle ) + ' -repair_check_sheet.json ' ) as outfile :
data = json . load ( outfile )
# data = data['data']
# filter_json = filter_publish_json(data, variant)
# data = filter_json
data = data . get ( ' data ' )
data = data . get ( variant )
FULL_UPDATE_FOLDER = BASE_URL + " /files/json_files/phase2/ " + \
str ( vehicle ) + ' / ' + str ( language ) + ' / ' + \
" {} " . format ( publish_type ) + " / "
FULL_UPDATE_PATH_FILE = FULL_UPDATE_FOLDER + \
vehicle . replace ( ' ' , ' - ' ) + ' -repair_check_sheet.json '
LATEST_GLOBAL_PATH = BASE_URL + " /files/json_files/phase2/ " + \
str ( vehicle ) + ' / ' + str ( language ) + ' / ' + " Global/ "
LATEST_GLOBAL_FILE = LATEST_GLOBAL_PATH + \
vehicle . replace ( ' ' , ' - ' ) + ' -repair_check_sheet.json '
if os . path . isfile ( FULL_UPDATE_PATH_FILE ) :
with open ( FULL_UPDATE_PATH_FILE ) as outfile :
data = json . load ( outfile )
data = data . get ( ' data ' )
# data = data.get(variant)
else :
with open ( LATEST_GLOBAL_FILE ) as outfile :
data = json . load ( outfile )
data = data . get ( ' data ' )
elif module == ' QWIK Service ' :
with open ( BASE_PATH + str ( vehicle ) + ' -qwik_service.json ' ) as outfile :
data = json . load ( outfile )
frappe . log_error ( str ( publish_type ) )
FULL_UPDATE_PATH = BASE_URL + " /files/json_files/phase2/ " + \
str ( vehicle ) + ' / ' + str ( language ) + ' / ' + \
" {} " . format ( publish_type ) + " _Full_Update/ "
FULL_UPDATE_PATH_FILE = FULL_UPDATE_PATH + \
vehicle . replace ( ' ' , ' - ' ) + ' -qwik_service_full_update.json '
LATEST_GLOBAL_PATH = BASE_URL + " /files/json_files/phase2/ " + \
str ( vehicle ) + ' / ' + str ( language ) + ' / ' + " Global_Full_Update/ "
LATEST_GLOBAL_FILE = LATEST_GLOBAL_PATH + \
vehicle . replace ( ' ' , ' - ' ) + ' -qwik_service_full_update.json '
# if publish_type == 'Internal':
if os . path . isfile ( FULL_UPDATE_PATH_FILE ) :
with open ( FULL_UPDATE_PATH_FILE ) as outfile :
data = json . load ( outfile )
# data = data['data']
# filter_json = filter_publish_json(data, variant)
# data = filter_json
data = data . get ( ' data ' )
data = data . get ( variant )
data = data . get ( ' data ' )
data = data . get ( variant )
else :
with open ( LATEST_GLOBAL_FILE ) as outfile :
data = json . load ( outfile )
# data = data['data']
# filter_json = filter_publish_json(data, variant)
# data = filter_json
data = data . get ( ' data ' )
data = data . get ( variant )
elif module == ' Training Information ' :
with open ( BASE_PATH + str ( vehicle ) + ' -training_information.json ' ) as outfile :
data = json . load ( outfile )
data = data . get ( ' data ' )
# data = data.get(variant)
FULL_UPDATE_FOLDER = BASE_URL + " /files/json_files/phase2/ " + \
str ( vehicle ) + ' / ' + str ( language ) + ' / ' + \
" {} " . format ( publish_type ) + " / "
FULL_UPDATE_PATH_FILE = FULL_UPDATE_FOLDER + \
vehicle . replace ( ' ' , ' - ' ) + ' -training_information.json '
LATEST_GLOBAL_PATH = BASE_URL + " /files/json_files/phase2/ " + \
str ( vehicle ) + ' / ' + str ( language ) + ' / ' + " Global/ "
LATEST_GLOBAL_FILE = LATEST_GLOBAL_PATH + \
vehicle . replace ( ' ' , ' - ' ) + ' -training_information.json '
if os . path . isfile ( FULL_UPDATE_PATH_FILE ) :
with open ( FULL_UPDATE_PATH_FILE ) as outfile :
data = json . load ( outfile )
data = data . get ( ' data ' )
else :
with open ( LATEST_GLOBAL_FILE ) as outfile :
data = json . load ( outfile )
data = data . get ( ' data ' )
elif module == ' Mahindra Special Tool Information ' :
FULL_UPDATE_PATH = BASE_URL + " /files/json_files/phase2/ " + \
str ( vehicle ) + ' / ' + \
" {} " . format ( publish_type ) + " _Full_Update/ "
FULL_UPDATE_PATH_FILE = FULL_UPDATE_PATH + \
vehicle . replace ( ' ' , ' - ' ) + ' -special_tool.json '
LATEST_GLOBAL_PATH = BASE_URL + " /files/json_files/phase2/ " + \
str ( vehicle ) + ' / ' + " Global_Full_Update/ "
LATEST_GLOBAL_FILE = LATEST_GLOBAL_PATH + \
vehicle . replace ( ' ' , ' - ' ) + ' -special_tool.json '
if os . path . isfile ( FULL_UPDATE_PATH_FILE ) :
with open ( FULL_UPDATE_PATH_FILE ) as outfile :
data = json . load ( outfile )
data = data . get ( ' data ' )
with open ( BASE_PATH + str ( vehicle ) + ' -special_tool_information.json ' ) as outfile :
data = json . load ( outfile )
# data = data['data']
# filter_json = filter_publish_json(data, variant)
# data = filter_json
data = data . get ( ' data ' )
data = data . get ( variant )
else :
with open ( LATEST_GLOBAL_FILE ) as outfile :
data = json . load ( outfile )
data = data . get ( ' data ' )
elif module == ' PDI Inspection ' :
pass
elif module == ' Torque Manual ' :
with open ( BASE_PATH + str ( vehicle ) + ' -torque_manual.json ' ) as outfile :
data = json . load ( outfile )
FULL_UPDATE_PATH = BASE_URL + " /files/json_files/phase2/ " + \
str ( vehicle ) + ' / ' + str ( language ) + ' / ' + \
" {} " . format ( publish_type ) + " _Full_Update/ "
FULL_UPDATE_PATH_FILE = FULL_UPDATE_PATH + \
vehicle . replace ( ' ' , ' - ' ) + ' -torque_manual_full_update.json '
LATEST_GLOBAL_PATH = BASE_URL + " /files/json_files/phase2/ " + \
str ( vehicle ) + ' / ' + str ( language ) + \
' / ' + " Global_Full_Update/ "
LATEST_GLOBAL_FILE = LATEST_GLOBAL_PATH + \
vehicle . replace ( ' ' , ' - ' ) + ' -torque_manual_full_update.json '
# if publish_type == 'Internal':
if os . path . isfile ( FULL_UPDATE_PATH_FILE ) :
with open ( FULL_UPDATE_PATH_FILE ) as outfile :
data = json . load ( outfile )
# data = data['data']
# filter_json = filter_publish_json(data, variant)
# data = filter_json
data = data . get ( ' data ' )
data = data . get ( variant )
else :
else :
data = ' No Module found '
with open ( LATEST_GLOBAL_FILE ) as outfile :
data = json . load ( outfile )
# data = data['data']
# filter_json = filter_publish_json(data, variant)
# data = filter_json
data = data . get ( ' data ' )
data = data . get ( variant )
torque_column_mapping = frappe . db . sql (
f ''' select idx as display_order, concat( ' col ' ,idx) as column_id,column_name from `tabTorque Column Mapping` where parent = ' { variant } ' order by idx; ''' , as_dict = 1 )
data = { ' torque_manual_mapping ' : torque_column_mapping , ' torque_manual_data ' : data }
return { ' status ' : 1 , ' error ' : None , ' data ' : data }
@ -525,8 +617,9 @@ def get_training_information(vehicle, language):
training_information_details = frappe . db . sql ( ''' select name,vehicle,category,display_order,active_status,my_id,keywords from
` tabTraining Information ` where vehicle = ' %s ' & & language = ' %s ' ; ''' % (vehicle, language), as_dict=1)
for i in training_information_details :
i [ ' content ' ] = frappe . db . sql ( ''' select idx as ' display_order ' ,topic,content from `tabTraining Information Content Reference`
i [ ' content ' ] = frappe . db . sql ( ''' select idx as ' display_order ' ,topic as file_type,file_url,file_name,scrom_file_url from `tabTraining Information Content Reference`
where parent = ' %s ' order by display_order ; ''' % (i[ ' name ' ]), as_dict=1)
return True , training_information_details
except Exception as e :
raise e
@ -536,7 +629,7 @@ def get_training_information(vehicle, language):
# def test_html(vehicle):
# base_path = BASE_URL + "/" + "/training" +"/"+ vehicle
# # Folder creation
# scrom_path = base_path +"/"+ "/scrom"
# scrom_path = base_path +"/"+ "/scrom"
# html_path = base_path +"/"+ "/html"
# try:
# # if not os.path.exists(base_path):
@ -547,7 +640,7 @@ def get_training_information(vehicle, language):
# if not os.path.exists(html_path):
# os.makedirs(html_path)
# # Create zip file
# # try:
# # if path:
@ -626,9 +719,6 @@ def input_validation(req):
return sts
@frappe . whitelist ( )
def get_published_data ( ) :
data = frappe . db . sql ( """ select vehicle,variant,language,publish_type from `tabPublish` where not in (select vehicle,variant,language,publish_type from