**Refactor: Replace reset_flag with wait function for consistent delay handling**
Browse files- Added a new `wait` function to handle delays consistently
- Updated `invoke_long_callback` calls to use `wait` instead of `reset_flag` for delay
- Modified `reset_flag` function to accept a `success` parameter for better flag management
- Ensured consistent 2.0 second delay across all relevant functions
This refactor improves code consistency and maintainability by centralizing delay handling and updating the flag management process.
functi.py
CHANGED
|
@@ -85,6 +85,9 @@ client_secret = os.environ.get("CLIENT_SECRET")
|
|
| 85 |
|
| 86 |
linkedin = OAuth2Session(client_id, redirect_uri=redirect_url, scope=scope)
|
| 87 |
|
|
|
|
|
|
|
|
|
|
| 88 |
def replanifier_toutes_les_tâches(df):
|
| 89 |
# Efface toutes les anciennes tâches
|
| 90 |
df.apply(
|
|
@@ -271,7 +274,7 @@ def add_scheduling(state):
|
|
| 271 |
print(f"❌ Error in add_scheduling: {e}", flush=True)
|
| 272 |
|
| 273 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 274 |
-
invoke_long_callback(state, reset_flag, ["add_scheduling",
|
| 275 |
|
| 276 |
def planning():
|
| 277 |
df = db_manager.fetch_schedule_table()
|
|
@@ -315,7 +318,7 @@ def post_publishing(state) :
|
|
| 315 |
print([resp.status_code, resp.text],flush = True)
|
| 316 |
|
| 317 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 318 |
-
invoke_long_callback(state, reset_flag, ["post_publishing",
|
| 319 |
|
| 320 |
def post_generation(state) :
|
| 321 |
if not state.has_post_generation:
|
|
@@ -326,7 +329,7 @@ def post_generation(state) :
|
|
| 326 |
)
|
| 327 |
|
| 328 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 329 |
-
invoke_long_callback(state, reset_flag, ["post_generation",
|
| 330 |
|
| 331 |
def authen(state) :
|
| 332 |
if not state.has_authen:
|
|
@@ -339,10 +342,9 @@ def authen(state) :
|
|
| 339 |
navigate(state, state.urlss)
|
| 340 |
|
| 341 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 342 |
-
invoke_long_callback(state, reset_flag)
|
| 343 |
|
| 344 |
-
def reset_flag(state, action):
|
| 345 |
-
time.sleep(1)
|
| 346 |
if action == "on_my_clicking":
|
| 347 |
state.has_on_my_clicking = False
|
| 348 |
elif action == "add_source":
|
|
@@ -379,7 +381,7 @@ def on_my_clicking(state, action, payload) :
|
|
| 379 |
on_logout(state)
|
| 380 |
navigate(state, payload["args"][0])
|
| 381 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 382 |
-
invoke_long_callback(state, reset_flag, ["on_my_clicking",
|
| 383 |
|
| 384 |
return " "
|
| 385 |
|
|
@@ -397,7 +399,7 @@ def add_source(state) :
|
|
| 397 |
state.Source_table = pd.DataFrame(data)
|
| 398 |
|
| 399 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 400 |
-
invoke_long_callback(state, reset_flag, ["add_source",
|
| 401 |
|
| 402 |
def delete_source(state, var_name: str, payload: dict) :
|
| 403 |
if not state.has_delete_source:
|
|
@@ -412,7 +414,7 @@ def delete_source(state, var_name: str, payload: dict) :
|
|
| 412 |
db_manager.delete_from_table("Source",valeurs)
|
| 413 |
|
| 414 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 415 |
-
invoke_long_callback(state, reset_flag, ["delete_source",
|
| 416 |
|
| 417 |
def delete_account(state, var_name: str, payload: dict) :
|
| 418 |
if not state.has_delete_account:
|
|
@@ -427,7 +429,7 @@ def delete_account(state, var_name: str, payload: dict) :
|
|
| 427 |
db_manager.delete_from_table("Social_network",valeurs)
|
| 428 |
|
| 429 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 430 |
-
invoke_long_callback(state, reset_flag, ["delete_account",
|
| 431 |
|
| 432 |
def delete_schedule(state, var_name: str, payload: dict) :
|
| 433 |
if not state.has_delete_schedule:
|
|
@@ -442,7 +444,7 @@ def delete_schedule(state, var_name: str, payload: dict) :
|
|
| 442 |
db_manager.delete_from_table("Scheduling",valeurs)
|
| 443 |
|
| 444 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 445 |
-
invoke_long_callback(state, reset_flag, ["delete_schedule",
|
| 446 |
|
| 447 |
def on_login(state, payload):
|
| 448 |
"""Handle login form submission"""
|
|
@@ -485,7 +487,7 @@ def on_login(state, payload):
|
|
| 485 |
state.message = "Email ou mot de passe incorrect."
|
| 486 |
|
| 487 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 488 |
-
invoke_long_callback(state, reset_flag, ["on_login",
|
| 489 |
|
| 490 |
def on_register(state):
|
| 491 |
"""Handle registration form submission"""
|
|
@@ -521,7 +523,7 @@ def on_register(state):
|
|
| 521 |
state.message = message or "Erreur lors de l'inscription. Veuillez réessayer."
|
| 522 |
|
| 523 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 524 |
-
invoke_long_callback(state, reset_flag, ["on_register",
|
| 525 |
|
| 526 |
def on_logout(state):
|
| 527 |
if not state.has_on_logout:
|
|
@@ -536,7 +538,7 @@ def on_logout(state):
|
|
| 536 |
state.login_password = ""
|
| 537 |
|
| 538 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 539 |
-
invoke_long_callback(state, reset_flag, ["on_logout",
|
| 540 |
|
| 541 |
def toggle_register(state):
|
| 542 |
"""Toggle between login and register forms"""
|
|
@@ -551,4 +553,4 @@ def toggle_register(state):
|
|
| 551 |
state.confirm_password = ""
|
| 552 |
|
| 553 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 554 |
-
invoke_long_callback(state, reset_flag, ["toggle_register",
|
|
|
|
| 85 |
|
| 86 |
linkedin = OAuth2Session(client_id, redirect_uri=redirect_url, scope=scope)
|
| 87 |
|
| 88 |
+
def wait(delay):
|
| 89 |
+
time.sleep(delay)
|
| 90 |
+
|
| 91 |
def replanifier_toutes_les_tâches(df):
|
| 92 |
# Efface toutes les anciennes tâches
|
| 93 |
df.apply(
|
|
|
|
| 274 |
print(f"❌ Error in add_scheduling: {e}", flush=True)
|
| 275 |
|
| 276 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 277 |
+
invoke_long_callback(state, wait, [2.0], reset_flag, ["add_scheduling", True])
|
| 278 |
|
| 279 |
def planning():
|
| 280 |
df = db_manager.fetch_schedule_table()
|
|
|
|
| 318 |
print([resp.status_code, resp.text],flush = True)
|
| 319 |
|
| 320 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 321 |
+
invoke_long_callback(state, wait, [2.0], reset_flag, ["post_publishing", True])
|
| 322 |
|
| 323 |
def post_generation(state) :
|
| 324 |
if not state.has_post_generation:
|
|
|
|
| 329 |
)
|
| 330 |
|
| 331 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 332 |
+
invoke_long_callback(state, wait, [2.0], reset_flag, ["post_generation", True])
|
| 333 |
|
| 334 |
def authen(state) :
|
| 335 |
if not state.has_authen:
|
|
|
|
| 342 |
navigate(state, state.urlss)
|
| 343 |
|
| 344 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 345 |
+
invoke_long_callback(state, wait, [2.0], reset_flag, ["authen", True])
|
| 346 |
|
| 347 |
+
def reset_flag(state, action, success):
|
|
|
|
| 348 |
if action == "on_my_clicking":
|
| 349 |
state.has_on_my_clicking = False
|
| 350 |
elif action == "add_source":
|
|
|
|
| 381 |
on_logout(state)
|
| 382 |
navigate(state, payload["args"][0])
|
| 383 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 384 |
+
invoke_long_callback(state, wait, [2.0], reset_flag, ["on_my_clicking", True])
|
| 385 |
|
| 386 |
return " "
|
| 387 |
|
|
|
|
| 399 |
state.Source_table = pd.DataFrame(data)
|
| 400 |
|
| 401 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 402 |
+
invoke_long_callback(state, wait, [2.0], reset_flag, ["add_source", True])
|
| 403 |
|
| 404 |
def delete_source(state, var_name: str, payload: dict) :
|
| 405 |
if not state.has_delete_source:
|
|
|
|
| 414 |
db_manager.delete_from_table("Source",valeurs)
|
| 415 |
|
| 416 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 417 |
+
invoke_long_callback(state, wait, [2.0], reset_flag, ["delete_source", True])
|
| 418 |
|
| 419 |
def delete_account(state, var_name: str, payload: dict) :
|
| 420 |
if not state.has_delete_account:
|
|
|
|
| 429 |
db_manager.delete_from_table("Social_network",valeurs)
|
| 430 |
|
| 431 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 432 |
+
invoke_long_callback(state, wait, [2.0], reset_flag, ["delete_account", True])
|
| 433 |
|
| 434 |
def delete_schedule(state, var_name: str, payload: dict) :
|
| 435 |
if not state.has_delete_schedule:
|
|
|
|
| 444 |
db_manager.delete_from_table("Scheduling",valeurs)
|
| 445 |
|
| 446 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 447 |
+
invoke_long_callback(state, wait, [2.0], reset_flag, ["delete_schedule", True])
|
| 448 |
|
| 449 |
def on_login(state, payload):
|
| 450 |
"""Handle login form submission"""
|
|
|
|
| 487 |
state.message = "Email ou mot de passe incorrect."
|
| 488 |
|
| 489 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 490 |
+
invoke_long_callback(state, wait, [2.0], reset_flag, ["on_login", True])
|
| 491 |
|
| 492 |
def on_register(state):
|
| 493 |
"""Handle registration form submission"""
|
|
|
|
| 523 |
state.message = message or "Erreur lors de l'inscription. Veuillez réessayer."
|
| 524 |
|
| 525 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 526 |
+
invoke_long_callback(state, wait, [2.0], reset_flag, ["on_register", True])
|
| 527 |
|
| 528 |
def on_logout(state):
|
| 529 |
if not state.has_on_logout:
|
|
|
|
| 538 |
state.login_password = ""
|
| 539 |
|
| 540 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 541 |
+
invoke_long_callback(state, wait, [2.0], reset_flag, ["on_logout", True])
|
| 542 |
|
| 543 |
def toggle_register(state):
|
| 544 |
"""Toggle between login and register forms"""
|
|
|
|
| 553 |
state.confirm_password = ""
|
| 554 |
|
| 555 |
# Utiliser invoke_long_callback pour la réinitialisation du flag
|
| 556 |
+
invoke_long_callback(state, wait, [2.0], reset_flag, ["toggle_register", True])
|