Recovered lost local code
This commit is contained in:
@@ -1,8 +1,177 @@
|
||||
# from flask import Blueprint, render_template, request, redirect, url_for, flash, jsonify
|
||||
# from flask_login import login_required
|
||||
|
||||
# import config
|
||||
|
||||
# from model.Village import Village
|
||||
# from model.State import State
|
||||
|
||||
# # Create Blueprint
|
||||
# village_bp = Blueprint('village', __name__)
|
||||
|
||||
|
||||
# # ------------------------- Add Village -------------------------
|
||||
# @village_bp.route('/add_village', methods=['GET', 'POST'])
|
||||
# @login_required
|
||||
# def add_village():
|
||||
|
||||
# village = Village()
|
||||
|
||||
# if request.method == 'POST':
|
||||
# village.AddVillage(request=request)
|
||||
# return village.resultMessage
|
||||
|
||||
# state = State()
|
||||
# states = state.GetAllStates(request=request)
|
||||
|
||||
# villages = village.GetAllVillages(request=request)
|
||||
|
||||
# return render_template(
|
||||
# 'add_village.html',
|
||||
# states=states,
|
||||
# villages=villages
|
||||
# )
|
||||
|
||||
|
||||
# # ------------------------- Fetch Districts -------------------------
|
||||
# @village_bp.route('/get_districts/<int:state_id>')
|
||||
# @login_required
|
||||
# def get_districts(state_id):
|
||||
|
||||
# connection = config.get_db_connection()
|
||||
# cursor = connection.cursor()
|
||||
|
||||
# cursor.callproc("GetDistrictByStateID", [state_id])
|
||||
|
||||
# districts = []
|
||||
|
||||
# for rs in cursor.stored_results():
|
||||
# districts = rs.fetchall()
|
||||
|
||||
# cursor.close()
|
||||
# connection.close()
|
||||
|
||||
# district_list = []
|
||||
|
||||
# for d in districts:
|
||||
# district_list.append({
|
||||
# "id": d[0],
|
||||
# "name": d[1]
|
||||
# })
|
||||
|
||||
# return jsonify(district_list)
|
||||
|
||||
|
||||
# # ------------------------- Fetch Blocks -------------------------
|
||||
# @village_bp.route('/get_blocks/<int:district_id>')
|
||||
# @login_required
|
||||
# def get_blocks(district_id):
|
||||
|
||||
# connection = config.get_db_connection()
|
||||
# cursor = connection.cursor()
|
||||
|
||||
# cursor.callproc("GetBlocksByDistrictID", [district_id])
|
||||
|
||||
# blocks = []
|
||||
|
||||
# for rs in cursor.stored_results():
|
||||
# blocks = rs.fetchall()
|
||||
|
||||
# cursor.close()
|
||||
# connection.close()
|
||||
|
||||
# block_list = []
|
||||
|
||||
# for b in blocks:
|
||||
# block_list.append({
|
||||
# "id": b[0],
|
||||
# "name": b[1]
|
||||
# })
|
||||
|
||||
# return jsonify(block_list)
|
||||
|
||||
|
||||
# # ------------------------- Check Village -------------------------
|
||||
# @village_bp.route('/check_village', methods=['POST'])
|
||||
# @login_required
|
||||
# def check_village():
|
||||
|
||||
# village = Village()
|
||||
# return village.CheckVillage(request=request)
|
||||
|
||||
|
||||
# # ------------------------- Delete Village -------------------------
|
||||
# @village_bp.route('/delete_village/<int:village_id>')
|
||||
# @login_required
|
||||
# def delete_village(village_id):
|
||||
|
||||
# village = Village()
|
||||
|
||||
# village.DeleteVillage(request=request, village_id=village_id)
|
||||
|
||||
# if not village.isSuccess:
|
||||
# flash(village.resultMessage, "error")
|
||||
# else:
|
||||
# flash(village.resultMessage, "success")
|
||||
|
||||
# return redirect(url_for('village.add_village'))
|
||||
|
||||
|
||||
# # ------------------------- Edit Village -------------------------
|
||||
# @village_bp.route('/edit_village/<int:village_id>', methods=['GET', 'POST'])
|
||||
# @login_required
|
||||
# def edit_village(village_id):
|
||||
|
||||
# village = Village()
|
||||
|
||||
# if request.method == 'POST':
|
||||
|
||||
# village.EditVillage(request=request, village_id=village_id)
|
||||
|
||||
# if village.isSuccess:
|
||||
# flash(village.resultMessage, "success")
|
||||
# return redirect(url_for('village.add_village'))
|
||||
|
||||
# else:
|
||||
# flash(village.resultMessage, "error")
|
||||
|
||||
# village_data = village.GetVillageByID(id=village_id)
|
||||
# blocks = village.GetAllBlocks()
|
||||
|
||||
# return render_template(
|
||||
# 'edit_village.html',
|
||||
# village_data=village_data,
|
||||
# blocks=blocks
|
||||
# )
|
||||
|
||||
# else:
|
||||
|
||||
# village_data = village.GetVillageByID(request=request, id=village_id)
|
||||
|
||||
# if not village.isSuccess:
|
||||
# flash(village.resultMessage, "error")
|
||||
# return redirect(url_for('village.add_village'))
|
||||
|
||||
# blocks = village.GetAllBlocks(request=request)
|
||||
|
||||
# if village_data is None:
|
||||
# village_data = []
|
||||
|
||||
# if blocks is None:
|
||||
# blocks = []
|
||||
|
||||
# return render_template(
|
||||
# 'edit_village.html',
|
||||
# village_data=village_data,
|
||||
# blocks=blocks
|
||||
# )
|
||||
|
||||
|
||||
|
||||
from flask import Blueprint, render_template, request, redirect, url_for, flash, jsonify
|
||||
from flask_login import login_required
|
||||
|
||||
import config
|
||||
|
||||
from model.Village import Village
|
||||
from model.State import State
|
||||
|
||||
@@ -23,7 +192,6 @@ def add_village():
|
||||
|
||||
state = State()
|
||||
states = state.GetAllStates(request=request)
|
||||
|
||||
villages = village.GetAllVillages(request=request)
|
||||
|
||||
return render_template(
|
||||
@@ -42,7 +210,6 @@ def get_districts(state_id):
|
||||
cursor = connection.cursor()
|
||||
|
||||
cursor.callproc("GetDistrictByStateID", [state_id])
|
||||
|
||||
districts = []
|
||||
|
||||
for rs in cursor.stored_results():
|
||||
@@ -51,15 +218,7 @@ def get_districts(state_id):
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
district_list = []
|
||||
|
||||
for d in districts:
|
||||
district_list.append({
|
||||
"id": d[0],
|
||||
"name": d[1]
|
||||
})
|
||||
|
||||
return jsonify(district_list)
|
||||
return jsonify([{"id": d[0], "name": d[1]} for d in districts])
|
||||
|
||||
|
||||
# ------------------------- Fetch Blocks -------------------------
|
||||
@@ -71,7 +230,6 @@ def get_blocks(district_id):
|
||||
cursor = connection.cursor()
|
||||
|
||||
cursor.callproc("GetBlocksByDistrictID", [district_id])
|
||||
|
||||
blocks = []
|
||||
|
||||
for rs in cursor.stored_results():
|
||||
@@ -80,22 +238,13 @@ def get_blocks(district_id):
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
block_list = []
|
||||
|
||||
for b in blocks:
|
||||
block_list.append({
|
||||
"id": b[0],
|
||||
"name": b[1]
|
||||
})
|
||||
|
||||
return jsonify(block_list)
|
||||
return jsonify([{"id": b[0], "name": b[1]} for b in blocks])
|
||||
|
||||
|
||||
# ------------------------- Check Village -------------------------
|
||||
@village_bp.route('/check_village', methods=['POST'])
|
||||
@login_required
|
||||
def check_village():
|
||||
|
||||
village = Village()
|
||||
return village.CheckVillage(request=request)
|
||||
|
||||
@@ -106,14 +255,9 @@ def check_village():
|
||||
def delete_village(village_id):
|
||||
|
||||
village = Village()
|
||||
|
||||
village.DeleteVillage(request=request, village_id=village_id)
|
||||
|
||||
if not village.isSuccess:
|
||||
flash(village.resultMessage, "error")
|
||||
else:
|
||||
flash(village.resultMessage, "success")
|
||||
|
||||
flash(village.resultMessage, "success" if village.isSuccess else "error")
|
||||
return redirect(url_for('village.add_village'))
|
||||
|
||||
|
||||
@@ -135,8 +279,8 @@ def edit_village(village_id):
|
||||
else:
|
||||
flash(village.resultMessage, "error")
|
||||
|
||||
village_data = village.GetVillageByID(request=request, id=village_id)
|
||||
blocks = village.GetAllBlocks(request=request)
|
||||
village_data = village.GetVillageByID(id=village_id) or []
|
||||
blocks = village.GetAllBlocks() or []
|
||||
|
||||
return render_template(
|
||||
'edit_village.html',
|
||||
@@ -145,23 +289,17 @@ def edit_village(village_id):
|
||||
)
|
||||
|
||||
else:
|
||||
|
||||
village_data = village.GetVillageByID(request=request, id=village_id)
|
||||
# ✅ FIXED HERE (removed request)
|
||||
village_data = village.GetVillageByID(id=village_id)
|
||||
|
||||
if not village.isSuccess:
|
||||
flash(village.resultMessage, "error")
|
||||
return redirect(url_for('village.add_village'))
|
||||
|
||||
blocks = village.GetAllBlocks(request=request)
|
||||
|
||||
if village_data is None:
|
||||
village_data = []
|
||||
|
||||
if blocks is None:
|
||||
blocks = []
|
||||
blocks = village.GetAllBlocks() or []
|
||||
|
||||
return render_template(
|
||||
'edit_village.html',
|
||||
village_data=village_data,
|
||||
village_data=village_data or [],
|
||||
blocks=blocks
|
||||
)
|
||||
Reference in New Issue
Block a user