Input validation checks
This commit is contained in:
parent
0e65ea8d3a
commit
f29ab0958f
25
main.py
25
main.py
@ -1,9 +1,12 @@
|
|||||||
from flask import Flask, render_template, flash, request
|
from flask import Flask, render_template, flash, request
|
||||||
import requests
|
import requests
|
||||||
from requests import HTTPError
|
from requests import HTTPError
|
||||||
from wtforms import Form, StringField, validators
|
from wtforms import Form, StringField, validators, SubmitField
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
from wtforms.validators import InputRequired
|
||||||
|
from wtforms.validators import Optional
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config['SECRET_KEY'] = '255771f2872f27567d441f2b62425'
|
app.config['SECRET_KEY'] = '255771f2872f27567d441f2b62425'
|
||||||
|
|
||||||
@ -65,9 +68,10 @@ def flash_address(results):
|
|||||||
return
|
return
|
||||||
|
|
||||||
class ReusableForm(Form):
|
class ReusableForm(Form):
|
||||||
postalcode = StringField('Postcode:', validators=[validators.InputRequired(), validators.Length(min=6, max=6)])
|
postalcode = StringField('Postcode', [InputRequired(), validators.Length(min=6, max=6, message='Formaat 1111AA')])
|
||||||
houseno = StringField('Huis nummer:', validators=[validators.InputRequired()])
|
houseno = StringField('Huisnummer', [InputRequired(),validators.Length(max=5)])
|
||||||
houseno_ext = StringField('Toevoeging:', validators=[])
|
houseno_ext = StringField('Toevoeging', [Optional(), validators.Length(max=10)])
|
||||||
|
submit = SubmitField('Zoek')
|
||||||
|
|
||||||
@app.route('/', methods=['GET', 'POST'])
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
def home():
|
def home():
|
||||||
@ -81,10 +85,17 @@ class ReusableForm(Form):
|
|||||||
houseno = request.form['houseno']
|
houseno = request.form['houseno']
|
||||||
houseno_ext = request.form['houseno_ext']
|
houseno_ext = request.form['houseno_ext']
|
||||||
results = search_mp('ELK', postalcode, houseno, houseno_ext)
|
results = search_mp('ELK', postalcode, houseno, houseno_ext)
|
||||||
flash_address(results)
|
if len(results['meteringPoints']) == 0:
|
||||||
flash_results(results)
|
flash('Geen ELK aansluiting gevonden bij dit adres', 'info')
|
||||||
|
else:
|
||||||
|
flash_address(results)
|
||||||
|
flash_results(results)
|
||||||
|
|
||||||
results = search_mp('GAS', postalcode, houseno, houseno_ext)
|
results = search_mp('GAS', postalcode, houseno, houseno_ext)
|
||||||
flash_results(results)
|
if len(results['meteringPoints']) == 0:
|
||||||
|
flash('Geen GAS aansluiting gevonden bij dit adres', 'info')
|
||||||
|
else:
|
||||||
|
flash_results(results)
|
||||||
|
|
||||||
return render_template('index.html', form=form)
|
return render_template('index.html', form=form)
|
||||||
|
|
||||||
|
|||||||
@ -6,22 +6,22 @@
|
|||||||
{{ form.csrf }}
|
{{ form.csrf }}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="entry-group">
|
<div class="entry-group">
|
||||||
<div class="entry-label"><label for="name">Postcode:</label></div>
|
<div class="entry-label">{{ form.postalcode.label }}</div>
|
||||||
<div class="entry-text"><input type="text" id="postcode" name="postalcode" placeholder="Wat is je postcode?"></div>
|
<div class="entry-text">{{ form.postalcode(class="form-control") }}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="entry-group">
|
<div class="entry-group">
|
||||||
<div class="entry-label"><label for="houseno">Huisnummer:</label></div>
|
<div class="entry-label">{{ form.houseno.label }}</div>
|
||||||
<div class="entry-text"><input type="text" id="houseno" name="houseno" placeholder="Wat is je huisnummer?"></div>
|
<div class="entry-text">{{ form.houseno(class="form-control") }}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="entry-group">
|
<div class="entry-group">
|
||||||
<div class="entry-label"><label for="houseno_ext">Toevoeging:</label></div>
|
<div class="entry-label">{{ form.houseno_ext.label }}</div>
|
||||||
<div class="entry-text"><input type="text" id="houseno_ext" name="houseno_ext" placeholder="Toevoeging?"></div>
|
<div class="entry-text">{{ form.houseno_ext(class="form-control") }}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="input-submit">
|
<div class="input-submit">
|
||||||
<input type="Submit" class="input-submit" value="Zoek">
|
{{ form.submit(class="input-submit")}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user