Browse Source

assets based on language

master
venkataakhil 1 year ago
parent
commit
479302c2a2
  1. 10
      smart_service/apis/publish_api.py
  2. 25
      smart_service/apis/support.py
  3. 4
      smart_service/transactions/doctype/publish/publish.js
  4. 16
      smart_service/transactions/doctype/publish/publish.py

10
smart_service/apis/publish_api.py

@ -360,6 +360,7 @@ def merge_json_files(old_json_path, new_json_path, out_file_path):
for variant_new in data_new["JSON"]:
if variant_new["Variant"]["name"] in variant_name and variant_new["Variant"]["name"] not in variant_added:
system_name = set()
system_id={}
system_added = set()
system_list = []
variant_asset_name = set()
@ -382,6 +383,7 @@ def merge_json_files(old_json_path, new_json_path, out_file_path):
system_asset_added = set()
system_asset_list = []
system_name.add(system["system_name"])
# system_name.add(system[''])
if system["system_name"] not in system_added and system["system_name"] in system_name:
sub_system_name = set()
sub_system_added = set()
@ -447,6 +449,7 @@ def merge_json_files(old_json_path, new_json_path, out_file_path):
old_pd)
proc_det_added.add(
old_pd["kilometer_name"])
sub_system_list.append({"subSystemdisplayorder": subsystem["subSystemdisplayorder"],
"systems": subsystem["systems"],
"sub_systems": subsystem["sub_systems"],
@ -644,6 +647,7 @@ def new_merge_json_files(old_json_path, new_json_path, out_file_path):
})
proc_det_added.add(
pd["procedure_name"])
for old_variants in data_old["JSON"]:
if old_variants["Variant"]["name"] == variant_new["Variant"]["name"]:
for old_system in old_variants["Variant"]["Systems"]:
@ -651,8 +655,6 @@ def new_merge_json_files(old_json_path, new_json_path, out_file_path):
for old_sub_system in old_system["Subsystems"]:
if old_sub_system["sub_systems"] == subsystem["sub_systems"]:
for old_pd in old_sub_system["Procedure_details"]:
# proc_det_name.add(
# old_pd["kilometer_name"])
if old_pd["procedure_name"] not in proc_det_added and \
old_pd["procedure_name"] in proc_det_name:
sub_system_list.append(
@ -719,8 +721,7 @@ def new_merge_json_files(old_json_path, new_json_path, out_file_path):
"myid": system["myid"],
"active_status": system["active_status"],
"Assets": system_asset_list,
"Subsystems": sub_system_list,
# "Config Kilometer": conf_km_list,
"Subsystems": sub_system_list
})
system_added.add(system["system_name"])
except:
@ -757,7 +758,6 @@ def new_merge_json_files(old_json_path, new_json_path, out_file_path):
if variant_old["Variant"]["name"] in variant_name and variant_old["Variant"]["name"] not in variant_added:
data_consolidated["JSON"].append({"Variant": variant_old["Variant"],
})
# json_object = json.dumps(data_consolidated, indent=4)
with open(out_file_path, "w") as outfile:
outfile.write(json.dumps(data_consolidated, indent=4))

25
smart_service/apis/support.py

@ -35,6 +35,23 @@ base_url = os.path.expanduser(
# 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('''
@ -179,18 +196,14 @@ def asset_to_files_path():
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:
frappe.log_error("File data :", str(d))
path = d['file']
isExist = os.path.exists(base_path + path)
frappe.log_error("Path exists :", str(isExist))
if not isExist:
ext = path[-3:]
path = path[:-3]
@ -204,8 +217,6 @@ def change_file_dir():
new_full_path = path + extension
frappe.log_error("New path:", str(new_full_path))
new_file_dir = base_path + new_full_path
if os.path.exists(new_file_dir):
changed_file_list.append(str(new_full_path))
@ -382,7 +393,7 @@ def get_single_star_data():
@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 FROM
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

4
smart_service/transactions/doctype/publish/publish.js

@ -372,6 +372,7 @@ frappe.ui.form.on('Publish', {
"method": "smart_service.transactions.doctype.publish.publish.get_vm_asset",
"args": {
"doc": frm.doc.variant_mapping,
"lang": frm.doc.language
},
callback: function (r) {
$.each(r.message, function (index, row) {
@ -392,7 +393,8 @@ frappe.ui.form.on('Publish', {
"method": "smart_service.transactions.doctype.publish.publish.get_sm_asset",
"args": {
"doc": frm.doc.variant_mapping,
"name": filter
"name": filter,
"lang": frm.doc.language
},
callback: function (r) {
$.each(r.message, function (index, row) {

16
smart_service/transactions/doctype/publish/publish.py

@ -239,7 +239,6 @@ def old_publish(vehicle, language):
@frappe.whitelist()
def update_mapping(variant_mapping, doc):
# frappe.msgprint("call update mapping")
doc = frappe.get_doc("Publish", doc)
current_db_name = frappe.conf.get("db_name")
if doc.publish_documents:
@ -261,14 +260,12 @@ def update_mapping(variant_mapping, doc):
sm = frappe.get_doc("System Mapping", system_map.name)
for sys_asset in sm.get('systems_assets'):
if sys_asset.systems == variant.system:
# frappe.msgprint("asset")
sys_asset.published = '1'
frappe.db.sql("""update {0}.`tabSystem Mapping_System Assets` set published = '1' where parent = "{1}" and systems = "{2}";""".format(
current_db_name, sm.name, variant.system))
frappe.db.commit()
for sm_item in sm.get("system_sub_systems"):
# frappe.msgprint("system")
if sm_item.systems == variant.system and sm_item.sub_systems == variant.sub_system and sm_item.procedure == variant.procedure_link:
sm_item.procedure_is_published = '1'
frappe.db.sql("""update {0}.`tabSystem Mapping_Sub System` set procedure_is_published = '1' where parent = "{1}"
@ -280,22 +277,22 @@ def update_mapping(variant_mapping, doc):
@frappe.whitelist()
def get_vm_asset(doc):
def get_vm_asset(doc,lang):
doc = frappe.get_doc("Variant Mapping", doc)
vm_assets = frappe.db.sql("""select category,language,attach_file,active_status from {0}.`tabVariant Mapping_Assets`
where parent = "{1}" and published = '0'; """.format(current_db_name, doc.name), as_dict=1)
where parent = "{1}" and language '{2}' and published = '0'; """.format(current_db_name, doc.name,lang), as_dict=1)
return vm_assets
@frappe.whitelist()
def get_sm_asset(doc, name):
system_map = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping="{1}" and name = "{2}"; """.format(
current_db_name, doc, name), as_dict=1)
def get_sm_asset(doc, name,lang):
system_map = frappe.db.sql("""select name from {0}.`tabSystem Mapping` where variant_mapping="{1}" and name = "{2}" and language = '{3}'; """.format(
current_db_name, doc, name,lang), as_dict=1)
if system_map:
for s in system_map:
doc = frappe.get_doc("System Mapping", s.name)
system_asset = frappe.db.sql("""select systems,language,active_status,system_asset from {0}.`tabSystem Mapping_System Assets`
where parent = "{1}" and published = '0'; """.format(current_db_name, s.name), as_dict=1)
where parent = "{1}" and language = "{2}" and published = '0'; """.format(current_db_name, s.name,lang), as_dict=1)
return system_asset
@ -305,7 +302,6 @@ def get_system(doc, name,lang):
current_db_name, doc, name,lang), as_dict=1)
if system_map:
for s in system_map:
frappe.msgprint(str(s.name))
doc = frappe.get_doc("System Mapping", s.name)
system = frappe.db.sql("""select systems,sub_systems,active_status,symptom,component,estimate_time,rts,component,mat,
procedure_status,`procedure` from {0}.`tabSystem Mapping_Sub System` where parent = "{1}" and

Loading…
Cancel
Save