|
|
|
|
|
from flask import Blueprint, render_template, request, redirect, url_for, flash, session |
|
from src.extensions import db |
|
from src.decorators import login_required |
|
from src.models.amendment import Amendment |
|
from src.models.legislation import Legislation |
|
|
|
amendment_bp = Blueprint("amendment", __name__, url_prefix="/amendments", template_folder="../templates/amendments") |
|
|
|
@amendment_bp.route("/") |
|
@login_required |
|
def list_amendments(): |
|
"""Lists all proposed amendments.""" |
|
|
|
amendments = Amendment.query.order_by(Amendment.last_updated.desc()).all() |
|
return render_template("list_amendments.html", amendments=amendments) |
|
|
|
@amendment_bp.route("/propose", methods=["GET", "POST"]) |
|
@login_required |
|
def propose_amendment(): |
|
"""Handles proposing a new amendment for existing legislation.""" |
|
if request.method == "POST": |
|
legislation_id = request.form.get("legislation_id") |
|
proposed_changes = request.form.get("proposed_changes") |
|
rationale = request.form.get("rationale") |
|
|
|
if not legislation_id or not proposed_changes: |
|
flash("Legislation ID and Proposed Changes are required.", "warning") |
|
|
|
legislations = Legislation.query.filter_by(status="Active").order_by(Legislation.title).all() |
|
return render_template("propose_amendment.html", legislations=legislations, legislation_id=legislation_id, proposed_changes=proposed_changes, rationale=rationale) |
|
|
|
|
|
author_id = session.get("user_id") |
|
|
|
new_amendment = Amendment( |
|
legislation_id=int(legislation_id), |
|
proposed_changes=proposed_changes, |
|
rationale=rationale, |
|
author_id=author_id |
|
) |
|
|
|
|
|
|
|
|
|
try: |
|
db.session.add(new_amendment) |
|
db.session.commit() |
|
flash(f"Amendment proposed successfully for Legislation ID {legislation_id}.", "success") |
|
return redirect(url_for("amendment.view_amendment", amendment_id=new_amendment.id)) |
|
except Exception as e: |
|
db.session.rollback() |
|
flash(f"Error proposing amendment: {e}", "danger") |
|
|
|
|
|
|
|
legislations = Legislation.query.filter_by(status="Active").order_by(Legislation.title).all() |
|
return render_template("propose_amendment.html", legislations=legislations) |
|
|
|
@amendment_bp.route("/<int:amendment_id>") |
|
@login_required |
|
def view_amendment(amendment_id): |
|
"""Displays a single amendment for viewing.""" |
|
amendment = Amendment.query.get_or_404(amendment_id) |
|
|
|
return render_template("view_amendment.html", amendment=amendment) |
|
|
|
|
|
|
|
|