Даты как параметры + страница для ошибок

This commit is contained in:
Anton Kamalov
2024-10-24 20:35:06 +03:00
parent e1d0510669
commit e97300f860
4 changed files with 23 additions and 12 deletions

View File

@@ -3,6 +3,7 @@ from os import path
from Database.sql_provider import SQLProvider
from checker import check_auth
from .requests_route import route
from datetime import date
import json
with open(path.join(path.dirname(__file__), 'zapros_menu.json')) as f:
@@ -16,8 +17,6 @@ requests_bp = Blueprint('requests_bp', __name__, template_folder='templates')
def requests():
if request.method == 'GET':
return render_template('zapros_menu.html', options=requests_list)
else:
return 'error'
@requests_bp.route('/req1', methods=['GET', 'POST'])
@check_auth
@@ -27,7 +26,7 @@ def sklad_zapros():
if zagotovki.status:
return render_template('sklad_zapros.html', materials=zagotovki.result)
else:
return zagotovki.error_message
return render_template('error.html', error_message=zagotovki.error_message)
else:
material = dict(request.form)
zagotovki = route(session['db_config'], material, sql_provider, 'zapros1.sql')
@@ -35,7 +34,7 @@ def sklad_zapros():
header = f'Заготовки на складе из материала \'{material["material"]}\''
return render_template('output.html', items=zagotovki.result, object=header)
else:
return zagotovki.error_message
return render_template('error.html', error_message=zagotovki.error_message)
@requests_bp.route('/req2', methods=['GET', 'POST'])
@check_auth
@@ -43,15 +42,16 @@ def zagotovki_ship():
if request.method == 'GET':
zagotovki = route(session['db_config'], {}, sql_provider, 'zagotovki.sql')
if zagotovki.status:
return render_template('zagotovki_ship.html', materials=zagotovki.result)
date_from = '2000-01-01'
date_to = date.today().strftime('%Y-%m-%d')
return render_template('zagotovki_ship.html', materials=zagotovki.result, date_from=date_from, date_to=date_to)
else:
return zagotovki.error_message
return render_template('error.html', error_message=zagotovki.error_message)
else:
material = dict(request.form)
print(material)
zagotovki = route(session['db_config'], material, sql_provider, 'zapros2.sql')
if zagotovki.status:
header = f'Поставленные заготовки из материала \'{material["material"]}\''
return render_template('output.html', items=zagotovki.result, object=header)
else:
return zagotovki.error_message
return render_template('error.html', error_message=zagotovki.error_message)

View File

@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Ошибка</title>
<link href="/static/css/main.css" type="text/css" rel="stylesheet">
</head>
<body>
<h1>Произошла ошибка</h1>
<p>{{ error_message }}.</p>
<a href="{{ url_for('index') }}"><button>На главную страницу</button></a>
</body>
</html>

View File

@@ -19,8 +19,8 @@
{% endfor %}
</select>
<p>Выберите даты:</p>
<p>с <input type="date" name="date_from" required min="2000-01-01" max="2024-12-31" id="date_from"></p>
<p>по <input type="date" name="date_to" required min="2000-01-01" max="2024-12-31" id="date_to"></p>
<p>с <input type="date" name="date_from" required min={{ date_from }} max={{ date_to }} id="date_from"></p>
<p>по <input type="date" name="date_to" required min={{ date_from }} max= {{ date_to }}" id="date_to"></p>
<input type="submit" value="Отправить">
</form>
<div class="return">

View File

@@ -1,9 +1,7 @@
from flask import Flask, render_template, session
from Requests.requests import requests_bp
from Auth.auth import auth_bp
from os import path
from checker import check_auth
import json
app = Flask(__name__)
app.secret_key = 'suplex'