Initial commit: aplicatie de cantarire si etichetare
Aplicatie Flask + SQLite pentru productie alimentara: cantarirea componentelor unui produs finit si tiparirea etichetei prin QZ Tray. - produse finite (retete) formate din componente cantarite - designer vizual de etichete (mm/px, zona sigura, campuri variabile, cod QR cu continut din mai multe bucati) - legare produs finit -> sablon de eticheta - navigare pe doua taburi: Cantarire / Setari - administrare: componente, produse finite, sabloane, campuri, istoric - backup, resetare baza de date, checklist de pregatire, /healthz - CLI de administrare si serviciu systemd pentru productie - vendor/syncpulse-scale-bridge (GPL-3.0-or-later) pentru citirea cantarului
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
"""Administrarea componentelor cantarite."""
|
||||
from __future__ import annotations
|
||||
|
||||
from flask import Blueprint, flash, redirect, render_template, request, url_for
|
||||
|
||||
from ..repositories import (
|
||||
ValidationError,
|
||||
create_component,
|
||||
delete_component,
|
||||
get_component,
|
||||
list_components,
|
||||
update_component,
|
||||
)
|
||||
|
||||
bp = Blueprint("components", __name__, url_prefix="/componente")
|
||||
|
||||
|
||||
@bp.get("")
|
||||
def index():
|
||||
return render_template("components/list.html",
|
||||
components=list_components(include_inactive=True))
|
||||
|
||||
|
||||
@bp.route("/nou", methods=["GET", "POST"])
|
||||
def create():
|
||||
if request.method == "POST":
|
||||
try:
|
||||
create_component(request.form)
|
||||
flash("Componentul a fost adaugat.", "success")
|
||||
return redirect(url_for("components.index"))
|
||||
except ValidationError as exc:
|
||||
flash(str(exc), "error")
|
||||
return render_template("components/form.html", component=dict(request.form), is_new=True)
|
||||
|
||||
|
||||
@bp.route("/<int:component_id>/editare", methods=["GET", "POST"])
|
||||
def edit(component_id: int):
|
||||
component = get_component(component_id)
|
||||
if component is None:
|
||||
flash("Componentul nu exista.", "error")
|
||||
return redirect(url_for("components.index"))
|
||||
|
||||
if request.method == "POST":
|
||||
try:
|
||||
update_component(component_id, request.form)
|
||||
flash("Componentul a fost actualizat.", "success")
|
||||
return redirect(url_for("components.index"))
|
||||
except ValidationError as exc:
|
||||
flash(str(exc), "error")
|
||||
component = {**component, **dict(request.form)}
|
||||
return render_template("components/form.html", component=component, is_new=False)
|
||||
|
||||
|
||||
@bp.post("/<int:component_id>/stergere")
|
||||
def remove(component_id: int):
|
||||
delete_component(component_id)
|
||||
flash("Componentul a fost sters sau dezactivat (daca e folosit intr-o reteta).", "success")
|
||||
return redirect(url_for("components.index"))
|
||||
Reference in New Issue
Block a user