year check valid or not All form commit
This commit is contained in:
18
main.py
18
main.py
@@ -6,7 +6,6 @@ import io
|
||||
import mysql.connector
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
from config import db_config
|
||||
from AppCode.Config import DBConfig
|
||||
from AppCode.FileHandler import FileHandler
|
||||
from AppCode.DocumentHandler import DocumentHandler
|
||||
@@ -133,6 +132,23 @@ def update_itr(id):
|
||||
return render_template('update_itr.html', record=record)
|
||||
|
||||
|
||||
# new new -- check year in table existe or not by using ajax calling.
|
||||
@app.route('/check_year', methods=['POST'])
|
||||
def check_year():
|
||||
table_name = request.json.get("table")
|
||||
year = request.json.get("year")
|
||||
|
||||
conn = DBConfig.get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
|
||||
query = f"SELECT COUNT(*) FROM {table_name} WHERE year = %s"
|
||||
cursor.execute(query, (year,))
|
||||
result = cursor.fetchone()[0]
|
||||
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
return {"exists": result > 0}
|
||||
|
||||
|
||||
## ===============================================
|
||||
|
||||
Reference in New Issue
Block a user