release: publish saldo 0.1.0
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
from .routes import months_bp
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from flask import Blueprint, current_app, flash, redirect, render_template, request, url_for
|
||||
from flask_login import login_required
|
||||
|
||||
from app.extensions import db
|
||||
from app.models import Month
|
||||
|
||||
months_bp = Blueprint("months", __name__, url_prefix="/months")
|
||||
|
||||
|
||||
@months_bp.route("/")
|
||||
@login_required
|
||||
def index():
|
||||
months = Month.query.order_by(Month.year.desc(), Month.month.desc()).all()
|
||||
return render_template("months/index.html", months=months)
|
||||
|
||||
|
||||
@months_bp.route("/create", methods=["POST"])
|
||||
@login_required
|
||||
def create():
|
||||
label = request.form.get("label", "")
|
||||
month = current_app.extensions["saldo.month_service"].get_or_create_by_label(label)
|
||||
flash(f"Monat {month.label} ist bereit.", "success")
|
||||
return redirect(url_for("planning.detail", label=month.label))
|
||||
|
||||
|
||||
@months_bp.route("/<label>/copy", methods=["POST"])
|
||||
@login_required
|
||||
def copy(label: str):
|
||||
source_month = Month.query.filter_by(label=label).first_or_404()
|
||||
target_label = request.form.get("target_label", "")
|
||||
year, month_num = [int(part) for part in target_label.split("-")]
|
||||
current_app.extensions["saldo.month_service"].copy_month(
|
||||
source_month, year, month_num, auto_created=False
|
||||
)
|
||||
db.session.commit()
|
||||
flash(f"{target_label} wurde aus {label} kopiert.", "success")
|
||||
return redirect(url_for("months.index"))
|
||||
|
||||
|
||||
@months_bp.route("/<label>/toggle-lock", methods=["POST"])
|
||||
@login_required
|
||||
def toggle_lock(label: str):
|
||||
month = Month.query.filter_by(label=label).first_or_404()
|
||||
month.is_locked = not month.is_locked
|
||||
db.session.commit()
|
||||
flash(f"Monat {label} wurde {'gesperrt' if month.is_locked else 'entsperrt'}.", "info")
|
||||
return redirect(url_for("months.index"))
|
||||
Reference in New Issue
Block a user