|
|
@ -9,6 +9,7 @@ from frappe.utils import cstr |
|
|
|
import datetime |
|
|
|
from smart_service.apis.app_user_login import input_validation |
|
|
|
import os |
|
|
|
import re |
|
|
|
current_db_name = frappe.conf.get("db_name") |
|
|
|
|
|
|
|
site_name = cstr(frappe.local.site) |
|
|
@ -435,16 +436,17 @@ def change_file_dir(): |
|
|
|
|
|
|
|
|
|
|
|
def file_not_exists(): |
|
|
|
|
|
|
|
file_data = frappe.db.sql(''' |
|
|
|
select parent,step_name,file from tabProcedure_Details where content_type = 'File' order by parent; ;''', as_dict=1) |
|
|
|
select parent,step_name,file,name from tabProcedure_Details where content_type = 'File' order by parent; ;''', as_dict=1) |
|
|
|
|
|
|
|
changed_file_list = [] |
|
|
|
for d in file_data: |
|
|
|
|
|
|
|
path = d['file'] |
|
|
|
isExist = os.path.exists(base_path + path) |
|
|
|
|
|
|
|
if not isExist: |
|
|
|
print(d) |
|
|
|
changed_file_list.append(d) |
|
|
|
|
|
|
|
file_path_not_exists = base_path + "/files/json_files/1.json" |
|
|
@ -455,15 +457,121 @@ def file_not_exists(): |
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
def remove_extra_spacces_in_file_path(): |
|
|
|
def remove_extra_spaces_in_file_path(): |
|
|
|
import re |
|
|
|
file_path_not_exists = base_path + "/files/json_files/1.json" |
|
|
|
with open(file_path_not_exists, 'r') as outfile: |
|
|
|
data = json.load(outfile) |
|
|
|
|
|
|
|
for d in data: |
|
|
|
res_str = re.sub("/files/ /", "/files/", d['file']) |
|
|
|
res_str = re.sub("/files/ ", "/files/", res_str) |
|
|
|
print(res_str) |
|
|
|
frappe.db.sql(f''' |
|
|
|
update tabProcedure_Details set file = '{res_str}' where name = '{d['name']}'; |
|
|
|
''') |
|
|
|
frappe.db.commit() |
|
|
|
|
|
|
|
|
|
|
|
def return_star_data(): |
|
|
|
data = frappe.db.sql(''' |
|
|
|
select content_type,content,name,parent,replace(content,'*','abcxyz ') as new_content from tabProcedure_Details where content like "%*%"; |
|
|
|
''', as_dict=1) |
|
|
|
return data |
|
|
|
|
|
|
|
|
|
|
|
def change_star_data(): |
|
|
|
count = frappe.db.sql(''' |
|
|
|
select count(*) from tabProcedure_Details where content like '%**%'; |
|
|
|
''', as_dict=1) |
|
|
|
print(count) |
|
|
|
updated_list = [] |
|
|
|
error_list = [] |
|
|
|
data = frappe.db.sql(''' |
|
|
|
select step_name,content_type,content,name,parent,replace(content,'**','abcxyz ') as new_content from tabProcedure_Details where content like '%**%'; |
|
|
|
''', as_dict=1) |
|
|
|
for v in data: |
|
|
|
try: |
|
|
|
result = re.split(r"abcxyz ", v['new_content'], flags=0) |
|
|
|
FLAG = 0 |
|
|
|
sts = '' |
|
|
|
if len(result) > 1: |
|
|
|
sts += result[0] |
|
|
|
for r in range(1, len(result)): |
|
|
|
if FLAG == 0: |
|
|
|
sts += '<b>' + result[r] + '</b>' |
|
|
|
FLAG = 1 |
|
|
|
else: |
|
|
|
sts += result[r] |
|
|
|
FLAG = 0 |
|
|
|
frappe.db.sql( |
|
|
|
f'''update tabProcedure_Details set content = "{sts}" where name = '{v['name']}'; ''') |
|
|
|
v['new_content'] = sts |
|
|
|
except Exception as e: |
|
|
|
error_list.append({v['name']: e}) |
|
|
|
updated_list.append(v) |
|
|
|
|
|
|
|
content_file = base_path + "/files/json_files/content_update.json" |
|
|
|
error_file = base_path + "/files/json_files/content_error.json" |
|
|
|
|
|
|
|
with open(error_file, 'w') as outfile: |
|
|
|
try: |
|
|
|
outfile.write(json.dumps(error_list)) |
|
|
|
except: |
|
|
|
pass |
|
|
|
with open(content_file, 'w') as outfile: |
|
|
|
try: |
|
|
|
outfile.write(json.dumps(updated_list)) |
|
|
|
except: |
|
|
|
pass |
|
|
|
return content_file |
|
|
|
|
|
|
|
|
|
|
|
def change_single_star_data(): |
|
|
|
count = frappe.db.sql(''' |
|
|
|
select count(*) from tabProcedure_Details where content like "%*%";''', as_dict=1) |
|
|
|
print(count) |
|
|
|
# updated_list = [] |
|
|
|
# error_list = [] |
|
|
|
# data = frappe.db.sql(''' |
|
|
|
# select parent,step_name,content_type,content,name,replace(content,'*','abcxyz ') as new_content from tabProcedure_Details where content like "%*%"; |
|
|
|
# ''', as_dict=1) |
|
|
|
|
|
|
|
# for v in data: |
|
|
|
|
|
|
|
# try: |
|
|
|
# result = re.split(r"abcxyz ", v['new_content'], flags=0) |
|
|
|
# sts = '<ul>' |
|
|
|
# if result[0] == '' and len(result) > 2: |
|
|
|
# for a in range(1, len(result)): |
|
|
|
# sts += '<li>' + result[a] + '</li> ' |
|
|
|
# sts += '</ul>' |
|
|
|
# # print(sts) |
|
|
|
# else: |
|
|
|
# sts += '<li>' + result[1] + '</li> ' |
|
|
|
# sts += '</ul>' |
|
|
|
# # print(sts) |
|
|
|
# frappe.db.sql( |
|
|
|
# f'''update tabProcedure_Details set content = "{sts}" where name = '{v['name']}'; ''') |
|
|
|
# frappe.db.commit() |
|
|
|
# v['new_content'] = sts |
|
|
|
# updated_list.append(v) |
|
|
|
|
|
|
|
# except Exception as e: |
|
|
|
# error_list.append({v['name']: e}) |
|
|
|
|
|
|
|
|
|
|
|
# content_file = base_path + "/files/json_files/content_single_star_update.json" |
|
|
|
# error_file = base_path + "/files/json_files/content_error_single_star.json" |
|
|
|
|
|
|
|
# with open(error_file, 'w') as outfile: |
|
|
|
# try: |
|
|
|
# outfile.write(json.dumps(error_list)) |
|
|
|
# except: |
|
|
|
# pass |
|
|
|
# with open(content_file, 'w') as outfile: |
|
|
|
# try: |
|
|
|
# outfile.write(json.dumps(updated_list)) |
|
|
|
# except: |
|
|
|
# pass |
|
|
|
# return content_file |
|
|
|