fix(session) : problème de cache de persistance.py
mise en place de la génération dynamique de toutes les variables dépendant de session_id
This commit is contained in:
parent
c0ab1f1591
commit
359d17f628
@ -1,6 +1,7 @@
|
||||
import streamlit as st
|
||||
from config import ENV
|
||||
from utils.translations import _
|
||||
from utils.persistance import get_session_id
|
||||
|
||||
|
||||
def afficher_entete():
|
||||
@ -11,7 +12,7 @@ def afficher_entete():
|
||||
"""
|
||||
|
||||
if ENV == "dev":
|
||||
header += f"<p>🔧 {_("app.dev_mode")}</p>"
|
||||
header += f"<p>🔧 {_("app.dev_mode")} Session : {get_session_id()}</p>"
|
||||
else:
|
||||
header += f"<p>{_("header.subtitle")}</p>"
|
||||
|
||||
|
||||
11
fabnum.py
11
fabnum.py
@ -1,5 +1,8 @@
|
||||
import utils.persistance
|
||||
utils.persistance.update_session_paths()
|
||||
|
||||
import streamlit as st
|
||||
from utils.persistance import get_champ_statut
|
||||
from utils.persistance import get_champ_statut, get_session_id
|
||||
|
||||
st.set_page_config(
|
||||
page_title="Fabnum – Analyse de chaîne",
|
||||
@ -88,8 +91,6 @@ init_translations()
|
||||
# Pour tester d'autres langues, décommenter cette ligne :
|
||||
set_language("fr")
|
||||
|
||||
session_id = st.context.headers.get("x-session-id")
|
||||
|
||||
#
|
||||
# Important
|
||||
# Avec Selinux, il faut mettre les bons droits :
|
||||
@ -97,6 +98,7 @@ session_id = st.context.headers.get("x-session-id")
|
||||
# sudo semanage fcontext -a -t var_log_t '/var/log/nginx/fabnum-public\.access\.log'
|
||||
# sudo restorecon -v /var/log/nginx/fabnum-public.access.log
|
||||
#
|
||||
session_id = get_session_id()
|
||||
def get_total_bytes_for_session(session_id):
|
||||
total_bytes = 0
|
||||
try:
|
||||
@ -158,7 +160,7 @@ def fermer_page():
|
||||
st.markdown("""</section>""", unsafe_allow_html=True)
|
||||
st.markdown("</main>", unsafe_allow_html=True)
|
||||
|
||||
total_bytes = get_total_bytes_for_session(session_id)
|
||||
total_bytes = get_total_bytes_for_session(get_session_id())
|
||||
|
||||
afficher_pied_de_page()
|
||||
afficher_impact(total_bytes)
|
||||
@ -176,7 +178,6 @@ ia_nalyse_tab = _("navigation.ia_nalyse")
|
||||
plan_d_action_tab = _("navigation.plan_d_action")
|
||||
visualisations_tab = _("navigation.visualisations")
|
||||
|
||||
from utils.persistance import get_champ_statut
|
||||
navigation_onglet = get_champ_statut("navigation_onglet")
|
||||
|
||||
if navigation_onglet == instructions_tab:
|
||||
|
||||
@ -8,22 +8,17 @@ from pathlib import Path
|
||||
|
||||
load_dotenv(".env")
|
||||
|
||||
def initialise():
|
||||
SAVE_SESSIONS_PATH.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
def get_session_id():
|
||||
if "session_id" not in st.session_state:
|
||||
session_id = st.context.headers.get("x-session-id", "anonymous")
|
||||
st.session_state["session_id"] = session_id
|
||||
else:
|
||||
session_id = st.session_state["session_id"]
|
||||
def get_session_id() -> str:
|
||||
session_id = st.context.headers.get("x-session-id", "anonymous")
|
||||
return session_id
|
||||
|
||||
SAVE_STATUT = os.getenv("SAVE_STATUT", "statut_general.json")
|
||||
session_id = get_session_id()
|
||||
SAVE_SESSIONS_PATH = Path(f"tmp/sessions/{session_id}")
|
||||
SAVE_STATUT_PATH = SAVE_SESSIONS_PATH / SAVE_STATUT
|
||||
initialise()
|
||||
def update_session_paths():
|
||||
global SAVE_STATUT, SAVE_SESSIONS_PATH, SAVE_STATUT_PATH
|
||||
|
||||
SAVE_STATUT = os.getenv("SAVE_STATUT", "statut_general.json")
|
||||
SAVE_SESSIONS_PATH = Path(f"tmp/sessions/{get_session_id()}")
|
||||
SAVE_SESSIONS_PATH.mkdir(parents=True, exist_ok=True)
|
||||
SAVE_STATUT_PATH = SAVE_SESSIONS_PATH / SAVE_STATUT
|
||||
|
||||
def _maj_champ(fichier, cle: str, contenu: str = "") -> bool:
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user