administrator
1 year ago
129 changed files with 665479 additions and 3911 deletions
@ -1,2 +1,7 @@ |
|||
#Ignore all pyc files |
|||
.DS_Store |
|||
*.egg-info |
|||
*.swp |
|||
tags |
|||
smart_service/docs/current |
|||
*.pyc |
|||
__pycache__/ |
|||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,8 +1,161 @@ |
|||
# Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors |
|||
# For license information, please see license.txt |
|||
|
|||
# import frappe |
|||
import frappe |
|||
from frappe.model.document import Document |
|||
|
|||
class Circular(Document): |
|||
pass |
|||
def validate(self): |
|||
if self.description and len(self.description)>500: |
|||
frappe.throw("Description should be less than or equal to 850 characters ") |
|||
|
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def file_validation(image, name): |
|||
if image: |
|||
res = check_img_ext(image) |
|||
res1 = check_png_ext(image) |
|||
res2 = check_pdf_ext(image) |
|||
if res == True or res1 == True or res2 == True: |
|||
return True |
|||
else: |
|||
return False, 1 |
|||
# if res== True: |
|||
# pass |
|||
# else: |
|||
# width, height, size = details_of_image(image) |
|||
# if width > 49 or height > 49 or size > 65 and image: |
|||
# val = checking_image(image, "Circular","circular_image", name) |
|||
# if val: |
|||
# return False, 2 |
|||
|
|||
|
|||
|
|||
# if res2 == True: |
|||
# pass |
|||
# else: |
|||
# width, height, size = details_of_image(image) |
|||
# if width > 49 or height > 49 or size > 65 and image: |
|||
# val = checking_image(image, "Circular", |
|||
# "circular_image", name) |
|||
# if val == True: |
|||
# return False, 2 |
|||
# else: |
|||
# return True |
|||
# else: |
|||
# val = checking_image(image, "Circular", |
|||
# "circular_image", name) |
|||
if res == False: |
|||
ret = res |
|||
elif res1 == False: |
|||
ret = res1 |
|||
else: |
|||
ret = res2 |
|||
return ret, 1 |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def check_pdf_ext(path): |
|||
if path: |
|||
ext = path.split()[-1] |
|||
if ext.lower().endswith('.pdf'): |
|||
return True |
|||
else: |
|||
return False |
|||
else: |
|||
return False |
|||
|
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def check_img_ext(path): |
|||
if path: |
|||
ext = path.split()[-1] |
|||
if ext.lower().endswith('.jpg') or ext.lower().endswith('.jpeg'): |
|||
return True |
|||
else: |
|||
return False |
|||
else: |
|||
return False |
|||
|
|||
|
|||
@frappe.whitelist() |
|||
def check_png_ext(path): |
|||
if path: |
|||
ext = path.split()[-1] |
|||
if ext.lower().endswith('.png'): |
|||
return True |
|||
else: |
|||
return False |
|||
else: |
|||
return False |
|||
|
|||
|
|||
|
|||
def details_of_image(image_file): |
|||
try: |
|||
# Image dimension validation |
|||
import os |
|||
from PIL import Image |
|||
if image_file.startswith('/private/'): |
|||
filepath = get_absolute_path(image_file, True) |
|||
else: |
|||
filepath = get_absolute_path(image_file) |
|||
img = Image.open(filepath) |
|||
width = img.width |
|||
height = img.height |
|||
size = os.stat(filepath) |
|||
size=size[6]/1024 |
|||
return width, height,size |
|||
except Exception as e: |
|||
raise e |
|||
|
|||
|
|||
def get_absolute_path(file_name, is_private=False): |
|||
try: |
|||
if file_name.startswith('/files/'): |
|||
file_name = file_name[7:] |
|||
else: |
|||
file_name = file_name[15:] |
|||
return frappe.utils.get_bench_path() + "/sites/" + frappe.utils.get_path('private' if is_private else 'public', |
|||
'files', file_name)[2:] |
|||
except Exception as e: |
|||
frappe.log_error("get_absolute_path", frappe.get_traceback()) |
|||
|
|||
|
|||
|
|||
def checking_image(file_url, attached_to_doctype, attached_to_field, docname, is_child=None): |
|||
try: |
|||
import time |
|||
time.sleep(1) |
|||
if docname.startswith('new'): |
|||
image_name = frappe.db.get_list("File", fields={"name"}, filters={"file_url": file_url, |
|||
"attached_to_doctype": attached_to_doctype, |
|||
"attached_to_field": attached_to_field, |
|||
"attached_to_name": docname}) |
|||
|
|||
else: |
|||
image_name = frappe.db.get_list("File", fields={"name"}, filters={"file_url": file_url, |
|||
"attached_to_doctype": attached_to_doctype, |
|||
"attached_to_field": attached_to_field}) |
|||
|
|||
image_name = frappe.db.sql(f"""select name from `tabFile` where file_url='{file_url}' and attached_to_doctype='{attached_to_doctype}' and |
|||
attached_to_field='{attached_to_field}'""",as_dict=1) |
|||
# frappe.msgprint("data-"+str(file_url)+"-"+str(attached_to_doctype)+"-"+str(attached_to_field)+"-"+str(docname)) |
|||
if not attached_to_doctype == "Symbol Scanner" and is_child != 1: |
|||
frappe.db.sql( |
|||
'''UPDATE `tab{0}` SET {2} = '' where name = "{1}"'''.format(attached_to_doctype, docname, |
|||
attached_to_field)) |
|||
frappe.db.commit() |
|||
if attached_to_doctype == "Symbol Scanner": |
|||
frappe.db.set_value( |
|||
"Symbol Scanner", "Symbol Scanner", attached_to_field, "") |
|||
|
|||
if len(image_name) > 0: |
|||
frappe.delete_doc('File', image_name[0]['name']) |
|||
return True |
|||
|
|||
except Exception as e: |
|||
frappe.log_error("Checking images", frappe.get_traceback()) |
|||
|
|||
|
@ -0,0 +1,8 @@ |
|||
// Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and contributors
|
|||
// For license information, please see license.txt
|
|||
|
|||
frappe.ui.form.on('Refresh Token', { |
|||
// refresh: function(frm) {
|
|||
|
|||
// }
|
|||
}); |
@ -0,0 +1,77 @@ |
|||
{ |
|||
"actions": [], |
|||
"allow_rename": 1, |
|||
"creation": "2023-02-02 11:54:48.885036", |
|||
"doctype": "DocType", |
|||
"editable_grid": 1, |
|||
"engine": "InnoDB", |
|||
"field_order": [ |
|||
"access_token", |
|||
"refresh_token", |
|||
"column_break_3", |
|||
"access_expiry_time", |
|||
"refresh_expiry_time", |
|||
"user", |
|||
"device_id" |
|||
], |
|||
"fields": [ |
|||
{ |
|||
"fieldname": "access_token", |
|||
"fieldtype": "Small Text", |
|||
"label": "Access Token" |
|||
}, |
|||
{ |
|||
"fieldname": "refresh_token", |
|||
"fieldtype": "Small Text", |
|||
"label": "Refresh Token" |
|||
}, |
|||
{ |
|||
"fieldname": "column_break_3", |
|||
"fieldtype": "Column Break" |
|||
}, |
|||
{ |
|||
"fieldname": "access_expiry_time", |
|||
"fieldtype": "Datetime", |
|||
"label": "Access Expiry Time" |
|||
}, |
|||
{ |
|||
"fieldname": "refresh_expiry_time", |
|||
"fieldtype": "Datetime", |
|||
"label": "Refresh Expiry Time" |
|||
}, |
|||
{ |
|||
"fieldname": "user", |
|||
"fieldtype": "Link", |
|||
"label": "User", |
|||
"options": "User" |
|||
}, |
|||
{ |
|||
"fieldname": "device_id", |
|||
"fieldtype": "Data", |
|||
"label": "Device ID" |
|||
} |
|||
], |
|||
"index_web_pages_for_search": 1, |
|||
"links": [], |
|||
"modified": "2023-06-24 12:22:02.491908", |
|||
"modified_by": "Administrator", |
|||
"module": "Add Ons", |
|||
"name": "Refresh Token", |
|||
"owner": "Administrator", |
|||
"permissions": [ |
|||
{ |
|||
"create": 1, |
|||
"delete": 1, |
|||
"email": 1, |
|||
"export": 1, |
|||
"print": 1, |
|||
"read": 1, |
|||
"report": 1, |
|||
"role": "System Manager", |
|||
"share": 1, |
|||
"write": 1 |
|||
} |
|||
], |
|||
"sort_field": "modified", |
|||
"sort_order": "DESC" |
|||
} |
@ -0,0 +1,8 @@ |
|||
# Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and contributors |
|||
# For license information, please see license.txt |
|||
|
|||
# import frappe |
|||
from frappe.model.document import Document |
|||
|
|||
class RefreshToken(Document): |
|||
pass |
@ -0,0 +1,8 @@ |
|||
# Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and Contributors |
|||
# See license.txt |
|||
|
|||
# import frappe |
|||
import unittest |
|||
|
|||
class TestRefreshToken(unittest.TestCase): |
|||
pass |
@ -0,0 +1,8 @@ |
|||
# Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and Contributors |
|||
# See license.txt |
|||
|
|||
# import frappe |
|||
import unittest |
|||
|
|||
class TestTokenSettings(unittest.TestCase): |
|||
pass |
@ -0,0 +1,8 @@ |
|||
// Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and contributors
|
|||
// For license information, please see license.txt
|
|||
|
|||
frappe.ui.form.on('Token Settings', { |
|||
// refresh: function(frm) {
|
|||
|
|||
// }
|
|||
}); |
@ -0,0 +1,48 @@ |
|||
{ |
|||
"actions": [], |
|||
"allow_rename": 1, |
|||
"creation": "2023-02-03 10:17:56.807664", |
|||
"doctype": "DocType", |
|||
"editable_grid": 1, |
|||
"engine": "InnoDB", |
|||
"field_order": [ |
|||
"access_expiry_time", |
|||
"refresh_expiry_time" |
|||
], |
|||
"fields": [ |
|||
{ |
|||
"description": "Token Expiry in Minutes e.g. 15", |
|||
"fieldname": "access_expiry_time", |
|||
"fieldtype": "Int", |
|||
"label": "Access Expiry Time" |
|||
}, |
|||
{ |
|||
"description": "Token Expiry in Hours e.g. 1", |
|||
"fieldname": "refresh_expiry_time", |
|||
"fieldtype": "Int", |
|||
"label": "Refresh Expiry Time" |
|||
} |
|||
], |
|||
"index_web_pages_for_search": 1, |
|||
"issingle": 1, |
|||
"links": [], |
|||
"modified": "2023-06-29 09:34:46.212738", |
|||
"modified_by": "Administrator", |
|||
"module": "Add Ons", |
|||
"name": "Token Settings", |
|||
"owner": "Administrator", |
|||
"permissions": [ |
|||
{ |
|||
"create": 1, |
|||
"delete": 1, |
|||
"email": 1, |
|||
"print": 1, |
|||
"read": 1, |
|||
"role": "System Manager", |
|||
"share": 1, |
|||
"write": 1 |
|||
} |
|||
], |
|||
"sort_field": "modified", |
|||
"sort_order": "DESC" |
|||
} |
@ -0,0 +1,15 @@ |
|||
# Copyright (c) 2023, Hard n Soft Technologies Pvt Ltd and contributors |
|||
# For license information, please see license.txt |
|||
|
|||
import frappe |
|||
from frappe.model.document import Document |
|||
|
|||
|
|||
class TokenSettings(Document): |
|||
|
|||
def validate(self): |
|||
if self.access_expiry_time <= 0: |
|||
frappe.throw("Access exipry time should be valid minutes") |
|||
|
|||
if self.refresh_expiry_time <= 0: |
|||
frappe.throw("Refresh exipry time should be valid hours") |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
@ -0,0 +1,475 @@ |
|||
import frappe |
|||
import json |
|||
import time |
|||
import re |
|||
import os |
|||
from frappe.utils import cstr |
|||
site_name = cstr(frappe.local.site) |
|||
|
|||
base_path = os.path.expanduser( |
|||
"~") + "/frappe-bench/sites/" + site_name + "/public" |
|||
|
|||
base_url = os.path.expanduser( |
|||
"~") + "/frappe-bench/sites/" + site_name + "/public/files" |
|||
base_url1 = os.path.expanduser( |
|||
"~") + "/frappe-bench/sites/" + site_name + "/public" |
|||
|
|||
|
|||
""" Working """ |
|||
# @frappe.whitelist(allow_guest=1) |
|||
# def delete_all_publish(): |
|||
# try: |
|||
# frappe.db.sql('delete from `tabPublish`;') |
|||
# time.sleep(1) |
|||
# frappe.db.sql('delete from `tabPublish_Docs`;') |
|||
# except Exception as e: |
|||
# return str(e) |
|||
# return True |
|||
|
|||
""" Working """ |
|||
# @frappe.whitelist(allow_guest=1) |
|||
# def reset_all_publish_assets(): |
|||
# try: |
|||
# frappe.db.sql( |
|||
# 'update `tabSystem Mapping_System Assets` set published=0;') |
|||
# except Exception as e: |
|||
# return str(e) |
|||
# return True |
|||
|
|||
|
|||
def custom_rate_limit(limit, seconds): |
|||
ip_based = True |
|||
ip = frappe.local.request_ip if ip_based is True else None |
|||
identity = None |
|||
|
|||
identity = ip |
|||
cache_key = f"rl:{frappe.form_dict.cmd}:{identity}" |
|||
value = frappe.cache().get(cache_key) or 0 |
|||
if not value: |
|||
frappe.cache().setex(cache_key, seconds, 0) |
|||
|
|||
value = frappe.cache().incrby(cache_key, 1) |
|||
if value > limit: |
|||
frappe.local.response["http_status_code"] = 429 |
|||
return "You hit the rate limit because of too many requests. Please try after sometime." |
|||
return 1 |
|||
|
|||
@frappe.whitelist(allow_guest=1) |
|||
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_file_type(): |
|||
folder_path = base_url |
|||
count = 0 |
|||
for root, dirs, files in os.walk(folder_path): |
|||
for file in files: |
|||
if file.split('.')[-1] == 'PNG': |
|||
count += 1 |
|||
f1 = os.path.join(root, file) |
|||
f2 = f1[:-3] + 'png' |
|||
os.rename(f1, f2) |
|||
|
|||
if file.split('.')[-1] == 'JPG': |
|||
count += 1 |
|||
f1 = os.path.join(root, file) |
|||
f2 = f1[:-3] + 'jpg' |
|||
os.rename(f1, f2) |
|||
|
|||
return count |
|||
|
|||
|
|||
def change_procedure_ext(): |
|||
try: |
|||
frappe.db.sql(''' |
|||
update tabProcedure_Details set file = concat(substring(file,1,length(file)-3),lower(substring(file,length(file)-2))) |
|||
where substring(file,length(file)-2) REGEXP BINARY '[A-Z]'; |
|||
''') |
|||
frappe.db.commit() |
|||
return True |
|||
except: |
|||
return False |
|||
|
|||
|
|||
def change_file_ext(): |
|||
try: |
|||
""" File URL Change """ |
|||
frappe.db.sql(''' |
|||
update tabFile set file_url = concat(substring(file_url,1,length(file_url)-3),lower(substring(file_url,length(file_url)-2))) |
|||
where substring(file_url,length(file_url)-2) REGEXP BINARY '[A-Z]'; |
|||
''') |
|||
frappe.db.commit() |
|||
|
|||
""" File Name """ |
|||
frappe.db.sql(''' |
|||
update tabFile set file_name = concat(substring(file_name,1,length(file_name)-3),lower(substring(file_name,length(file_name)-2))) |
|||
where substring(file_name,length(file_name)-2) REGEXP BINARY '[A-Z]'; |
|||
''') |
|||
frappe.db.commit() |
|||
except: |
|||
return False |
|||
return True |
|||
|
|||
|
|||
def delete_file_ext(): |
|||
try: |
|||
frappe.db.sql(''' |
|||
Delete from tabFile where substring(file_url,length(file_url)-2) REGEXP BINARY '[A-Z]'; |
|||
''') |
|||
frappe.db.commit() |
|||
except: |
|||
return False |
|||
return True |
|||
|
|||
@frappe.whitelist() |
|||
def append_size_file(): |
|||
try: |
|||
data = frappe.db.sql( |
|||
""" SELECT * FROM `tabFile` where file_size = 0 and is_folder!=1; """, as_dict=1) |
|||
for d in data: |
|||
try: |
|||
file_path = base_url1 + d.get("file_url") |
|||
isExist=os.path.exists(file_path) |
|||
if isExist: |
|||
file_size = os.path.getsize(file_path) |
|||
frappe.db.sql( |
|||
f'''UPDATE `tabFile` SET file_size = '{file_size}' WHERE name = '{d['name']}'; ''', as_dict=1) |
|||
frappe.db.commit() |
|||
else: |
|||
pass |
|||
|
|||
except Exception as e: |
|||
return str(e) |
|||
return data |
|||
except Exception as e: |
|||
frappe.log_error("FIle size ", str(e)) |
|||
return e |
|||
|
|||
|
|||
def asset_to_files_path(): |
|||
try: |
|||
count = frappe.db.sql(''' |
|||
select count(*) from tabProcedure_Details where content_type = 'File' and file like '%Asset/%';''') |
|||
frappe.db.sql(''' |
|||
update tabProcedure_Details set file =concat('/files/',SUBSTRING_INDEX(file,'/',-1)) where content_type = 'File' and file like '%Asset/%'; |
|||
''') |
|||
frappe.db.commit() |
|||
return count |
|||
except: |
|||
return False |
|||
|
|||
|
|||
def change_file_dir(): |
|||
base_path = os.path.expanduser( |
|||
"~") + "/frappe-bench/sites/" + site_name + "/public" |
|||
file_data = frappe.db.sql(''' |
|||
select name,file from tabProcedure_Details where content_type = 'File' ;''', as_dict=1) |
|||
changed_file_list = [] |
|||
for d in file_data: |
|||
path = d['file'] |
|||
isExist = os.path.exists(base_path + path) |
|||
if not isExist: |
|||
ext = path[-3:] |
|||
path = path[:-3] |
|||
|
|||
extension = '' |
|||
if ext == 'png': |
|||
extension = 'jpg' |
|||
|
|||
if ext == 'jpg': |
|||
extension = 'png' |
|||
|
|||
new_full_path = path + extension |
|||
|
|||
new_file_dir = base_path + new_full_path |
|||
if os.path.exists(new_file_dir): |
|||
changed_file_list.append(str(new_full_path)) |
|||
frappe.db.sql(f''' |
|||
update tabProcedure_Details set file = '{new_full_path}' where content_type = 'File' and name = '{d['name']}'; |
|||
''') |
|||
frappe.db.commit() |
|||
|
|||
frappe.log_error("ALL updated files", str(changed_file_list)) |
|||
if file_data: |
|||
return file_data |
|||
else: |
|||
return "Done" |
|||
|
|||
@frappe.whitelist(allow_guest=1) |
|||
def file_not_exists(): |
|||
# file_data = frappe.db.sql( |
|||
# '''select parent,step_name,file,name from tabProcedure_Details where content_type = 'File' order by parent;''', as_dict=1) |
|||
""" Cover Images """ |
|||
file_data = frappe.db.sql( |
|||
'''selectparent,systems,sub_systems,cover_image from `tabSystem Mapping_Sub System` where order by parent;''', as_dict=1) |
|||
|
|||
changed_file_list = [] |
|||
count = 1 |
|||
for d in file_data: |
|||
|
|||
path = d['file'] |
|||
is_exist = os.path.exists(base_path + path) |
|||
|
|||
if not is_exist: |
|||
print(d) |
|||
d['id'] = count |
|||
changed_file_list.append(d) |
|||
count += 1 |
|||
|
|||
file_path_not_exists = base_path + "/files/json_files/cover_missing.json" |
|||
with open(file_path_not_exists, 'w') as outfile: |
|||
try: |
|||
outfile.write(json.dumps(changed_file_list)) |
|||
except Exception as e: |
|||
pass |
|||
|
|||
|
|||
@frappe.whitelist(allow_guest=1) |
|||
def get_mp4_cover(): |
|||
file_data = frappe.db.sql( |
|||
'''select parent,systems,sub_systems,cover_image from `tabSystem Mapping_Sub System` where cover_image like '.mp4' order by parent;''', as_dict=1) |
|||
|
|||
file_path_not_exists = base_path + "/files/json_files/cover_mp4.json" |
|||
with open(file_path_not_exists, 'w') as outfile: |
|||
try: |
|||
outfile.write(json.dumps(file_data)) |
|||
except Exception as e: |
|||
pass |
|||
|
|||
|
|||
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: |
|||
print(d['file']) |
|||
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 name,parent,step_name,content_type,content,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 len(result) > 1: |
|||
for a in range(1, len(result)): |
|||
sts += '<li>' + result[a] + '</li> ' |
|||
sts += '</ul>' |
|||
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 |
|||
|
|||
|
|||
def get_single_star_data(): |
|||
count = frappe.db.sql(''' |
|||
select count(*) from tabProcedure_Details where content like "%*%";''', as_dict=1) |
|||
|
|||
@frappe.whitelist(allow_guest=1) |
|||
def procedure_do(variant,language,system): |
|||
data = frappe.db.sql(f'''SELECT min(tmss.idx) as systemdisplayorder,ts.system_name,ts.icon_file,ts.myid,ts.active_status,concat(variant,'-',ts.system_name) FROM |
|||
`tabSystem Mapping_Sub System` as tmss inner join `tabSystems` as ts on tmss.systems = ts.system_name |
|||
where tmss.parent LIKE "{variant}" and substring(tmss.parent,-5,2) = "{language}" and tmss.systems ="{system}";''',as_dict=1) |
|||
return data |
|||
|
|||
@frappe.whitelist() |
|||
def set_procedure_false(): |
|||
try: |
|||
frappe.db.sql('''update `tabSystem Mapping_Sub System` set procedure_is_published=0; |
|||
''') |
|||
frappe.db.commit() |
|||
return True |
|||
except Exception as e: |
|||
return False |
|||
|
|||
|
|||
# @frappe.whitelist(allow_guest=1) |
|||
# def clear_procedures(): |
|||
# try: |
|||
# set_procedure_false() |
|||
# frappe.db.sql('''delete FROM `tabPublish`;''') |
|||
# frappe.db.sql('''delete FROM `tabPublish_Docs`;''') |
|||
# frappe.db.sql('''update `tabVariant Mapping_Assets` set published=0;''') |
|||
# frappe.db.sql('''update `tabSystem Mapping_Sub System` set procedure_is_published=0;''') |
|||
# frappe.db.sql('''update `tabSystem Mapping_System Assets` set published=0;''') |
|||
# frappe.db.commit() |
|||
# except Exception as e: |
|||
# return e |
|||
|
|||
@frappe.whitelist(allow_guest=1) |
|||
def circular_api(): |
|||
api = frappe.db.sql( |
|||
'''SELECT creation,name,title,status,description,circular_image as FileUrl,valid_till from `tabCircular` WHERE valid_till >='{}' '''.format( |
|||
frappe.utils.today()), as_dict=True) |
|||
for i in api: |
|||
if i["status"] == "Active": |
|||
i["status"] = True |
|||
else: |
|||
i["status"] = False |
|||
return api |
|||
|
|||
@frappe.whitelist(allow_guest=1) |
|||
def get_kms_mapping(sub_system,variant,language): |
|||
try: |
|||
varKMS = variant + "-" + language + "%" |
|||
data = frappe.db.sql(f'''SELECT kilometer as kilometer_name, idx as kilometer_IDX, applicable as kilometers_applicable |
|||
FROM `tabKilometer Mapping_Items` where sub_systems="{sub_system}" and parent LIKE "{varKMS}" order by kilometer_IDX;''',as_dict=1) |
|||
return data |
|||
except Exception as e: |
|||
return e |
|||
|
|||
@frappe.whitelist(allow_guest=1) |
|||
def remove_html_tags(): |
|||
try: |
|||
frappe.db.sql('''update tabProcedure_Details set content= replace(content,'>','>'); ''') |
|||
frappe.db.sql('''update tabProcedure_Details set content= replace(content,'<','<'); ''') |
|||
frappe.db.sql('''update tabProcedure_Details set content= replace(content,'<div class="ql-editor read-mode"><p>',''); ''') |
|||
frappe.db.sql('''update tabProcedure_Details set content= replace(content,'</p></div>',''); ''') |
|||
frappe.db.sql('''update tabProcedure_Details set content= replace(content,'<div class=\"ql-editor read-mode\"><ol><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span>',''); ''') |
|||
frappe.db.sql('''update tabProcedure_Details set content= replace(content,'</li></ol></div>',''); ''') |
|||
|
|||
frappe.db.commit() |
|||
return True, 'Done' |
|||
except Exception as e: |
|||
return False,e |
|||
|
|||
@frappe.whitelist() |
|||
def clear_tables(table_name): |
|||
try: |
|||
frappe.db.sql(f'''delete FROM `tab{table_name}`;''') |
|||
return 1 |
|||
except Exception as e: |
|||
return e |
File diff suppressed because it is too large
File diff suppressed because it is too large
File diff suppressed because it is too large
File diff suppressed because it is too large
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 34 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue