diff --git a/App/Waybill/__init__.py b/App/Waybill/__init__.py index 78dd921..0c69085 100644 --- a/App/Waybill/__init__.py +++ b/App/Waybill/__init__.py @@ -1,16 +1,24 @@ from flask import request, Blueprint, render_template, session, current_app, redirect, url_for from checker import check_auth -from .model import waybill_model -waybill_bp = Blueprint('waybill_bp', __name__, template_folder='templates') +from .model import workpiece_list, clear +waybill_bp = Blueprint('waybill_bp', __name__, template_folder='templates', static_folder='static') -@waybill_bp.route('/', methods=['GET', 'POST']) +@waybill_bp.route('/', methods=['GET']) @check_auth +def index(): + lst = workpiece_list() + if lst.status: + return render_template('waybill.html', items=lst.result) + else: + return render_template('error.html', error_message=lst.error_message) + +@waybill_bp.route('/clear', methods=['GET']) +@check_auth +def clear_basket(): + clear() + return redirect(url_for('waybill_bp.index')) + +@waybill_bp.route('/', methods=['POST']) def waybill(): - if request.method == 'GET': - pack = waybill_model() - if pack.status: - return render_template('waybill.html', items=pack.result) - else: - return render_template('error.html', error_message=pack.error_message) print(request.form) return 'OK' \ No newline at end of file diff --git a/App/Waybill/model.py b/App/Waybill/model.py index d63f599..a1eda22 100644 --- a/App/Waybill/model.py +++ b/App/Waybill/model.py @@ -1,6 +1,6 @@ from .db.sql_provider import SQLProvider from .db.work import select_list -from flask import current_app +from flask import current_app, session from dataclasses import dataclass import os @@ -12,8 +12,11 @@ class InfoRespronse: sql_provider = SQLProvider(os.path.join(os.path.dirname(__file__), 'sql')) +def clear(): + if session.get('basket',{}): + session.pop('basket') -def waybill_model() -> InfoRespronse: +def workpiece_list() -> InfoRespronse: _sql = sql_provider.get('goods.sql', {}) result = select_list(current_app.config['db_config'], _sql) if result is None: diff --git a/App/static/css/waybill.css b/App/Waybill/static/css/waybill.css similarity index 100% rename from App/static/css/waybill.css rename to App/Waybill/static/css/waybill.css diff --git a/App/Waybill/templates/card.html b/App/Waybill/templates/card.html index a687103..2963232 100644 --- a/App/Waybill/templates/card.html +++ b/App/Waybill/templates/card.html @@ -9,7 +9,7 @@