Merkt sich das aktuelle Item in einer temporären json Datei im Work Ordner. Beim speichern wird der Baum ausgeblendet, da in einer neuen Session dieser neu aus der Datenbank bestimmt werden muss

This commit is contained in:
2024-02-05 17:05:19 +01:00
parent 1075997873
commit f8c660e1ee
+20 -21
View File
@@ -1,5 +1,4 @@
import json import json
from controller import Controller
import pandas as pd import pandas as pd
import os import os
@@ -96,6 +95,7 @@ class CadItem():
"cb_oberflaeche_neu", "cb_oberflaeche_neu",
"cb_farbe_neu", "cb_farbe_neu",
# buttons # buttons
"cb_suche_asm",
"cb_speichern", "cb_speichern",
"cb_migrieren", "cb_migrieren",
"cb_zurücksetzen", "cb_zurücksetzen",
@@ -192,6 +192,13 @@ class CadItem():
data = self.load_csv(path) data = self.load_csv(path)
return data return data
return None return None
def sivas_data_from_json(self, cid):
path = os.path.join(self.controller.get_env("out"), cid + '.json')
if os.path.exists(path):
data = self.load(path)
return data
return None
def load_csv(self, path): def load_csv(self, path):
"""lädt die SIVAS csv Datei in die Felder für die Oberfläche """ """lädt die SIVAS csv Datei in die Felder für die Oberfläche """
if not os.path.exists(path): if not os.path.exists(path):
@@ -217,12 +224,6 @@ class CadItem():
else: else:
raise Exception("no gui_data given in string") raise Exception("no gui_data given in string")
# if "data" in jsonobj:
# data = jsonobj["data"]
# self.set_data_dict(data)
# else:
# raise Exception("no data given in string")
if "parent_children_mapping" in jsonobj: if "parent_children_mapping" in jsonobj:
parent_children_mapping = jsonobj["parent_children_mapping"] parent_children_mapping = jsonobj["parent_children_mapping"]
self.set_parent_children(parent_children_mapping) self.set_parent_children(parent_children_mapping)
@@ -232,27 +233,25 @@ class CadItem():
red_ids = jsonobj["red_ids"] red_ids = jsonobj["red_ids"]
self.set_red_ids(red_ids) self.set_red_ids(red_ids)
def to_dict(self): def to_dict(self, tree=False ):
jsonobj = dict() jsonobj = dict()
# die Oberflächendaten # die Oberflächendaten
gui_data = self.get_all_gui_data() gui_data = self.get_all_gui_data()
jsonobj["gui_data"] = gui_data jsonobj["gui_data"] = gui_data
# die Impfdaten
# data = self.get_all_data()
# jsonobj["data"] = data
# der Baum # der Baum
parent_children_mapping = self.get_parent_children() if tree:
jsonobj["parent_children_mapping"] = parent_children_mapping parent_children_mapping = self.get_parent_children()
jsonobj["parent_children_mapping"] = parent_children_mapping
# die ids der nicht migrierten Dateien # die ids der nicht migrierten Dateien
red_ids = self.get_red_ids() red_ids = self.get_red_ids()
jsonobj["red_ids"] = red_ids jsonobj["red_ids"] = red_ids
return jsonobj return jsonobj
def to_json(self):
obj = self.to_dict() def to_json(self, tree=False):
obj = self.to_dict(tree)
return json.dumps(obj) return json.dumps(obj)
def load(self, path): def load(self, path):
@@ -263,10 +262,10 @@ class CadItem():
except Exception: except Exception:
raise Exception("guid_data, data, parent_children_mapping or red_ids not found") raise Exception("guid_data, data, parent_children_mapping or red_ids not found")
def save(self, path): def save(self, path, tree=False):
"""saves all data of model to a json string""" """saves all data of model to a json string"""
with open(path, 'w') as f: with open(path, 'w') as f:
json.dump(self.to_dict(), f) json.dump(self.to_dict(tree), f)
class CadItemRepository: class CadItemRepository:
""" """