chg: [history_session] save new query in tree

pull/592/merge
David Cruciani 2024-03-11 12:12:23 +01:00
parent c218090463
commit f0fff0df2e
No known key found for this signature in database
GPG Key ID: 8690CDE1E3994B9B
2 changed files with 46 additions and 22 deletions

View File

@ -31,15 +31,14 @@ def get_history_session():
# It's already save in history # It's already save in history
# Only parent-child tree structure is in flask session # Only parent-child tree structure is in flask session
current_query_value = sess.get(current_query) current_query_value = sess.get(current_query)
if current_query_value and current_query_value["children"]: if current_query_value:
loc_list.append(current_query_value) loc_list.append(current_query_value)
for q in sess: for q in sess:
if isUUID(q): if isUUID(q):
# If query have no children then don't display it # If query have no children then don't display it
q_value = sess.get(q) q_value = sess.get(q)
if q_value["children"]: if not q == current_query:
if not q == current_query: loc_list.append(q_value)
loc_list.append(q_value)
return loc_list return loc_list
@ -47,7 +46,7 @@ def get_current_query_history():
current_query = sess.get("current_query") current_query = sess.get("current_query")
if current_query: if current_query:
current_query_value = sess.get(current_query) current_query_value = sess.get(current_query)
if current_query_value and current_query_value["children"]: if current_query_value:
return current_query_value return current_query_value
return {} return {}
@ -163,9 +162,8 @@ def remove_node_session(node_uuid):
if q_value["uuid"] == node_uuid: if q_value["uuid"] == node_uuid:
loc = i loc = i
break break
else: elif q_value["children"]:
if q_value["children"]: return util_remove_node_session(node_uuid, q_value, sess[keys_list[i]])
return util_remove_node_session(node_uuid, q_value, sess[keys_list[i]])
if loc: if loc:
del sess[keys_list[i]] del sess[keys_list[i]]

View File

@ -1,5 +1,5 @@
import json import json
from .utils.utils import query_get_module from .utils.utils import isUUID, query_get_module
from . import db from . import db
from .db_class.db import History, Module, Config, Module_Config, Session_db, History_Tree from .db_class.db import History, Module, Config, Module_Config, Session_db, History_Tree
from flask import session as sess from flask import session as sess
@ -150,14 +150,7 @@ def get_history():
def create_new_session_tree(current_session, parent_id): def create_new_session_tree(current_session, parent_id):
loc_session = get_session(parent_id) loc_session = get_session(parent_id)
loc_json = {
"uuid": loc_session.uuid,
"modules": json.loads(loc_session.modules_list),
"query": loc_session.query_enter,
"input": loc_session.input_query,
"query_date": loc_session.query_date.strftime('%Y-%m-%d %H:%M'),
"config": json.loads(loc_session.config_module)
}
loc_json_child = { loc_json_child = {
"uuid": current_session.uuid, "uuid": current_session.uuid,
"modules": current_session.modules_list, "modules": current_session.modules_list,
@ -165,12 +158,20 @@ def create_new_session_tree(current_session, parent_id):
"input": current_session.input_query, "input": current_session.input_query,
"query_date": current_session.query_date.strftime('%Y-%m-%d'), "query_date": current_session.query_date.strftime('%Y-%m-%d'),
"config": current_session.config_module, "config": current_session.config_module,
"children": [] "children": list()
}
loc_json = {
"uuid": loc_session.uuid,
"modules": json.loads(loc_session.modules_list),
"query": loc_session.query_enter,
"input": loc_session.input_query,
"query_date": loc_session.query_date.strftime('%Y-%m-%d %H:%M'),
"config": json.loads(loc_session.config_module),
"children" : [loc_json_child]
} }
sess["current_query"] = loc_session.uuid sess["current_query"] = loc_session.uuid
sess[sess.get("current_query")] = loc_json sess[sess.get("current_query")] = loc_json
sess[sess.get("current_query")]["children"] = [loc_json_child]
def util_set_flask_session(parent_id, loc_session, current_session): def util_set_flask_session(parent_id, loc_session, current_session):
if parent_id == loc_session["uuid"]: if parent_id == loc_session["uuid"]:
@ -201,9 +202,34 @@ def set_flask_session(current_session, parent_id):
if not current_query or current_query not in sess: if not current_query or current_query not in sess:
create_new_session_tree(current_session, parent_id) create_new_session_tree(current_session, parent_id)
else: else:
# sess["uuid"] ## Check in current query
loc_session = sess.get(sess.get("current_query")) loc_session = sess.get(current_query)
if not "children" in loc_session: if not "children" in loc_session:
loc_session["children"] = list() loc_session["children"] = list()
## If not in current query, current query change for an other one
if not util_set_flask_session(parent_id, loc_session, current_session): if not util_set_flask_session(parent_id, loc_session, current_session):
create_new_session_tree(current_session, parent_id) # sess["uuid"]
for q in sess:
if isUUID(q) and not q == current_query:
loc_session = sess.get(q)
if not "children" in loc_session:
loc_session["children"] = list()
if util_set_flask_session(parent_id, loc_session, current_session):
sess["current_query"] = q
flag = False
break
if flag:
create_new_session_tree(current_session, parent_id)
else:
loc_json = {
"uuid": current_session.uuid,
"modules": current_session.modules_list,
"query": current_session.query,
"input": current_session.input_query,
"query_date": current_session.query_date.strftime('%Y-%m-%d %H:%M'),
"config": current_session.config_module,
"children": list()
}
sess["current_query"] = current_session.uuid
sess[sess.get("current_query")] = loc_json