add new func

This commit is contained in:
danamir
2024-06-09 17:13:08 +03:00
parent b9a71474df
commit 0bcde72bba
5 changed files with 124 additions and 0 deletions

40
app.py Normal file
View File

@@ -0,0 +1,40 @@
from flask import Flask, render_template, redirect, url_for, request, jsonify
from models import db, CommissionPersons
from flask_migrate import Migrate
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'
@app.route("/", methods=["GET", "POST"])
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)
return jsonify({'success': True}, 200, {'ContentType': 'application/json'})
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=3800)

12
models.py Normal file
View File

@@ -0,0 +1,12 @@
from flask_sqlalchemy import SQLAlchemy
import datetime
db = SQLAlchemy()
class CommissionPersons(db.Model):
id = db.Column(db.Integer, primary_key=True)
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)

36
static/js/settings.js Normal file
View File

@@ -0,0 +1,36 @@
let btnadd = document.getElementById("addbtn")
btnadd.onclick = function (){
fio = document.getElementById("fio").value;
predsed = document.getElementById("predsedatel").checked;
recent = document.getElementById("recentzent").checked;
console.log(fio);
console.log(predsed);
console.log(recent);
$.ajax(
{
url: "/addperson",
type: "get",
contentType: "application/json",
dataType: "json",
data: {
'fio': fio,
'predsed': predsed,
'recent': recent,
},
error: function(error){
console.log(error);
}
}
)
document.getElementById("fio").value = "";
document.getElementById("predsedatel").checked = false;
document.getElementById("recentzent").checked = false;
}

10
templates/index.html Normal file
View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</body>
</html>

26
templates/settnigs.html Normal file
View File

@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Настройки</title>
</head>
<body>
<h2>Добавить члена комиссии</h2>
<label>ФИО</label> <input type="text" name="myInput" size="30" required id="fio">
<label>
<input type="checkbox" value="yes" id="predsedatel">
Председатель
</label>
<label>
<input type="checkbox" value="yes" id="recentzent">
Рецензент
</label>
<button type="button" name="AddChlenKom" id="addbtn">
Добавить
</button>
</body>
<script src="{{url_for('static', filename='js/settings.js')}}"></script>
<script src="{{url_for('static', filename='js/jquery-3.7.1.js')}}"></script>
</html>