Skip to content

Commit

Permalink
fix(toolchain): use querydict all the way
Browse files Browse the repository at this point in the history
  • Loading branch information
Kl0ven committed Feb 3, 2023
1 parent 813dd60 commit f365902
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
2 changes: 1 addition & 1 deletion admin_action_tools/tests/unit/test_toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ def test_toolchain_querydict(self):
toolchain = ToolChain(request)
res = toolchain._ToolChain__clean_data(data, {})

self.assertEqual(res["data"], {"a": ["1", "2", "3"]})
self.assertEqual(res["data"], "a=1&a=2&a=3")
14 changes: 3 additions & 11 deletions admin_action_tools/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def set_tool(self, tool_name: str, data: dict, metadata=None) -> None:

def get_tool(self, tool_name: str) -> Tuple[Optional[dict], Optional[dict]]:
tool = self.data.get(tool_name, {})
return tool.get("data"), tool.get("metadata")
return QueryDict(tool.get("data")), tool.get("metadata")

def clear_tool_chain(self):
self.session.pop(self.name, None)
Expand Down Expand Up @@ -130,19 +130,11 @@ def get_next_step(self, tool_name: str) -> ToolAction:
return ToolAction.INIT

def __clean_data(self, data: QueryDict, metadata):
new_data = data.dict()
new_data = data.copy()
new_data.pop("csrfmiddlewaretoken", None)
cleaned_data = self.__process_query_dict(new_data, data)

metadata = metadata or {}
return {"data": cleaned_data, "metadata": metadata}

def __process_query_dict(self, new_data: dict, data: QueryDict):
for key in new_data:
old_field = data.getlist(key)
if len(old_field) > 1:
new_data[key] = old_field
return new_data
return {"data": new_data.urlencode(), "metadata": metadata}

def get_history(self):
return self.data["history"]

0 comments on commit f365902

Please sign in to comment.