June 25 - Optimize codes
This commit is contained in:
@@ -18,7 +18,8 @@ def dashboard():
|
||||
stats = get_admin_dashboard_stats()
|
||||
except Exception as e:
|
||||
logger.error(f"Dashboard stats error: {e}")
|
||||
stats = {"user_stats": [], "total_sites": 0, "total_users": 0, "active_today": 0}
|
||||
stats = {"user_stats": [], "total_sites": 0, "total_users": 0, "active_today": 0,
|
||||
"open_bids": 0, "bids_due_soon": 0, "ai_analyses_30d": 0}
|
||||
try:
|
||||
missed = get_missed_shifts_today()
|
||||
except Exception as e:
|
||||
|
||||
@@ -7,6 +7,7 @@ from flask import Blueprint, render_template, request, redirect, url_for, flash,
|
||||
from models import (
|
||||
get_all_users, create_user, update_user, delete_user,
|
||||
get_user_by_id, create_password_reset_token, log_action,
|
||||
invalidate_admin_stats_cache,
|
||||
)
|
||||
from utils.decorators import admin_required
|
||||
from utils.email import send_email
|
||||
@@ -38,6 +39,7 @@ def create():
|
||||
|
||||
try:
|
||||
create_user(admin_id, username, password, role, full_name, email)
|
||||
invalidate_admin_stats_cache()
|
||||
flash(f"User '{username}' created successfully.", "success")
|
||||
logger.info(f"User '{username}' created by admin_id={admin_id}.")
|
||||
except Exception as e:
|
||||
@@ -60,6 +62,7 @@ def edit(user_id):
|
||||
|
||||
try:
|
||||
update_user(admin_id, user_id, username, role, full_name, is_active, password, email)
|
||||
invalidate_admin_stats_cache()
|
||||
flash(f"User '{username}' updated successfully.", "success")
|
||||
logger.info(f"User id={user_id} updated by admin_id={admin_id}.")
|
||||
except ValueError as e:
|
||||
@@ -77,6 +80,7 @@ def delete(user_id):
|
||||
admin_id = session["user"]["id"]
|
||||
try:
|
||||
delete_user(admin_id, user_id)
|
||||
invalidate_admin_stats_cache()
|
||||
flash("User deleted successfully.", "success")
|
||||
logger.info(f"User id={user_id} deleted by admin_id={admin_id}.")
|
||||
except ValueError as e:
|
||||
|
||||
@@ -7,7 +7,7 @@ from flask import Blueprint, render_template, request, redirect, url_for, flash,
|
||||
from models import (
|
||||
get_all_websites, get_website_by_id, get_website_credentials,
|
||||
get_website_assigned_users, create_website, update_website, delete_website,
|
||||
get_all_users,
|
||||
get_all_users, invalidate_admin_stats_cache,
|
||||
)
|
||||
from utils.decorators import admin_required
|
||||
|
||||
@@ -78,6 +78,7 @@ def create():
|
||||
|
||||
try:
|
||||
create_website(admin_id, name, url, check_type, note, creds, visibility, assigned)
|
||||
invalidate_admin_stats_cache()
|
||||
flash(f"Website '{name}' created successfully.", "success")
|
||||
logger.info(f"Website '{name}' created by admin_id={admin_id}.")
|
||||
except Exception as e:
|
||||
@@ -101,6 +102,7 @@ def edit(website_id):
|
||||
|
||||
try:
|
||||
update_website(admin_id, website_id, name, url, check_type, note, creds, visibility, assigned)
|
||||
invalidate_admin_stats_cache()
|
||||
flash(f"Website '{name}' updated successfully.", "success")
|
||||
logger.info(f"Website id={website_id} updated by admin_id={admin_id}.")
|
||||
except Exception as e:
|
||||
@@ -116,6 +118,7 @@ def delete(website_id):
|
||||
admin_id = session["user"]["id"]
|
||||
try:
|
||||
delete_website(admin_id, website_id)
|
||||
invalidate_admin_stats_cache()
|
||||
flash("Website deleted (soft) successfully.", "success")
|
||||
logger.info(f"Website id={website_id} soft-deleted by admin_id={admin_id}.")
|
||||
except Exception as e:
|
||||
|
||||
@@ -11,6 +11,7 @@ from models import (
|
||||
get_all_bids, get_bid, create_bid, update_bid, delete_bid,
|
||||
get_bid_updates, add_bid_update, delete_bid_update, BID_STATUSES,
|
||||
log_action, get_bids_due_soon, get_admin_emails,
|
||||
invalidate_admin_stats_cache,
|
||||
)
|
||||
from utils.decorators import login_required, admin_required
|
||||
from utils.email import send_email
|
||||
@@ -78,6 +79,7 @@ def create():
|
||||
bid_id = create_bid(user["id"], title, url, source, sol_no, status, due_date, notes)
|
||||
log_action(user["id"], "CREATE_BID", "bid_tracker", bid_id,
|
||||
f"Created bid '{title}' status='{status}'.")
|
||||
invalidate_admin_stats_cache()
|
||||
flash(f"Bid '{title}' added.", "success")
|
||||
logger.info(f"Bid '{title}' created by user_id={user['id']}.")
|
||||
except Exception as e:
|
||||
@@ -103,6 +105,7 @@ def edit(bid_id):
|
||||
update_bid(user["id"], bid_id, title, url, source, sol_no, status, due_date, notes)
|
||||
log_action(user["id"], "UPDATE_BID", "bid_tracker", bid_id,
|
||||
f"Updated bid id={bid_id} status='{status}'.")
|
||||
invalidate_admin_stats_cache()
|
||||
flash(f"Bid '{title}' updated.", "success")
|
||||
logger.info(f"Bid id={bid_id} updated by user_id={user['id']}.")
|
||||
except Exception as e:
|
||||
@@ -120,6 +123,7 @@ def delete(bid_id):
|
||||
delete_bid(user["id"], bid_id)
|
||||
log_action(user["id"], "DELETE_BID", "bid_tracker", bid_id,
|
||||
f"Deleted bid id={bid_id}.")
|
||||
invalidate_admin_stats_cache()
|
||||
flash("Bid deleted.", "success")
|
||||
logger.info(f"Bid id={bid_id} deleted by user_id={user['id']}.")
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user