Compare commits

...

9 Commits

  1. 114
      smart_service/apis/master_api.py
  2. 5
      smart_service/apis/publish_api.py
  3. 2
      smart_service/transactions/doctype/procedure/procedure.js
  4. 10
      smart_service/transactions/doctype/procedure/procedure.py

114
smart_service/apis/master_api.py

@ -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

5
smart_service/apis/publish_api.py

@ -35,6 +35,7 @@ def custom_rate_limit(limit, seconds):
return "You hit the rate limit because of too many requests. Please try after sometime."
return 1
def get_parent_map(input_list, parameter):
parentChildMap = {}
for b in input_list:
@ -203,14 +204,14 @@ def json_grouping(args, language):
for k in docs_child:
if k['variant_mapping'] == d and k['system'] == i and k['sub_system'] == j:
# proc_details = frappe.db.sql('''select procedure_name, step_name, content_type, GROUP_CONCAT(case when content_type='Link' Then system_id else content end) as content,
# GROUP_CONCAT(file) as file,GROUP_CONCAT(DISTINCT idx order by idx) as display_order, idx from {}.tabProcedure_Details
# GROUP_CONCAT(file) as file,GROUP_CONCAT(DISTINCT idx order by idx) as display_order, idx from {}.tabProcedure_Details
# where parent ='{}' group by procedure_name,step_name,content_type,content order by idx asc; '''.format(
# current_db_name, k['procedure_link']), as_dict=True)
proc_details = frappe.db.sql('''select procedure_name, step_name, content_type, content,
file,idx as display_order,idx from {}.tabProcedure_Details
where parent ='{}' order by idx asc; '''.format(current_db_name, k['procedure_link']), as_dict=True)
proc_data = get_parent_map(
proc_details, 'procedure_name')
total_count += len(proc_data)

2
smart_service/transactions/doctype/procedure/procedure.js

@ -36,7 +36,7 @@ frappe.ui.form.on('Procedure', {
},
validate: function (frm) {
// var regex = /[@#$%^*\\[\]{}`~\\|\?]/;
var regex = /[@#$%^\\[\]{}`\\|\?]/;
var regex = /[@#$^\\[\]{}`\\|\?]/;
if (frm.doc.procedure_details) {
for (var i = 0; i < frm.doc.procedure_details.length; i++) {
if (regex.test(frm.doc.procedure_details[i].content) === true) {

10
smart_service/transactions/doctype/procedure/procedure.py

@ -14,9 +14,7 @@ class Procedure(Document):
if self.procedure_details:
for x in self.get("procedure_details"):
if x.content:
# try:
# title = x.content.encode('cp1252').decode('UTF-8')
# frappe.msgprint(str(x.as_dict())+":" +str(title))
res_str = re.sub("–", "", x.content)
res_str = re.sub("—", "", res_str)
res_str = re.sub("‘", "", res_str)
@ -24,12 +22,8 @@ class Procedure(Document):
res_str = re.sub("“", "", res_str)
res_str = re.sub("”", "", res_str)
res_str = re.sub("Â", "", res_str)
x.content = res_str
# frappe.msgprint(str(title))
# except Exception as e:
# frappe.log_error("validate encoding",frappe.get_traceback())
if x.content_type == "File":
if not x.file:
frappe.throw("Please choose the file in row no " + str(x.idx))

Loading…
Cancel
Save