add sorting func

This commit is contained in:
2024-05-18 20:58:55 +03:00
parent 7b956d89bf
commit 946ad5c31f
2 changed files with 298 additions and 266 deletions

86
app.py
View File

@@ -9,12 +9,14 @@ import random
from urllib.parse import unquote from urllib.parse import unquote
from flask_httpauth import HTTPBasicAuth from flask_httpauth import HTTPBasicAuth
from werkzeug.security import generate_password_hash, check_password_hash from werkzeug.security import generate_password_hash, check_password_hash
from openpyxl import load_workbook import xlrd
import xlwt
import xlsxwriter
from xlutils.copy import copy
app = Flask(__name__) app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///project.db" app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///PRODproject.db"
app.jinja_env.auto_reload = True app.jinja_env.auto_reload = True
app.config['TEMPLATES_AUTO_RELOAD'] = True app.config['TEMPLATES_AUTO_RELOAD'] = True
@@ -25,13 +27,11 @@ db.init_app(app)
migrate = Migrate(app, db) migrate = Migrate(app, db)
@app.route("/login", methods=['GET', 'POST']) @app.route("/login", methods=['GET', 'POST'])
def login(): def login():
return render_template('login.html') return render_template('login.html')
@app.route("/", methods=['GET', 'POST']) @app.route("/", methods=['GET', 'POST'])
def index(): def index():
results = [] results = []
@@ -132,7 +132,7 @@ def getall():
oborud = db.session.query(Oboruds).order_by(Oboruds.invNumber).all() oborud = db.session.query(Oboruds).order_by(Oboruds.invNumber).all()
results = [] results = []
for oboruds in oborud : for oboruds in oborud:
if oboruds.aud_id is None: if oboruds.aud_id is None:
results.append({ results.append({
'invNumber': oboruds.invNumber, 'invNumber': oboruds.invNumber,
@@ -142,7 +142,7 @@ def getall():
'kolichestvo': oboruds.kolichestvo, 'kolichestvo': oboruds.kolichestvo,
'numberppasu': oboruds.numberppasu, 'numberppasu': oboruds.numberppasu,
'numberved': oboruds.numberved, 'numberved': oboruds.numberved,
'aud': "" }) 'aud': ""})
else: else:
aud = db.session.query(Auditory).filter_by(id=oboruds.aud_id).first() aud = db.session.query(Auditory).filter_by(id=oboruds.aud_id).first()
results.append({ results.append({
@@ -153,9 +153,7 @@ def getall():
'kolichestvo': oboruds.kolichestvo, 'kolichestvo': oboruds.kolichestvo,
'numberppasu': oboruds.numberppasu, 'numberppasu': oboruds.numberppasu,
'numberved': oboruds.numberved, 'numberved': oboruds.numberved,
'aud': aud.audnazvanie }) 'aud': aud.audnazvanie})
return jsonify(results) return jsonify(results)
@@ -211,38 +209,33 @@ def zamsearch():
@app.route('/addraspved', methods=['GET', 'POST']) @app.route('/addraspved', methods=['GET', 'POST'])
def addraspved(): def addraspved():
if request.method == 'POST': if request.method == 'POST':
query_string = request.data.decode() query_string = request.data.decode()
un_query_string = unquote(unquote(query_string)).split(',') un_query_string = unquote(unquote(query_string)).split(',')
ob = db.session.query(Oboruds).filter_by(invNumber=un_query_string[0]).first() ob = db.session.query(Oboruds).filter_by(invNumber=un_query_string[0]).first()
ob.numberved=un_query_string[1] ob.numberved = un_query_string[1]
ob.kolichestvo = un_query_string[2] ob.kolichestvo = un_query_string[2]
ob.balancenumber = un_query_string[3] ob.balancenumber = un_query_string[3]
ob.raspologenie=un_query_string[4] ob.raspologenie = un_query_string[4]
db.session.commit() db.session.commit()
db.session.close() db.session.close()
return jsonify({'success': True}, 200, {'ContentType': 'application/json'}) return jsonify({'success': True}, 200, {'ContentType': 'application/json'})
@app.route('/addoborudasu', methods=['GET', 'POST']) @app.route('/addoborudasu', methods=['GET', 'POST'])
def addoborud(): def addoborud():
if request.method == 'POST': if request.method == 'POST':
query_string = request.data.decode() query_string = request.data.decode()
un_query_string = unquote(unquote(query_string)).split(',') un_query_string = unquote(unquote(query_string)).split(',')
db.session.add( db.session.add(
Oboruds(invNumber=un_query_string[0], Oboruds(invNumber=un_query_string[0],
nazvanie=un_query_string[5], nazvanie=un_query_string[5],
raspologenie= un_query_string[4], raspologenie=un_query_string[4],
numberved=un_query_string[1], numberved=un_query_string[1],
kolichestvo=un_query_string[2], kolichestvo=un_query_string[2],
balancenumber=un_query_string[3] balancenumber=un_query_string[3]
@@ -251,17 +244,17 @@ def addoborud():
db.session.commit() db.session.commit()
return jsonify({'success': True}, 200, {'ContentType': 'application/json'}) return jsonify({'success': True}, 200, {'ContentType': 'application/json'})
# ================================================================================== # ==================================================================================
def ranomraspr(): def ranomraspr():
with app.app_context(): with app.app_context():
while len(db.session.query(Oboruds).filter(Oboruds.aud_id == None).all()) > 0: while len(db.session.query(Oboruds).filter(Oboruds.aud_id is None).all()) > 0:
audid = random.choice(db.session.query(Auditory).all()) audid = random.choice(db.session.query(Auditory).all())
oborud = random.choice(db.session.query(Oboruds).filter(Oboruds.aud_id == None).all()) oborud = random.choice(db.session.query(Oboruds).filter(Oboruds.aud_id is None).all())
oborud.aud_id = audid.id oborud.aud_id = audid.id
db.session.commit() db.session.commit()
@@ -308,32 +301,49 @@ def createdb():
db.session.commit() db.session.commit()
def write2excell():
wb = load_workbook("VedomostMOL.xlsx")
sheet = wb.worksheets[0]
x=19314 def write2excell():
wb = xlrd.open_workbook("VedIsh.xls")
sheet = wb.sheet_by_index(0)
newFile = copy(wb)
newSheet = newFile.get_sheet(0)
invNomerColum = 6
column_index = 1
for row_idx in range(sheet.nrows):
cell_value = sheet.cell(row_idx, column_index)
if cell_value:
tmp_inv_number = str(cell_value).split(':')[1]
try:
a = tmp_inv_number[1:-1]
inv_number = int(tmp_inv_number[1:-1])
with app.app_context(): with app.app_context():
joinQuery = db.session.query(Oboruds, Auditory).filter( auditory_obj = db.session.query(Auditory).join(Oboruds, Oboruds.aud_id == Auditory.id).filter(
Oboruds.aud_id == Auditory.id).filter( Oboruds.invNumber == inv_number).first()
Oboruds.invNumber==x)
print(joinQuery.all())
for i in range(10):
cell = 'B'+str(i+6)
print(auditory_obj.audnazvanie)
# cur.execute("SELECT aud.audnazvanie FROM oboruds AS ob JOIN auditory AS aud ON ob.aud_id = aud.id WHERE ob.invNumber = ?", (inv_number,))
except:
pass
"""
else:
#newSheet.write(row_idx, invNomerColum, "Нет инв номера")
pass
newFile.save("Ved31.xls")
"""
if __name__ == '__main__': if __name__ == '__main__':
#write2excell() #write2excell()
#ranomraspr()
#createdb()
app.run(debug=True, host='0.0.0.0', port='3800') app.run(debug=True, host='0.0.0.0', port='3800')

View File

@@ -9,14 +9,14 @@ function clearTable() {
} }
function getAllData(){ function getAllData() {
console.log('12321321') console.log('12321321')
clearTable(); clearTable();
let tableBody = document.getElementById('alldatatable').getElementsByTagName("tbody")[0]; let tableBody = document.getElementById('alldatatable').getElementsByTagName("tbody")[0];
i = 0; i = 0;
$.getJSON("/getall", function(data) { $.getJSON("/getall", function (data) {
$.each(data, function(index, item) { $.each(data, function (index, item) {
let newRow = tableBody.insertRow(tableBody.rows.length); let newRow = tableBody.insertRow(tableBody.rows.length);
let cell1 = newRow.insertCell(0); let cell1 = newRow.insertCell(0);
let cell2 = newRow.insertCell(1); let cell2 = newRow.insertCell(1);
@@ -35,14 +35,14 @@ function getAllData(){
cell4.innerText = item.nazvanie; cell4.innerText = item.nazvanie;
cell5.innerText = item.kolichestvo; cell5.innerText = item.kolichestvo;
cell6.innerText = item.balancenumber; cell6.innerText = item.balancenumber;
cell7.innerText= item.aud; cell7.innerText = item.aud;
cell8.innerText = item.raspologenie; cell8.innerText = item.raspologenie;
$(newRow).data('itemData', i); $(newRow).data('itemData', i);
$(newRow).on("click", function() { $(newRow).on("click", function () {
let vednumbertxt = newRow.cells[1].innerText; let vednumbertxt = newRow.cells[1].innerText;
let invnomertxt = newRow.cells[2].innerText; let invnomertxt = newRow.cells[2].innerText;
@@ -63,21 +63,21 @@ function getAllData(){
let rasp = document.getElementById('modal_rapolog') let rasp = document.getElementById('modal_rapolog')
invnom.innerText = invnomertxt invnom.innerText = invnomertxt
matcen.innerText = nazvanietxt.substring(0,20) matcen.innerText = nazvanietxt.substring(0, 20)
if (vednumbertxt.length>0){ if (vednumbertxt.length > 0) {
vedomost.value = vednumbertxt; vedomost.value = vednumbertxt;
} }
if (kolvotxt.length>0){ if (kolvotxt.length > 0) {
kolvo.value = kolvotxt; kolvo.value = kolvotxt;
} }
if (schettxt.length>0){ if (schettxt.length > 0) {
balancenumber.value = schettxt; balancenumber.value = schettxt;
} }
if (raspologtxt.length>0){ if (raspologtxt.length > 0) {
rasp.value = raspologtxt; rasp.value = raspologtxt;
} }
@@ -88,14 +88,14 @@ function getAllData(){
} }
$( document ).ready(function() { $(document).ready(function () {
getAllData(); getAllData();
}); });
$('#modalclose').click(function(){ $('#modalclose').click(function () {
let vednumber = document.getElementById('modal_vednumber') let vednumber = document.getElementById('modal_vednumber')
@@ -105,7 +105,6 @@ $('#modalclose').click(function(){
let rasp = document.getElementById('modal_rapolog') let rasp = document.getElementById('modal_rapolog')
vednumber.value = ''; vednumber.value = '';
kolvo.value = ''; kolvo.value = '';
balancenumber.value = ''; balancenumber.value = '';
@@ -114,10 +113,9 @@ $('#modalclose').click(function(){
$('#getmodal').modal('hide') $('#getmodal').modal('hide')
})
} ) $('#modalsavetodb').click(function () {
$('#modalsavetodb').click(function(){
let invnom = document.getElementById('modal_invnom') let invnom = document.getElementById('modal_invnom')
let vednumber = document.getElementById('modal_vednumber') let vednumber = document.getElementById('modal_vednumber')
@@ -128,8 +126,6 @@ $('#modalsavetodb').click(function(){
let nazv = document.getElementById('modal_nazvanie') let nazv = document.getElementById('modal_nazvanie')
let changeddata = new Array() let changeddata = new Array()
changeddata[0] = invnom.text; changeddata[0] = invnom.text;
@@ -139,7 +135,6 @@ $('#modalsavetodb').click(function(){
changeddata[4] = rasp.value; changeddata[4] = rasp.value;
let sendData = changeddata.join(',') let sendData = changeddata.join(',')
console.log(sendData) console.log(sendData)
@@ -151,7 +146,7 @@ $('#modalsavetodb').click(function(){
dataType: "json", dataType: "json",
data: sendData, data: sendData,
success: function(){ success: function () {
$('#getmodal').modal('hide') $('#getmodal').modal('hide')
vednumber.value = ''; vednumber.value = '';
@@ -168,13 +163,13 @@ $('#modalsavetodb').click(function(){
}) })
$('#addoborud').click(function(){ $('#addoborud').click(function () {
$('#addmodal').modal('show'); $('#addmodal').modal('show');
}) })
$('#modal2savetodb').click(function(){ $('#modal2savetodb').click(function () {
let invnomer = document.getElementById('modal2_invnom') let invnomer = document.getElementById('modal2_invnom')
let vednumber = document.getElementById('modal2_vednumber') let vednumber = document.getElementById('modal2_vednumber')
@@ -185,8 +180,6 @@ $('#modal2savetodb').click(function(){
let nazv = document.getElementById('modal2_nazvanie') let nazv = document.getElementById('modal2_nazvanie')
let changeddata = new Array() let changeddata = new Array()
changeddata[0] = invnomer.value; changeddata[0] = invnomer.value;
@@ -197,7 +190,6 @@ $('#modal2savetodb').click(function(){
changeddata[5] = nazv.value; changeddata[5] = nazv.value;
let sendData = changeddata.join(',') let sendData = changeddata.join(',')
console.log(sendData) console.log(sendData)
@@ -209,10 +201,10 @@ $('#modal2savetodb').click(function(){
dataType: "json", dataType: "json",
data: sendData, data: sendData,
success: function(){ success: function () {
vednumber.value = ''; vednumber.value = '';
invnomer.value= ''; invnomer.value = '';
nazvanie.value=''; nazvanie.value = '';
kolvo.value = ''; kolvo.value = '';
balancenumber.value = ''; balancenumber.value = '';
matcen.value = ''; matcen.value = '';
@@ -228,7 +220,7 @@ $('#modal2savetodb').click(function(){
}) })
$('#modal2close').click(function(){ $('#modal2close').click(function () {
let vednumber = document.getElementById('modal2_vednumber') let vednumber = document.getElementById('modal2_vednumber')
@@ -240,10 +232,9 @@ $('#modal2close').click(function(){
let rasp = document.getElementById('modal2_rapolog') let rasp = document.getElementById('modal2_rapolog')
vednumber.value = ''; vednumber.value = '';
invnomer.value= ''; invnomer.value = '';
nazvanie.value=''; nazvanie.value = '';
kolvo.value = ''; kolvo.value = '';
balancenumber.value = ''; balancenumber.value = '';
matcen.value = ''; matcen.value = '';
@@ -252,9 +243,40 @@ $('#modal2close').click(function(){
$('#addmodal').modal('hide') $('#addmodal').modal('hide')
})
} )
$('#modal2').on('hidden.bs.modal', function () { $('#modal2').on('hidden.bs.modal', function () {
location.reload(); location.reload();
}) })
$(document).ready(function () {
// Слушаем событие клика по заголовкам таблицы
$('#alldatatable thead th').on('click', function () {
var columnIndex = $(this).index(); // Индекс колонки
var sortColumn = $(this).text().toLowerCase(); // Текст заголовка колонки
// Сортируем таблицу по выбранной колонке
$('#alldatatable tbody tr').sort(function (a, b) {
var valA;
var valB;
if (isNaN(parseFloat($(a).find('td:eq(' + columnIndex + ')').text()))) {
// если это текстовая колонка, то сортируем по алфавиту
valA = $(a).find('td:eq(' + columnIndex + ')').text().toLowerCase();
valB = $(b).find('td:eq(' + columnIndex + ')').text().toLowerCase();
} else {
// если это числовая колонка, то сортируем по числовому значению
valA = parseFloat($(a).find('td:eq(' + columnIndex + ')').text());
valB = parseFloat($(b).find('td:eq(' + columnIndex + ')').text());
}
if (valA < valB) return -1;
if (valA > valB) return 1;
return 0;
}).appendTo('#alldatatable tbody');
// Обновляем классы для активной колонки
$('#alldatatable thead th').removeClass('active');
$(this).addClass('active');
});
});