complete parcours
This commit is contained in:
parent
2d4b428093
commit
202fda826f
3 changed files with 116 additions and 23 deletions
|
@ -67,7 +67,7 @@ class AddressFinder:
|
|||
con.close()
|
||||
return list(communesMap.values())
|
||||
|
||||
def getCommuneFantoirVoies(self, communeInseeCode: str) -> list[FantoirVoie]:
|
||||
def getCommuneFantoirVoies(self, communeInseeCode: str, voieSearch: str = None) -> list[FantoirVoie]:
|
||||
|
||||
# Extract data from DB
|
||||
con = sqlite3.connect(self.dbPath)
|
||||
|
@ -92,6 +92,19 @@ class AddressFinder:
|
|||
data_dict = json.loads(data.get("value"))
|
||||
# In extracted JSON data, the interesting payload is behind "value" key
|
||||
fantoir_dict = data_dict.get("value")
|
||||
if voieSearch is not None:
|
||||
regexSearch = r".*"
|
||||
for expr in voieSearch.split(' '):
|
||||
regexSearch += r"(?=" + expr + r").*"
|
||||
regexSearch += r".*"
|
||||
fantoir_voies_filtered = []
|
||||
for voie in fantoir_dict:
|
||||
for libelle in voie['libelle']:
|
||||
if re.search(regexSearch, libelle, re.IGNORECASE):
|
||||
fantoir_voies_filtered.append(voie)
|
||||
break
|
||||
fantoir_dict = fantoir_voies_filtered
|
||||
|
||||
else:
|
||||
print("Did not found any data matching Insee code " +
|
||||
str(communeInseeCode))
|
||||
|
|
|
@ -25,10 +25,10 @@
|
|||
<div id="methodPto" class="collapse show testMethods">
|
||||
|
||||
<h2 class="text-center form-title">Test d'éligibilité par PTO</h1>
|
||||
<form>
|
||||
<form method="post" action="/test/pto">
|
||||
<div class="form-group" id="ptoForm">
|
||||
<label class="form-label" for="pto-number">Numéro PTO</label>
|
||||
<input required type="text" class="form-control" id="pto-number" aria-describedby="ptoHelp" placeholder="OOOO-XXXX-XXXX" oninvalid="this.setCustomValidity('Veuillez renseigner le PTO')" oninput="setCustomValidity('')">
|
||||
<input required type="text" class="form-control" name="pto" id="pto-number" aria-describedby="ptoHelp" placeholder="OOOO-XXXX-XXXX" oninvalid="this.setCustomValidity('Veuillez renseigner le PTO')" oninput="setCustomValidity('')">
|
||||
|
||||
<small id="ptoHelp" class="form-text btn btn-link" data-toggle="collapse" data-target="#ptoInfo" aria-expanded="true" aria-controls="ptoInfo">Où trouver mon numéro de PTO ?</small>
|
||||
<div id="ptoInfo" class="collapse" aria-labelledby="ptoForm" data-parent="#ptoForm">
|
||||
|
@ -49,25 +49,27 @@
|
|||
|
||||
<div id="methodAddress" class="collapse testMethods">
|
||||
<h2 class="text-center form-title">Test d'éligibilité par adresse</h1>
|
||||
<form>
|
||||
<form method="post" action="/test/address">
|
||||
<div class="form-group" id="communeForm">
|
||||
<label class="form-label" for="communeInput">Commune</label>
|
||||
<input type="text" list="communes" class="form-control" id="communeInput" ondblclick="this.focus();this.select()" aria-describedby="communeHelp" placeholder="Nom de la commune ou code postal">
|
||||
<input type="text" list="communes" name="commune" class="form-control" id="communeInput" ondblclick="this.focus();this.select()" aria-describedby="communeHelp" placeholder="Nom de la commune ou code postal">
|
||||
<datalist id="communes">
|
||||
</datalist>
|
||||
</div>
|
||||
<div class="form-row collapse waitCommune" id="voieForm">
|
||||
<div class="form-row collapse" id="voieForm">
|
||||
<div class="col-sm-3 my-1">
|
||||
<label class="form-label" for="numeroVoieInput">Numéro de voie</label>
|
||||
<input type="text" class="form-control" id="numeroVoieInput" aria-describedby="numeroVoieHelp" placeholder="Numéro de voie">
|
||||
<input required type="text" name="numeroVoie" class="form-control" id="numeroVoieInput" aria-describedby="numeroVoieHelp" placeholder="Numéro de voie" oninvalid="this.setCustomValidity('Veuillez renseigner le numéro de voie')" oninput="setCustomValidity('')">
|
||||
</div>
|
||||
<div class="col-sm-9 my-1">
|
||||
<label class="form-label" for="voieInput">Nom de voie</label>
|
||||
<input type="text" class="form-control" id="voieInput" aria-describedby="voieHelp" placeholder="Nom de voie">
|
||||
<input type="text" name="voie" list="voies" class="form-control" id="voieInput" aria-describedby="voieHelp" placeholder="Nom de voie">
|
||||
<datalist id="voies">
|
||||
</datalist>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<button id="btnTestAdresse" type="button" class="btn btn-sable collapse waitCommune">Tester l'adresse</button>
|
||||
<button id="btnTestAdresse" type="submit" class="btn btn-sable collapse">Tester l'adresse</button>
|
||||
</form>
|
||||
<br>
|
||||
<button id="buttonReturnPto" type="button" data-toggle="collapse" data-target=".testMethods" class="btn btn-link" aria-expanded="false" aria-controls="methodPto methodAddress">Revenir au test par PTO</button>
|
||||
|
@ -79,6 +81,9 @@
|
|||
<script>
|
||||
$(document).ready(function(){
|
||||
var communes=[]
|
||||
var codeInsee=0
|
||||
var voies=[]
|
||||
var voie=""
|
||||
function fillCommunes(search='') {
|
||||
var api="addresses/communes";
|
||||
if (search != '') {
|
||||
|
@ -99,32 +104,91 @@
|
|||
$("#communes").append("<option codeInsee=" + communes[i].codeInsee + " value='" +
|
||||
communes[i].codeZip + ' ' + communes[i].nom + "'></option>");
|
||||
}
|
||||
}
|
||||
if (communes.length == 1) {
|
||||
$('.waitCommune').addClass('show');
|
||||
codeInsee=communes[0].codeInsee
|
||||
console.log("fillCommunes show voieForm")
|
||||
$('#voieForm').collapse('show');
|
||||
console.log("fillCommunes shown voieForm")
|
||||
} else {
|
||||
$('.waitCommune').removeClass('show');
|
||||
console.log("fillCommunes hide voieForm")
|
||||
console.log("voieInput to empty")
|
||||
$('#voieInput').val('');
|
||||
$('#voieForm').collapse('hide');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
var voies=[]
|
||||
function fillVoies(codeInsee,search='') {
|
||||
var api="addresses/fantoirvoies/" + codeInsee;
|
||||
if (search != '') {
|
||||
api+="?s="+search;
|
||||
}
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
dataType:"json",
|
||||
url: api,
|
||||
success: function (data, status, xhr) {
|
||||
if (JSON.stringify(data) !== JSON.stringify(voies)){
|
||||
$("#voies").empty();
|
||||
voies=data
|
||||
for (let i = 0; i < 20; i++) {
|
||||
if (! voies[i]) {
|
||||
break;
|
||||
}
|
||||
$("#voies").append("<option id=" + voies[i].id + " value='" +
|
||||
voies[i].libelle[0] + "'></option>");
|
||||
}
|
||||
if (voies.length == 1) {
|
||||
console.log("fillVoies show btnTestAdresse")
|
||||
$('#btnTestAdresse').collapse('show');
|
||||
voie=voies[0].libelle[0]
|
||||
} else {
|
||||
console.log("fillVoies hide btnTestAdresse")
|
||||
$('#btnTestAdresse').collapse('hide');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
$('#methodAddress').on('shown.bs.collapse', function () {
|
||||
fillCommunes();
|
||||
$('#methodAddress').on('show.bs.collapse', function () {
|
||||
console.log("SHOW methodAddress")
|
||||
$('#communeInput').trigger('input')
|
||||
$('#communeInput').trigger('keyup')
|
||||
});
|
||||
$('#voieForm').on('show.bs.collapse', function () {
|
||||
console.log("SHOW voieForm")
|
||||
|
||||
$('#voieInput').trigger('input')
|
||||
$('#voieInput').trigger('keyup')
|
||||
});
|
||||
|
||||
$('#communeInput').on('keyup', function () {
|
||||
console.log("communes keyup, call fillCommunes")
|
||||
fillCommunes($(this).val());
|
||||
});
|
||||
|
||||
$('#communeInput').on('input', function() {
|
||||
console.log("val ", $(this).val())
|
||||
if ($(this).val() === '') {
|
||||
$('.waitCommune').removeClass('show');
|
||||
console.log("on empty input hide voieForm")
|
||||
$('#voieForm').collapse('hide');
|
||||
}
|
||||
});
|
||||
$('#buttonReturnPto').on('click', function() {
|
||||
console.log("click")
|
||||
$('#communeInput').val('');
|
||||
$('.waitCommune').removeClass('show');
|
||||
$('#voieInput').on('keyup', function () {
|
||||
fillVoies(codeInsee,$(this).val());
|
||||
});
|
||||
$('#voieInput').on('input', function () {
|
||||
console.log("voie val ", $(this).val())
|
||||
if ($(this).val() === '') {
|
||||
console.log("on empty input hide btnTestAdresse")
|
||||
$('#btnTestAdresse').collapse('hide');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
|
18
webapp.py
18
webapp.py
|
@ -48,9 +48,25 @@ def get_communes():
|
|||
|
||||
@app.route("/addresses/fantoirvoies/<codeInsee>", methods=['GET'])
|
||||
def get_fantoir_voies(codeInsee):
|
||||
fantoirVoies=addressFinder.getCommuneFantoirVoies(codeInsee)
|
||||
to_search=request.args.get('s')
|
||||
fantoirVoies=addressFinder.getCommuneFantoirVoies(codeInsee,to_search)
|
||||
response = app.response_class(
|
||||
response=json.dumps(fantoirVoies),
|
||||
mimetype='application/json'
|
||||
)
|
||||
return response
|
||||
|
||||
@app.route("/test/address", methods=['POST'])
|
||||
def test_address():
|
||||
print(request.form)
|
||||
# pto = escape(request.form['pto'])
|
||||
# result = parse_response(query_axione_pto(cfg, pto))
|
||||
return json.dumps({'success':True}), 200, {'ContentType':'application/json'}
|
||||
|
||||
|
||||
@app.route("/test/pto", methods=['POST'])
|
||||
def test_pto():
|
||||
print(request.form)
|
||||
# pto = escape(request.form['pto'])
|
||||
# result = parse_response(query_axione_pto(cfg, pto))
|
||||
return json.dumps({'success':True}), 200, {'ContentType':'application/json'}
|
||||
|
|
Loading…
Reference in a new issue