diff --git a/src/cript/api/api.py b/src/cript/api/api.py index 15711852..8bfd8bae 100644 --- a/src/cript/api/api.py +++ b/src/cript/api/api.py @@ -431,14 +431,26 @@ def save(self, new_node): quit() self._internal_save(new_node, _no_condense_uuid=False) - def _internal_save(self, new_node: PrimaryBaseNode, _no_condense_uuid: bool) -> None: - print("_no_condense_uuid") - print(_no_condense_uuid) + def _internal_save(self, new_node: PrimaryBaseNode, preknown_uid: str, _no_condense_uuid: bool) -> None: + """ + NOTE: for Ludwig + + WIP NOTES: + + unfinished WIP, but the idea is we want to send + a preknown_uuid + + I'm imagining something like + data = new_node.get_json(preknown_uid="preknown uid into here").json + in the same way we did the _no_condense_uuid + + but, then , I see where I would add a preknown uuid + scroll down to - data = new_node.get_json(_no_condense_uuid=_no_condense_uuid).json + WIP NOTES CONTINUED: + + """ - print("data") - print(data) print("----------\\------------\n") node_class_name = new_node.node_type.capitalize() @@ -454,15 +466,31 @@ def _internal_save(self, new_node: PrimaryBaseNode, _no_condense_uuid: bool) -> # or else its a patch handled by previous node if new_node.node_type.lower() == "project": + # data = new_node.get_json(_no_condense_uuid=_no_condense_uuid).json + # data = new_node.get_json(sort_keys=False, condense_to_uuid={}, indent=2).json # indent=2 + + # data = new_node.get_json(_no_condense_uuid=_no_condense_uuid).json + data = new_node.get_json(_no_condense_uuid=_no_condense_uuid).json - print("---- data -----") + # data = new_node.get_json(condense_to_uuid={}).json + print("---- data 2 -----") + # print(type(data2)) + # print(type(json.loads(data2))) + # data = json.loads(data) + # print(type(data)) + # print(str(data)) print(data) + # data = str(data) + # data = json.dumps(data) + # data = data.replace('""', "[]") + # print("now data\n", data) print("---- data end -----") # if _no_condense_uuid is true do a POST if its false do a patch, # but wouldnt we then just find the existing node above in the generator? response = self._capsule_request(url_path="/project/", method="POST", data=data) if response.status_code in [200, 201]: + print("FINALLY_WORKED!") return # Return here, since we successfully Posting else: # debug for now print("GET HERE ALI") @@ -506,6 +534,32 @@ def _internal_save(self, new_node: PrimaryBaseNode, _no_condense_uuid: bool) -> url_path = f"/{new_node.node_type}/{new_node.uuid}" + """ + WIP NOTES CONTINUED: + + this is where we would need to make a map of the uids + patch_map[uid_] ? constructed above? + + problem right now is , + we need the uids to be in place for the original POST json + which happens up above + so I'm wondeing how to go about that, + + and I think I would need to rewalk the original get_json for the post + switching any {uuid: "uuid"} for {uid:"uid"} + + AND I TRY TO DO THAT if you look inside + + json.py , you'd find the following below + + ######## WIP HERE ################ + if self.preknown_uid: + element = {"uid": str(uid)} + return element, uid + + but we need this uid map and i'm not so sure where to put this ? + + """ for uuid_ in reversed(patch_map.keys_sorted_by_last_modified()): node = patch_map[uuid_] diff --git a/src/cript/nodes/core.py b/src/cript/nodes/core.py index 343fcca6..d2d58ce4 100644 --- a/src/cript/nodes/core.py +++ b/src/cript/nodes/core.py @@ -448,6 +448,7 @@ def get_json( "Collection": {"member", "admin"}, }, _no_condense_uuid: bool = False, + preknown_uid: str = "", **kwargs, ): """ @@ -489,6 +490,7 @@ class ReturnTuple: previous_no_condense_uuid = copy.deepcopy(NodeEncoder.no_condense_uuid) NodeEncoder.no_condense_uuid = _no_condense_uuid + NodeEncoder.preknown_uid = preknown_uid try: tmp_json = json.dumps(self, cls=NodeEncoder, **kwargs) @@ -508,6 +510,8 @@ class ReturnTuple: NodeEncoder.suppress_attributes = previous_suppress_attributes NodeEncoder.condense_to_uuid = previous_condense_to_uuid NodeEncoder.no_condense_uuid = previous_no_condense_uuid + # HERE?? + # NodeEncoder.preknown_uid = preknown_uid def find_children(self, search_attr: dict, search_depth: int = -1, handled_nodes: Optional[List] = None) -> List: """ diff --git a/src/cript/nodes/util/json.py b/src/cript/nodes/util/json.py index 6d287cb2..d0e88e96 100644 --- a/src/cript/nodes/util/json.py +++ b/src/cript/nodes/util/json.py @@ -1,6 +1,7 @@ """ This module contains classes and functions that help with the json serialization and deserialization of nodes. """ + import dataclasses import inspect import json @@ -67,6 +68,7 @@ class NodeEncoder(json.JSONEncoder): condense_to_uuid: Dict[str, Set[str]] = dict() suppress_attributes: Optional[Dict[str, Set[str]]] = None no_condense_uuid: bool = False + preknown_uid: str = "" def default(self, obj): """ @@ -183,12 +185,18 @@ def strip_to_edge_uuid(element): except AttributeError: uid = element["uid"] - if self.no_condense_uuid: - element = "" - else: - element = {"uuid": str(uuid)} + ######## WIP HERE ################ + if self.preknown_uid: + element = {"uid": str(uid)} return element, uid + ######################### + # if self.no_condense_uuid: + # element = "" + # else: + # element = {"uuid": str(uuid)} + # return element, uid + # Processes an attribute based on its type (list or single element) if isinstance(attribute, List): processed_elements = []