This repository has been archived on 2025-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
Files
RIS/App/Report/__init__.py

70 lines
3.0 KiB
Python

from flask import request, Blueprint, render_template, session, url_for
from checker import check_auth
from os import path
from .report_model import view_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('/menu')
@check_auth
def menu():
if request.method == 'GET':
return render_template('report_menu.html')
@report_bp.route('/create', methods=['GET', 'POST'])
@check_auth
def create():
if request.method == 'GET':
return render_template('report_basic.html',
is_write=True,
title='Создание отчетов',
items=report_list)
else:
data = dict(id=request.form.get('category'),
month=request.form.get('month'),
year=request.form.get('year'))
with open(path.join(path.dirname(__file__), f'access/{data['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',
is_write=False,
title='Просмотр отчетов',
items=report_list)
else:
data = dict(id=request.form.get('category'),
month=request.form.get('month'),
year=request.form.get('year'))
with open(path.join(path.dirname(__file__), f'access/{data['id']}.json')) as f:
report_access = json.load(f)
if session['role'] in report_access['read']:
ready_report = view_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='Недосточно прав для чтения данного отчета!')