You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.9 KiB

from flask import render_template, url_for, flash, redirect, request, Blueprint
from minibase.app import db
import minibase.theme as theme
import minibase.blueprints.database.utils as dbUtils
import minibase.blueprints.main.utils as mainUtils
import minibase.blueprints.geography.utils as geoUtils
from minibase.blueprints.geography.models import City, State
from minibase.blueprints.geography.forms import LocationForm
from flask_wtf import FlaskForm
# Declaring a blueprint
geography = Blueprint('geography', __name__, template_folder='templates')
@geography.route('/test', methods=["GET", "POST"])
def test():
print("hello")
form = LocationForm()
form.country.choices = [(row.id, row.name) for row in geoUtils.queryCountryNamesWithDefault(-1)]
if form.country.data:
form.city.choices = [(row.id, row.name) for row in geoUtils.queryCiytNamesOfStateWithDefId(form.country.data.id)]
else:
form.city.choices = [(row.id, row.name) for row in City.query.filter(None).all()]
if form.validate_on_submit():
print(form.country.data.name)
print(form.city.data.name)
return render_template("geography/index.html",
form=form,
theme=theme)
@geography.route("/get_cities", methods=['GET', 'POST'])
def get_cities():
country_id = request.args.get("country", type=int)
cities = City.query.filter_by(country_id=country_id).all()
print(len(cities))
if len(cities) == 0:
cities = 'Non Awailable'
return render_template("geography/city_options.html", cities=cities)
@geography.route("/get_states", methods=['GET', 'POST'])
def get_states():
country_id = request.args.get("country", type=int)
cities = State.query.filter_by(country_id=country_id).all()
print(len(cities))
if len(cities) == 0:
cities = 'Non Awailable'
return render_template("geography/city_options.html", cities=cities)