wag-managment-api-service-v.../a_project_files/drafts_and_notes/evyos-draft/recursive_menu.py

230 lines
10 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import json
data = '{"menu":[{"only_menu_item":false,"item_order":0,"layer":0,"app_name":"Tanımlama Menüsü","app_description":"Tanımlama Menüsü","app_path":"","uu_id":"166d9a3f-495e-4261-baab-dd456e9d294b","app_parent_items_id":null,"after_separator":false,"row_limit":100,"read":true,"write":false,"delete":false,"report_print":false,"report_export":false,"program_name":"APP166d9a3f495e4261baabdd456e9d294b"},{"only_menu_item":false,"item_order":10,"layer":1,"app_name":"Firma İşlemleri","app_description":"Firma İşlemleri","app_path":"","uu_id":"d1aa4365-b1ef-4c91-ac8e-e3289f7eb075","app_parent_items_id":"166d9a3f-495e-4261-baab-dd456e9d294b","after_separator":false,"row_limit":100,"read":true,"write":false,"delete":false,"report_print":false,"report_export":false,"program_name":"APPd1aa4365b1ef4c91ac8ee3289f7eb075"},{"only_menu_item":true,"item_order":20,"layer":2,"app_name":"Firma Tanımlama","app_description":"Firma Tanımlama","app_path":"create_company","uu_id":"a3c60a25-ff46-4872-b209-9e501dde7b73","app_parent_items_id":"d1aa4365-b1ef-4c91-ac8e-e3289f7eb075","after_separator":false,"row_limit":100,"read":true,"write":false,"delete":false,"report_print":false,"report_export":false,"program_name":"APPa3c60a25ff464872b2099e501dde7b73"},{"only_menu_item":false,"item_order":30,"layer":1,"app_name":"Personel İşlemleri","app_description":"Personel İşlemleri","app_path":"","uu_id":"eebb591d-842b-4495-8721-e09552665a06","app_parent_items_id":"166d9a3f-495e-4261-baab-dd456e9d294b","after_separator":false,"row_limit":100,"read":true,"write":false,"delete":false,"report_print":false,"report_export":false,"program_name":"APPeebb591d842b44958721e09552665a06"},{"only_menu_item":true,"item_order":40,"layer":2,"app_name":"Kişi Tanımlama","app_description":"Kişi Tanımlama","app_path":"create_person","uu_id":"0c6c8cd2-f6b7-471f-9671-5cc1ac9f502e","app_parent_items_id":"eebb591d-842b-4495-8721-e09552665a06","after_separator":false,"row_limit":100,"read":true,"write":false,"delete":false,"report_print":false,"report_export":false,"program_name":"APP0c6c8cd2f6b7471f96715cc1ac9f502e"},{"only_menu_item":false,"item_order":50,"layer":1,"app_name":"Bina İşlemleri","app_description":"Bina İşlemleri","app_path":"","uu_id":"66627ebb-0425-425f-bc0f-8a943eb0a3ca","app_parent_items_id":"166d9a3f-495e-4261-baab-dd456e9d294b","after_separator":false,"row_limit":100,"read":true,"write":false,"delete":false,"report_print":false,"report_export":false,"program_name":"APP66627ebb0425425fbc0f8a943eb0a3ca"},{"only_menu_item":true,"item_order":60,"layer":2,"app_name":"Bina ve bölüm tanımlama","app_description":"Bina ve bölüm tanımlama","app_path":"create_build","uu_id":"173c4d8e-5577-4d4d-8712-f6fa2fbc8019","app_parent_items_id":"66627ebb-0425-425f-bc0f-8a943eb0a3ca","after_separator":false,"row_limit":100,"read":true,"write":false,"delete":false,"report_print":false,"report_export":false,"program_name":"APP173c4d8e55774d4d8712f6fa2fbc8019"}]}'
class Menu:
def __init__(self, json_data):
self.data = {}
self.json = json_data
self.app_name = None
self.app_description = None
self.app_path = None
self.uu_id = None
self.app_parent_items_id = None
self.children = {}
self.only_menu_item = None
self.item_order = None
self.layer = None
self.before_separator = None
self.row_limit = None
self.read = None
self.write = None
self.delete = None
self.report_print = None
self.report_export = None
self.program_name = None
self.dct = {}
self.import_data()
def add_item(
self,
only_menu_item,
item_order,
layer,
app_name,
app_description,
app_path,
uu_id,
app_parent_items_id,
before_separator,
row_limit,
read,
write,
delete,
report_print,
report_export,
program_name,
):
self.app_name = app_name
self.app_description = app_description
self.app_path = app_path
self.uu_id = uu_id
self.app_parent_items_id = app_parent_items_id
self.children = {}
self.only_menu_item = only_menu_item
self.item_order = item_order
self.layer = layer
self.before_separator = before_separator
self.row_limit = row_limit
self.read = read
self.write = write
self.delete = delete
self.report_print = report_print
self.report_export = report_export
self.program_name = program_name
self.dct = dict(
app_parent_items_id=app_parent_items_id,
uu_id=uu_id,
app_name=app_name,
children={},
app_path=app_path,
app_description=app_description,
only_menu_item=self.only_menu_item,
item_order=self.item_order,
layer=self.layer,
before_separator=self.before_separator,
row_limit=self.row_limit,
read=self.read,
write=self.write,
delete=self.delete,
report_print=self.report_print,
report_export=self.report_export,
program_name=self.program_name,
)
xx = self.find_data(self.data, str(app_parent_items_id))
if not xx:
self.data[self.uu_id] = self.dct
else:
xx["children"][self.uu_id] = self.dct
# xx.self.children[self.uu_id] = self.dct
# self.add_data(self.data, None)
def find_data(self, search_data, find_text):
if find_text is None:
return None
for x, y in search_data.items():
if x == find_text:
print(find_text, " bulundu")
# y["children"].append(self.dct)
return y
if "children" in y and len(y["children"]) > 0:
ret = self.find_data(y["children"], find_text)
if ret is not None:
return ret
return None
@staticmethod
def show_col(i, y):
print(
"layer :",
i,
" app_parent_items_id",
y["app_parent_items_id"],
"uu_id",
y["uu_id"],
"app_name",
y["app_name"],
"app_path",
y["app_path"],
"app_description",
y["app_description"],
"only_menu_item",
y["only_menu_item"],
"item_order",
y["item_order"],
"layer",
y["layer"],
"before_separator",
y["before_separator"],
"row_limit",
y["row_limit"],
"read",
y["read"],
"write",
y["write"],
"delete",
y["delete"],
"report_print",
y["report_print"],
"report_export",
y["report_export"],
"program_name",
y["program_name"],
)
def show_data(self):
# print(self.data)
for x, y in self.data.items():
self.show_col(0, y)
if type(y) is dict:
for a, b in y["children"].items():
self.show_col(1, b)
if type(y) is dict:
for c, d in b["children"].items():
self.show_col(2, d)
if type(y) is dict:
for e, f in d["children"].items():
self.show_col(3, f)
# print("show Dat :", x, y)
return self.data
def import_data(self):
if type(self.json) is str:
print("string miş")
self.json = json.loads(self.json)
for item, value in self.json.items():
if type(value) is list:
for x in range(len(value)):
print(f"t:{type(value[x])} : {value[x]}")
if type(value[x]) is list:
print("list", x)
if type(value[x]) is dict:
print(
value[x]["app_name"],
value[x]["app_description"],
value[x]["app_path"],
value[x]["uu_id"],
value[x]["app_parent_items_id"],
[],
value[x]["only_menu_item"],
value[x]["item_order"],
value[x]["layer"],
value[x]["after_separator"],
value[x]["row_limit"],
value[x]["read"],
value[x]["write"],
value[x]["delete"],
value[x]["report_print"],
value[x]["report_export"],
value[x]["program_name"],
)
self.add_item(
value[x]["only_menu_item"],
value[x]["item_order"],
value[x]["layer"],
value[x]["app_name"],
value[x]["app_description"],
value[x]["app_path"],
value[x]["uu_id"],
value[x]["app_parent_items_id"],
value[x]["after_separator"],
value[x]["row_limit"],
value[x]["read"],
value[x]["write"],
value[x]["delete"],
value[x]["report_print"],
value[x]["report_export"],
value[x]["program_name"],
)
# self.add_item(value[x]["app_name"], app_description, app_path, uu_id, app_parent_items_id):
# self.app_name = app_name
# for child in item.children:
# print(f" - {child.app_name}")
(0, [1, 3, 5])
(1, [2])
(3, [4])
(5, [6])
(4, [7])
menu = Menu(json.loads(data))
print("*" * 100)
menu.show_data()