Fix in Requests + in Report part
This commit is contained in:
@@ -1,21 +1,67 @@
|
||||
from flask import request, Blueprint, render_template
|
||||
from flask import request, Blueprint, render_template, session, url_for
|
||||
from checker import check_auth
|
||||
from os import path
|
||||
from .report_model import sales_report, make_report
|
||||
import json
|
||||
|
||||
with open(path.join(path.dirname(__file__), 'reports.json')) as f:
|
||||
report_list = json.load(f)
|
||||
|
||||
|
||||
report_bp = Blueprint('report_bp', __name__, template_folder='templates')
|
||||
|
||||
@report_bp.route('/', methods=['GET', 'POST'])
|
||||
@report_bp.route('/menu')
|
||||
@check_auth
|
||||
def menu():
|
||||
if request.method == 'GET':
|
||||
return render_template('report_menu.html', options=report_list)
|
||||
|
||||
@report_bp.route('/quaterly', methods=['GET', 'POST'])
|
||||
return render_template('report_menu.html')
|
||||
|
||||
@report_bp.route('/create', methods=['GET', 'POST'])
|
||||
@check_auth
|
||||
def quaterly():
|
||||
def create():
|
||||
if request.method == 'GET':
|
||||
return render_template('quaterly.html')
|
||||
return render_template('report_basic.html',
|
||||
write=True,
|
||||
title='Создание отчета',
|
||||
items = report_list)
|
||||
else:
|
||||
data = dict(month=request.form.get('month'), year=request.form.get('year'))
|
||||
id = request.form.get('category')
|
||||
with open(path.join(path.dirname(__file__), f'access/{id}.json')) as f:
|
||||
report_access = json.load(f)
|
||||
|
||||
if session['role'] in report_access['write']:
|
||||
proc_name = report_access['procedure']
|
||||
ready_report = make_report(data, proc_name)
|
||||
if ready_report.status:
|
||||
return render_template("OK.html")
|
||||
else:
|
||||
return render_template("error.html", error_message=ready_report.error_message)
|
||||
else:
|
||||
return render_template("error.html", error_message='Недостаточно прав для создания данного отчета!')
|
||||
|
||||
@report_bp.route('/view', methods=['GET', 'POST'])
|
||||
@check_auth
|
||||
def view():
|
||||
if request.method == 'GET':
|
||||
return render_template('report_basic.html',
|
||||
write=False,
|
||||
title='Просмотр отчета',
|
||||
items = report_list)
|
||||
else:
|
||||
data = dict(month=request.form.get('month'), year=request.form.get('year'))
|
||||
id = request.form.get('category')
|
||||
with open(path.join(path.dirname(__file__), f'access/{id}.json')) as f:
|
||||
report_access = json.load(f)
|
||||
|
||||
if session['role'] in report_access['read']:
|
||||
ready_report = sales_report(data, report_access['view'])
|
||||
if ready_report.status:
|
||||
title= f'{report_access["title"]} за {data["month"]}-{data["year"]}'
|
||||
return render_template("output.html", items=ready_report.result,
|
||||
header=title,
|
||||
link = url_for('report_bp.menu'))
|
||||
else:
|
||||
return render_template("error.html", error_message=ready_report.error_message)
|
||||
else:
|
||||
return render_template("error.html", error_message='Недосточно прав для чтения данного отчета!')
|
||||
Reference in New Issue
Block a user