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:
+20
-21
@@ -1,5 +1,4 @@
|
||||
import json
|
||||
from controller import Controller
|
||||
import pandas as pd
|
||||
import os
|
||||
|
||||
@@ -96,6 +95,7 @@ class CadItem():
|
||||
"cb_oberflaeche_neu",
|
||||
"cb_farbe_neu",
|
||||
# buttons
|
||||
"cb_suche_asm",
|
||||
"cb_speichern",
|
||||
"cb_migrieren",
|
||||
"cb_zurücksetzen",
|
||||
@@ -192,6 +192,13 @@ class CadItem():
|
||||
data = self.load_csv(path)
|
||||
return data
|
||||
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):
|
||||
"""lädt die SIVAS csv Datei in die Felder für die Oberfläche """
|
||||
if not os.path.exists(path):
|
||||
@@ -217,12 +224,6 @@ class CadItem():
|
||||
else:
|
||||
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:
|
||||
parent_children_mapping = jsonobj["parent_children_mapping"]
|
||||
self.set_parent_children(parent_children_mapping)
|
||||
@@ -232,27 +233,25 @@ class CadItem():
|
||||
red_ids = jsonobj["red_ids"]
|
||||
self.set_red_ids(red_ids)
|
||||
|
||||
def to_dict(self):
|
||||
def to_dict(self, tree=False ):
|
||||
jsonobj = dict()
|
||||
|
||||
# die Oberflächendaten
|
||||
gui_data = self.get_all_gui_data()
|
||||
jsonobj["gui_data"] = gui_data
|
||||
|
||||
# die Impfdaten
|
||||
# data = self.get_all_data()
|
||||
# jsonobj["data"] = data
|
||||
|
||||
# der Baum
|
||||
parent_children_mapping = self.get_parent_children()
|
||||
jsonobj["parent_children_mapping"] = parent_children_mapping
|
||||
if tree:
|
||||
parent_children_mapping = self.get_parent_children()
|
||||
jsonobj["parent_children_mapping"] = parent_children_mapping
|
||||
|
||||
# die ids der nicht migrierten Dateien
|
||||
red_ids = self.get_red_ids()
|
||||
jsonobj["red_ids"] = red_ids
|
||||
# die ids der nicht migrierten Dateien
|
||||
red_ids = self.get_red_ids()
|
||||
jsonobj["red_ids"] = red_ids
|
||||
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)
|
||||
|
||||
def load(self, path):
|
||||
@@ -263,10 +262,10 @@ class CadItem():
|
||||
except Exception:
|
||||
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"""
|
||||
with open(path, 'w') as f:
|
||||
json.dump(self.to_dict(), f)
|
||||
json.dump(self.to_dict(tree), f)
|
||||
|
||||
class CadItemRepository:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user