From 40bb5d83f018384d4383266ba105c13f0e1a4e58 Mon Sep 17 00:00:00 2001 From: danamir Date: Sun, 9 Jun 2024 21:45:04 +0300 Subject: [PATCH] add new func --- app.py | 80 ++++++++++++++++++++++++++++---- models.py | 1 + static/js/createcommision.js | 83 ++++++++++++++++++++++++++++++++++ static/js/settings.js | 6 +-- templates/createCommision.html | 68 ++++++++++++++++++++++++++++ templates/settnigs.html | 4 ++ 6 files changed, 230 insertions(+), 12 deletions(-) create mode 100644 static/js/createcommision.js create mode 100644 templates/createCommision.html diff --git a/app.py b/app.py index f71183c..50a2ce5 100644 --- a/app.py +++ b/app.py @@ -1,18 +1,14 @@ from flask import Flask, render_template, redirect, url_for, request, jsonify from models import db, CommissionPersons from flask_migrate import Migrate +import json app = Flask(__name__) - app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///project.db" app.jinja_env.auto_reload = True app.config['TEMPLATES_AUTO_RELOAD'] = True db.init_app(app) migrate = Migrate(app, db) - - - - app.secret_key = '6523e58bc0eec42c31b9635d5e0dfc23b6d119b73e633bf3a5284c79bb4a1edeaskldj' @@ -20,21 +16,89 @@ app.secret_key = '6523e58bc0eec42c31b9635d5e0dfc23b6d119b73e633bf3a5284c79bb4a1e def index(): return "22222" + @app.route("/settings", methods=["GET", "POST"]) def settings(): return render_template('settnigs.html') + @app.route("/addperson", methods=["GET", "POST"]) def addperson(): if request.method == "GET": fio = request.args.get("fio") predsed = request.args.get("predsed") recent = request.args.get("recent") - print(fio) - print(predsed) - print(recent) + secretar = request.args.get("secretar") + + ispred = False + isrecenz = False + issecretar = False + + if predsed == "true": + ispred = True + + if recent == "true": + isrecenz = True + + if secretar == "true": + issecretar = True + + db.session.add(CommissionPersons(fio=fio, + ispredsedatel=ispred, + isrecenzent=isrecenz, + issecretar=issecretar)) + db.session.commit() return jsonify({'success': True}, 200, {'ContentType': 'application/json'}) +@app.route("/createcommision", methods=["GET", "POST"]) +def createcommision(): + return render_template("createCommision.html") + + +@app.route("/1", methods=["GET", "POST"]) +def one(): + if request.method == "GET": + return "111111" + + +@app.route("/gu", methods=["GET", "POST"]) +def getuchastniki(): + if request.method == "GET": + data = db.session.query(CommissionPersons).all() + data_dct = [] + for item in data: + data_dct.append( + { + 'fio': item.fio, + 'predsed': item.ispredsedatel, + 'recent': item.isrecenzent, + 'secretar': item.issecretar + } + ) + + return jsonify(data_dct) + + +@app.route("/addcommision", methods=["GET", "POST"]) +def addcommision(): + if request.method == "GET": + predsdatel = request.args.get("predsdatel") + uchastnik1 = request.args.get("uchastnik1") + uchastnik2 = request.args.get("uchastnik2") + uchastnik3 = request.args.get("uchastnik3") + uchastnik4 = request.args.get("uchastnik4") + secretar = request.args.get("secretar") + + pred = db.session.query(CommissionPersons).filter(CommissionPersons.fio == predsdatel).first() + uch1 = db.session.query(CommissionPersons).filter(CommissionPersons.fio == uchastnik1).first() + uch2 = db.session.query(CommissionPersons).filter(CommissionPersons.fio == uchastnik2).first() + uch3 = db.session.query(CommissionPersons).filter(CommissionPersons.fio == uchastnik3).first() + uch4 = db.session.query(CommissionPersons).filter(CommissionPersons.fio == uchastnik4).first() + secr = db.session.query(CommissionPersons).filter(CommissionPersons.fio == secretar).first() + + return jsonify({'success': True}, 200, {'ContentType': 'application/json'}) + + if __name__ == "__main__": app.run(debug=True, host="0.0.0.0", port=3800) diff --git a/models.py b/models.py index f12cc71..9ab3d9e 100644 --- a/models.py +++ b/models.py @@ -9,4 +9,5 @@ class CommissionPersons(db.Model): fio = db.Column(db.String(80), unique=True, nullable=False) ispredsedatel = db.Column(db.Boolean, nullable=False, default=False) isrecenzent = db.Column(db.Boolean, nullable=False, default=False) + issecretar = db.Column(db.Boolean, nullable=False, default=False) diff --git a/static/js/createcommision.js b/static/js/createcommision.js new file mode 100644 index 0000000..d61791d --- /dev/null +++ b/static/js/createcommision.js @@ -0,0 +1,83 @@ +let numbergak = document.getElementById("gaknumber") +let predsel = document.getElementById('predesdatel') +let uch1 = document.getElementById('uchgak1') +let uch2 = document.getElementById('uchgak2') +let uch3 = document.getElementById('uchgak3') +let uch4 = document.getElementById('uchgak4') +let addcom = document.getElementById("addcom") + +let secretar = document.getElementById('secretar') + +let preds = [] +let alluchs = [] +let secretars = [] + +$(document).ready(function () { + console.log("page Load!!") + + $.getJSON("/gu", function (data) { + data.forEach(function (element) { + if (element.secretar == 0) { + alluchs.push(element.fio) + } else { + secretars.push(element.fio) + } + if (element.predsed == 1) { + preds.push(element.fio) + } + + }); + + + for (i = 0; i < preds.length; i++) { + let newOption = new Option(preds[i], preds[i]) + predsel.appendChild(newOption) + } + + alluchs.forEach(function (item) { + let newOption = new Option(item, item) + uch1.appendChild(newOption); + }) + alluchs.forEach(function (item) { + let newOption = new Option(item, item) + uch2.appendChild(newOption); + }) + alluchs.forEach(function (item) { + let newOption = new Option(item, item) + uch3.appendChild(newOption); + }) + alluchs.forEach(function (item) { + let newOption = new Option(item, item) + uch4.appendChild(newOption); + }) + secretars.forEach(function (item) { + let newOption = new Option(item, item) + secretar.appendChild(newOption) + }) + }); + +}); + +addcom.onclick = function () { + console.log('PRESSEDD') + + $.ajax({ + url: "/addcommision", + type: "get", + contentType: "application/json", + dataType: "json", + data: { + 'predsdatel': predsel.value, + 'uchastnik1': uch1.value, + 'uchastnik2': uch2.value, + 'uchastnik3': uch3.value, + 'uchastnik4': uch4.value, + 'secretar': secretar.value + }, + error: function (error) { + console.log(error); + } + }) + + +} \ No newline at end of file diff --git a/static/js/settings.js b/static/js/settings.js index edf3635..3e8ebd1 100644 --- a/static/js/settings.js +++ b/static/js/settings.js @@ -6,11 +6,8 @@ btnadd.onclick = function (){ fio = document.getElementById("fio").value; predsed = document.getElementById("predsedatel").checked; recent = document.getElementById("recentzent").checked; + secretar = document.getElementById("secretar").checked; - - console.log(fio); - console.log(predsed); - console.log(recent); $.ajax( { url: "/addperson", @@ -21,6 +18,7 @@ btnadd.onclick = function (){ 'fio': fio, 'predsed': predsed, 'recent': recent, + 'secretar': secretar }, error: function(error){ console.log(error); diff --git a/templates/createCommision.html b/templates/createCommision.html new file mode 100644 index 0000000..856da98 --- /dev/null +++ b/templates/createCommision.html @@ -0,0 +1,68 @@ + + + + + Создать комиссию + + + +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + +
+ + +
+ +
+ + +
+ +
+ + +
+ + + + + + + + + + + \ No newline at end of file diff --git a/templates/settnigs.html b/templates/settnigs.html index 080e5e5..18fccfa 100644 --- a/templates/settnigs.html +++ b/templates/settnigs.html @@ -17,6 +17,10 @@ Рецензент +