05/24 Fix bugs
This commit is contained in:
+25
-24
@@ -8,6 +8,7 @@ from flask import (Blueprint, render_template, request, redirect, url_for,
|
||||
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,
|
||||
)
|
||||
from utils.decorators import login_required
|
||||
|
||||
@@ -23,6 +24,11 @@ STATUS_LABELS = {
|
||||
}
|
||||
|
||||
|
||||
def _ser(row):
|
||||
"""Make a DB dict JSON-serialisable (dates/times → ISO strings)."""
|
||||
return {k: v.isoformat() if hasattr(v, "isoformat") else v for k, v in row.items()}
|
||||
|
||||
|
||||
@bid_tracker_bp.route("/")
|
||||
@login_required
|
||||
def bids_list():
|
||||
@@ -66,7 +72,9 @@ def create():
|
||||
return redirect(url_for("bid_tracker.bids_list"))
|
||||
|
||||
try:
|
||||
create_bid(user["id"], title, url, source, sol_no, status, due_date, notes)
|
||||
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}'.")
|
||||
flash(f"Bid '{title}' added.", "success")
|
||||
logger.info(f"Bid '{title}' created by user_id={user['id']}.")
|
||||
except Exception as e:
|
||||
@@ -90,6 +98,8 @@ def edit(bid_id):
|
||||
|
||||
try:
|
||||
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}'.")
|
||||
flash(f"Bid '{title}' updated.", "success")
|
||||
logger.info(f"Bid id={bid_id} updated by user_id={user['id']}.")
|
||||
except Exception as e:
|
||||
@@ -105,6 +115,8 @@ def delete(bid_id):
|
||||
user = session["user"]
|
||||
try:
|
||||
delete_bid(user["id"], bid_id)
|
||||
log_action(user["id"], "DELETE_BID", "bid_tracker", bid_id,
|
||||
f"Deleted bid id={bid_id}.")
|
||||
flash("Bid deleted.", "success")
|
||||
logger.info(f"Bid id={bid_id} deleted by user_id={user['id']}.")
|
||||
except Exception as e:
|
||||
@@ -122,7 +134,9 @@ def add_update(bid_id):
|
||||
flash("Update content cannot be empty.", "warning")
|
||||
else:
|
||||
try:
|
||||
add_bid_update(user["id"], bid_id, content)
|
||||
upd_id = add_bid_update(user["id"], bid_id, content)
|
||||
log_action(user["id"], "ADD_BID_UPDATE", "bid_updates", upd_id,
|
||||
f"Posted update on bid_id={bid_id}.")
|
||||
flash("Update posted.", "success")
|
||||
logger.info(f"Bid update posted on bid_id={bid_id} by user_id={user['id']}.")
|
||||
except Exception as e:
|
||||
@@ -137,6 +151,8 @@ def delete_update(update_id):
|
||||
user = session["user"]
|
||||
try:
|
||||
delete_bid_update(user["id"], update_id)
|
||||
log_action(user["id"], "DELETE_BID_UPDATE", "bid_updates", update_id,
|
||||
f"Deleted bid update id={update_id}.")
|
||||
flash("Update deleted.", "success")
|
||||
logger.info(f"Bid update id={update_id} deleted by user_id={user['id']}.")
|
||||
except Exception as e:
|
||||
@@ -162,19 +178,9 @@ def bid_json(bid_id):
|
||||
is_owner = bid.get("added_by") == user["id"]
|
||||
can_edit = user["role"] == "admin" or is_owner
|
||||
|
||||
def ser(row):
|
||||
"""Make a dict JSON-serialisable (dates → str)."""
|
||||
out = {}
|
||||
for k, v in row.items():
|
||||
if hasattr(v, "isoformat"):
|
||||
out[k] = v.isoformat()
|
||||
else:
|
||||
out[k] = v
|
||||
return out
|
||||
|
||||
return jsonify({
|
||||
"bid": ser(bid),
|
||||
"updates": [ser(u) for u in updates],
|
||||
"bid": _ser(bid),
|
||||
"updates": [_ser(u) for u in updates],
|
||||
"can_edit": can_edit,
|
||||
"user_id": user["id"],
|
||||
"is_admin": user["role"] == "admin",
|
||||
@@ -191,16 +197,7 @@ def list_json():
|
||||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
def ser(row):
|
||||
out = {}
|
||||
for k, v in row.items():
|
||||
if hasattr(v, "isoformat"):
|
||||
out[k] = v.isoformat()
|
||||
else:
|
||||
out[k] = v
|
||||
return out
|
||||
|
||||
return jsonify([ser(b) for b in bids])
|
||||
return jsonify([_ser(b) for b in bids])
|
||||
|
||||
|
||||
@bid_tracker_bp.route("/<int:bid_id>/updates/json", methods=["POST"])
|
||||
@@ -213,6 +210,8 @@ def add_update_json(bid_id):
|
||||
return jsonify({"error": "Update content cannot be empty."}), 400
|
||||
try:
|
||||
update_id = add_bid_update(user["id"], bid_id, content)
|
||||
log_action(user["id"], "ADD_BID_UPDATE", "bid_updates", update_id,
|
||||
f"Posted update on bid_id={bid_id}.")
|
||||
logger.info(f"Bid update id={update_id} posted on bid_id={bid_id} by user_id={user['id']}.")
|
||||
return jsonify({"ok": True, "update_id": update_id})
|
||||
except Exception as e:
|
||||
@@ -227,6 +226,8 @@ def delete_update_json(update_id):
|
||||
user = session["user"]
|
||||
try:
|
||||
delete_bid_update(user["id"], update_id)
|
||||
log_action(user["id"], "DELETE_BID_UPDATE", "bid_updates", update_id,
|
||||
f"Deleted bid update id={update_id}.")
|
||||
logger.info(f"Bid update id={update_id} deleted by user_id={user['id']}.")
|
||||
return jsonify({"ok": True})
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user