add all files
This commit is contained in:
310
app.py
Normal file
310
app.py
Normal file
@@ -0,0 +1,310 @@
|
||||
from flask import Flask, render_template, redirect, url_for, request, jsonify
|
||||
from models import db, Oboruds, Auditory, Zametki
|
||||
from flask_migrate import Migrate
|
||||
from datetime import *
|
||||
import csv
|
||||
import random
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///project.db"
|
||||
app.jinja_env.auto_reload = True
|
||||
app.config['TEMPLATES_AUTO_RELOAD'] = True
|
||||
|
||||
app.secret_key = '6523e58bc0eec42c31b9635d5e0dfc23b6d119b73e633bf3a5284c79bb4a1ede'
|
||||
|
||||
db.init_app(app)
|
||||
|
||||
migrate = Migrate(app, db)
|
||||
|
||||
|
||||
@app.route("/", methods=['GET', 'POST'])
|
||||
def index():
|
||||
results = []
|
||||
results1 = []
|
||||
all_aud = db.session.query(Auditory).all()
|
||||
auds = []
|
||||
for item in all_aud:
|
||||
auds.append(item.audnazvanie)
|
||||
|
||||
if request.method == 'POST':
|
||||
p = request.form.get('srch').strip()
|
||||
all_aud = db.session.query(Auditory).all()
|
||||
s = db.session.query(Oboruds).filter(
|
||||
Oboruds.invNumber.contains(p)).first()
|
||||
if s:
|
||||
for item in all_aud:
|
||||
auds.append(item.audnazvanie)
|
||||
if s.aud_id is None:
|
||||
results.append([s.invNumber, s.nazvanie])
|
||||
else:
|
||||
results1.append(s.invNumber)
|
||||
results1.append(s.nazvanie)
|
||||
aud = db.session.get(Auditory, s.aud_id)
|
||||
results1.append(aud.audnazvanie)
|
||||
return render_template('index.html', aud=all_aud, results=results, res1=results1)
|
||||
return render_template('index.html', aud=all_aud, results=results, res1=results1)
|
||||
|
||||
|
||||
@app.route("/perenos", methods=['GET', 'POST'])
|
||||
def perenos():
|
||||
audid = request.args.get('audid')
|
||||
invnomer = request.args.get('invnum')
|
||||
ob = db.session.query(Oboruds).filter_by(invNumber=invnomer).first()
|
||||
ob.aud_id = audid
|
||||
db.session.commit()
|
||||
return jsonify({'success': True}, 200, {'ContentType': 'application/json'})
|
||||
|
||||
|
||||
@app.route("/addaud", methods=['GET', 'POST'])
|
||||
def addAud():
|
||||
return render_template('addaud.html', methods=['GET', 'POST'])
|
||||
|
||||
|
||||
@app.route('/searchonaud', methods=['GET', 'POST'])
|
||||
def searchonaud():
|
||||
all_aud = db.session.query(Auditory).all()
|
||||
res = []
|
||||
if request.method == 'GET' and request.args.get('auditory'):
|
||||
audid = request.args.get('auditory')
|
||||
q = db.session.query(Auditory, Oboruds).filter(
|
||||
Auditory.id == Oboruds.aud_id
|
||||
).filter(Auditory.id == audid
|
||||
).order_by(Oboruds.invNumber).all()
|
||||
results = []
|
||||
for auditory, oboruds in q:
|
||||
results.append({
|
||||
'auditory_id': auditory.id,
|
||||
'auditory_name': auditory.audnazvanie,
|
||||
'inv_number': oboruds.invNumber,
|
||||
'oboruds_id': oboruds.nazvanie,
|
||||
})
|
||||
return jsonify(results)
|
||||
|
||||
else:
|
||||
return render_template('searchonaud.html', aud=all_aud, res=res)
|
||||
|
||||
|
||||
@app.route("/addaudtodb", methods=['GET', 'POST'])
|
||||
def addaudtodb():
|
||||
if request.method == 'POST':
|
||||
aud = request.form.get('auditory')
|
||||
db.session.add(Auditory(audnazvanie=aud))
|
||||
db.session.commit()
|
||||
return redirect(url_for('addAud'))
|
||||
|
||||
|
||||
@app.route("/addoborudtodb", methods=['GET', 'POST'])
|
||||
def addoborudtodb():
|
||||
res = []
|
||||
if request.method == 'POST':
|
||||
audid = request.form.get('auditory')
|
||||
invnomer = request.form.get('invnomer')
|
||||
ob = db.session.query(Oboruds).filter_by(invNumber=invnomer).first()
|
||||
ob.aud_id = audid
|
||||
db.session.commit()
|
||||
return redirect(url_for('index'))
|
||||
|
||||
|
||||
@app.route('/all')
|
||||
def alloborud():
|
||||
|
||||
result = db.session.query(Oboruds).order_by(Oboruds.invNumber).all()
|
||||
|
||||
res = []
|
||||
|
||||
for ob in result:
|
||||
if ob.aud_id is not None:
|
||||
aud = db.session.query(Auditory).filter_by(id=ob.aud_id).first()
|
||||
res.append([ob.invNumber, ob.nazvanie, aud.audnazvanie])
|
||||
else:
|
||||
res.append([ob.invNumber, ob.nazvanie])
|
||||
|
||||
return render_template('all.html', res=res)
|
||||
|
||||
|
||||
@app.route('/updateduplicate', methods=['GET', 'POST'])
|
||||
def updateduplicate():
|
||||
if request.method == 'POST':
|
||||
aud = request.form.get('auditory_dubl')
|
||||
|
||||
|
||||
|
||||
|
||||
@app.route('/vneaud', methods=['GET', 'POST'])
|
||||
def vneaud():
|
||||
res = []
|
||||
data = db.session.query(Oboruds).filter(Oboruds.aud_id == None).all()
|
||||
|
||||
ak = db.session.query(Oboruds).all()
|
||||
|
||||
for dt in data:
|
||||
res.append([dt.invNumber, dt.nazvanie, dt.typeBalanse])
|
||||
|
||||
return render_template('vneaud.html', res=res, kolvo=len(data), all_kol=len(ak))
|
||||
|
||||
|
||||
@app.route('/zametki', methods=['GET', 'POST'])
|
||||
def zametki():
|
||||
zam = db.session.query(Zametki).filter(Zametki.rmdt == None).all()
|
||||
if request.method == 'POST':
|
||||
textzam = request.form.get('textzam')
|
||||
timeadd = datetime.now(timezone.utc)
|
||||
if len(textzam) > 0:
|
||||
db.session.add(Zametki(txtzam=textzam, created_date=timeadd))
|
||||
db.session.commit()
|
||||
return redirect(url_for('zametki'))
|
||||
|
||||
return render_template('zametki.html', zam=zam)
|
||||
|
||||
|
||||
@app.route('/zamrm', methods=['GET', 'POST'])
|
||||
def js2():
|
||||
zmid = request.args.get('zmid')
|
||||
ob = db.session.query(Zametki).filter_by(id=zmid).first()
|
||||
ob.rmdt = datetime.now(timezone.utc)
|
||||
db.session.commit()
|
||||
return jsonify({'success': True}), 200, {'ContentType': 'application/json'}
|
||||
|
||||
|
||||
@app.route('/zamsearch', methods=['GET', 'POST'])
|
||||
def zamsearch():
|
||||
p = request.form.get('srch')
|
||||
|
||||
searchedZam = db.session.query(Zametki).filter(
|
||||
Zametki.txtzam.contains(p)).all()
|
||||
|
||||
zam = []
|
||||
|
||||
for item in searchedZam:
|
||||
zam.append([item.txtzam, item.created_date])
|
||||
|
||||
return render_template('zametki.html', zam=zam)
|
||||
|
||||
# ==================================================================================
|
||||
|
||||
# Выгрузка в пдф
|
||||
|
||||
@app.route('/pdfexport')
|
||||
def pdfexport():
|
||||
auds = db.session.query(Auditory).all()
|
||||
print(auds)
|
||||
for aud in auds:
|
||||
q = db.session.query(Auditory, Oboruds).filter(
|
||||
Auditory.id == Oboruds.aud_id
|
||||
).filter(Auditory.id == aud.id
|
||||
).order_by(Oboruds.invNumber).all()
|
||||
print(q)
|
||||
|
||||
results = []
|
||||
for auditory, oboruds in q:
|
||||
results.append({
|
||||
'auditory_id': auditory.id,
|
||||
'auditory_name': auditory.audnazvanie,
|
||||
'inv_number': oboruds.invNumber,
|
||||
'oboruds_id': oboruds.nazvanie,
|
||||
})
|
||||
html = render_template('searchonaud.html', aud=auds, res=results)
|
||||
|
||||
return render_pdf(HTML(string=html))
|
||||
|
||||
|
||||
# ==================================================================================
|
||||
def createdb():
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
auds = ['519', '521', '521a', '522', '523',
|
||||
'601л',
|
||||
'602л',
|
||||
'603л',
|
||||
'604л',
|
||||
'605л',
|
||||
'606л',
|
||||
'607л',
|
||||
'608л',
|
||||
'609л',
|
||||
'610л',
|
||||
'611л',
|
||||
'612л',
|
||||
'613л',
|
||||
'616л',
|
||||
'617л',
|
||||
'618л',
|
||||
'619л',
|
||||
'620л',
|
||||
'621л',
|
||||
'622л',
|
||||
'626л',
|
||||
'627л',
|
||||
'703л',
|
||||
'710л',
|
||||
'713л']
|
||||
for aud in auds:
|
||||
db.session.add(Auditory(audnazvanie=aud))
|
||||
|
||||
db.session.commit()
|
||||
|
||||
with open('inventMavrin.csv', encoding='cp1251') as csv_file:
|
||||
csv_reader = csv.reader(csv_file, delimiter=';')
|
||||
for row in csv_reader:
|
||||
db.session.add(
|
||||
Oboruds(invNumber=row[0], nazvanie=row[1], typeBalanse='баланс'))
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def updateOborud():
|
||||
with app.app_context():
|
||||
db.session.query(Oboruds).update({Oboruds.typeBalanse: 'баланс'})
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def addZabalans():
|
||||
with app.app_context():
|
||||
with open('zabalans.csv', encoding='utf-8') as csv_file:
|
||||
csv_reader = csv.reader(csv_file, delimiter=';')
|
||||
for row in csv_reader:
|
||||
print(row)
|
||||
db.session.add(
|
||||
Oboruds(invNumber=row[0], nazvanie=row[1], typeBalanse="забаланс"))
|
||||
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def randomraspr():
|
||||
with app.app_context():
|
||||
while db.session.query(Oboruds).filter(Oboruds.aud_id == None).all():
|
||||
audid = random.choice(db.session.query(Auditory).all())
|
||||
oborud = random.choice(db.session.query(
|
||||
Oboruds).filter(Oboruds.aud_id == None).all())
|
||||
oborud.aud_id = audid.id
|
||||
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def randomzam():
|
||||
files = ['cf.txt', 'ci.txt', 'co.txt']
|
||||
|
||||
fio = []
|
||||
for i in range(20):
|
||||
tmp = []
|
||||
for file in files:
|
||||
f = open(file, "r", encoding="utf-8").readlines()
|
||||
tmp.append(random.choice(f))
|
||||
|
||||
fio.append((''.join(tmp)).replace('\n', ' ').replace('\t', ''))
|
||||
|
||||
print(fio)
|
||||
|
||||
for item in fio:
|
||||
timeadd = datetime.now(timezone.utc)
|
||||
with app.app_context():
|
||||
db.session.add(Zametki(txtzam=item, created_date=timeadd))
|
||||
db.session.commit()
|
||||
|
||||
# ==================================
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
app.run(debug=True, host='0.0.0.0', port='3800')
|
||||
Reference in New Issue
Block a user