Skip to content

Commit

Permalink
change again
Browse files Browse the repository at this point in the history
  • Loading branch information
InnocentBug committed Apr 5, 2024
1 parent 71210d3 commit 8e7375d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
16 changes: 6 additions & 10 deletions src/cript/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,16 +426,12 @@ def api_version(self):

# _no_condense_uuid is either active or not
def save(self, new_node):
self._internal_save(new_node, _no_condense_uuid=True)
self._internal_save(new_node)
print("GET_ALI_HERE")
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)

data = new_node.get_json(_no_condense_uuid=_no_condense_uuid).json
def _internal_save(self, new_node: PrimaryBaseNode) -> None:
new_node.validate(force_validation=True)
data = new_node.get_json().json

print("data")
print(data)
Expand All @@ -454,13 +450,13 @@ 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().json

print("---- data -----")
print(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?
# but wouldn't 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]:
return # Return here, since we successfully Posting
Expand Down
11 changes: 7 additions & 4 deletions src/cript/nodes/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ def get_json(
"Project": {"member", "admin"},
"Collection": {"member", "admin"},
},
_no_condense_uuid: bool = False,
**kwargs,
):
"""
Expand Down Expand Up @@ -487,8 +486,12 @@ class ReturnTuple:
previous_condense_to_uuid = copy.deepcopy(NodeEncoder.condense_to_uuid)
NodeEncoder.condense_to_uuid = condense_to_uuid

previous_no_condense_uuid = copy.deepcopy(NodeEncoder.no_condense_uuid)
NodeEncoder.no_condense_uuid = _no_condense_uuid
known_uid = set()
for child_node in self:
known_uid.add(child_node.uid)

previous_known_uid = copy.deepcopy(NodeEncoder.known_uid)
NodeEncoder.known_uid = known_uid

try:
tmp_json = json.dumps(self, cls=NodeEncoder, **kwargs)
Expand All @@ -507,7 +510,7 @@ class ReturnTuple:
NodeEncoder.known_uuid = previous_known_uuid
NodeEncoder.suppress_attributes = previous_suppress_attributes
NodeEncoder.condense_to_uuid = previous_condense_to_uuid
NodeEncoder.no_condense_uuid = previous_no_condense_uuid
NodeEncoder.known_uid = previous_known_uid

def find_children(self, search_attr: dict, search_depth: int = -1, handled_nodes: Optional[List] = None) -> List:
"""
Expand Down
7 changes: 4 additions & 3 deletions src/cript/nodes/util/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class NodeEncoder(json.JSONEncoder):
known_uuid: Set[str] = set()
condense_to_uuid: Dict[str, Set[str]] = dict()
suppress_attributes: Optional[Dict[str, Set[str]]] = None
no_condense_uuid: bool = False
known_uid: Optional[Set[str]] = None

def default(self, obj):
"""
Expand Down Expand Up @@ -183,8 +183,9 @@ def strip_to_edge_uuid(element):
except AttributeError:
uid = element["uid"]

if self.no_condense_uuid:
element = ""
# If this is not the only occurrence of the node, replace it with UID instead of UUID
if self.known_uid and uid in self.known_uid:
element = {"uid": uid}
else:
element = {"uuid": str(uuid)}
return element, uid
Expand Down

0 comments on commit 8e7375d

Please sign in to comment.