This commit is contained in:
Abel Fokkinga 2022-01-04 09:43:46 +01:00
commit 1ce1f783f7
Signed by: abel
GPG Key ID: B84FADF9AF5B8D90
2 changed files with 25 additions and 14 deletions

19
main.py
View File

@ -1,9 +1,12 @@
from flask import Flask, render_template, flash, request
import requests
from requests import HTTPError
from wtforms import Form, StringField, validators
from wtforms import Form, StringField, validators, SubmitField
import json
from wtforms.validators import InputRequired
from wtforms.validators import Optional
app = Flask(__name__)
app.config['SECRET_KEY'] = '255771f2872f27567d441f2b62425'
@ -65,9 +68,10 @@ def flash_address(results):
return
class ReusableForm(Form):
postalcode = StringField('Postcode:', validators=[validators.InputRequired(), validators.Length(min=6, max=6)])
houseno = StringField('Huis nummer:', validators=[validators.InputRequired()])
houseno_ext = StringField('Toevoeging:', validators=[])
postalcode = StringField('Postcode', [InputRequired(), validators.Length(min=6, max=6, message='Formaat 1111AA')])
houseno = StringField('Huisnummer', [InputRequired(),validators.Length(max=5)])
houseno_ext = StringField('Toevoeging', [Optional(), validators.Length(max=10)])
submit = SubmitField('Zoek')
@app.route('/', methods=['GET', 'POST'])
def home():
@ -81,9 +85,16 @@ class ReusableForm(Form):
houseno = request.form['houseno']
houseno_ext = request.form['houseno_ext']
results = search_mp('ELK', postalcode, houseno, houseno_ext)
if len(results['meteringPoints']) == 0:
flash('Geen ELK aansluiting gevonden bij dit adres', 'info')
else:
flash_address(results)
flash_results(results)
results = search_mp('GAS', postalcode, houseno, houseno_ext)
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)

View File

@ -6,22 +6,22 @@
{{ form.csrf }}
<div class="form-group">
<div class="entry-group">
<div class="entry-label"><label for="name">Postcode:</label></div>
<div class="entry-text"><input type="text" id="postcode" name="postalcode" placeholder="Wat is je postcode?"></div>
<div class="entry-label">{{ form.postalcode.label }}</div>
<div class="entry-text">{{ form.postalcode(class="form-control") }}</div>
</div>
<div class="entry-group">
<div class="entry-label"><label for="houseno">Huisnummer:</label></div>
<div class="entry-text"><input type="text" id="houseno" name="houseno" placeholder="Wat is je huisnummer?"></div>
<div class="entry-label">{{ form.houseno.label }}</div>
<div class="entry-text">{{ form.houseno(class="form-control") }}</div>
</div>
<div class="entry-group">
<div class="entry-label"><label for="houseno_ext">Toevoeging:</label></div>
<div class="entry-text"><input type="text" id="houseno_ext" name="houseno_ext" placeholder="Toevoeging?"></div>
<div class="entry-label">{{ form.houseno_ext.label }}</div>
<div class="entry-text">{{ form.houseno_ext(class="form-control") }}</div>
</div>
<div class="input-submit">
<input type="Submit" class="input-submit" value="Zoek">
{{ form.submit(class="input-submit")}}
</div>
</form>