add get data func
This commit is contained in:
107
app.py
107
app.py
@@ -175,44 +175,23 @@ def zamsearch():
|
||||
p = request.form.get('srch')
|
||||
|
||||
searchedZam = db.session.query(Zametki).filter(
|
||||
Zametki.txtzam.contains(p)).all()
|
||||
|
||||
Zametki.txtzam.contains(p)).ll()
|
||||
zam = []
|
||||
|
||||
for item in searchedZam:
|
||||
zam.append([item.txtzam, item.created_date])
|
||||
|
||||
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 ranomraspr():
|
||||
with app.app_context():
|
||||
while len(db.session.query(Oboruds).filter(Oboruds.aud_id == None).all()) > 0:
|
||||
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 createdb():
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
@@ -247,66 +226,28 @@ def createdb():
|
||||
|
||||
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: 'баланс'})
|
||||
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 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="забаланс"))
|
||||
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()
|
||||
|
||||
# ==================================
|
||||
db.session.commit()
|
||||
"""
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
app.run(debug=True, host='0.0.0.0', port='3800')
|
||||
#ranomraspr()
|
||||
#createdb()
|
||||
app.run(debug=True, host='0.0.0.0', port='3800')
|
||||
|
||||
Reference in New Issue
Block a user