diff --git a/app/rollerverbrauch/__init__.py b/app/rollerverbrauch/__init__.py index 8a959cd..e2eea31 100644 --- a/app/rollerverbrauch/__init__.py +++ b/app/rollerverbrauch/__init__.py @@ -38,6 +38,9 @@ from rollerverbrauch.entities import \ Pitstop, \ Vehicle +# required to activate the filters +import rollerverbrauch.filters + user_datastore = SQLAlchemyUserDatastore(db, User, Role) security = Security(app, user_datastore) @@ -82,7 +85,7 @@ def edit_vehicle(vid): form = EditVehicleForm() if form.validate_on_submit(): - vehicle.name = form.name.data; + vehicle.name = form.name.data db.session.commit() return redirect(url_for('get_account_page')) diff --git a/app/rollerverbrauch/filters.py b/app/rollerverbrauch/filters.py new file mode 100644 index 0000000..00a0e59 --- /dev/null +++ b/app/rollerverbrauch/filters.py @@ -0,0 +1,9 @@ +from rollerverbrauch import app + + +@app.template_filter('none_filter') +def none_filter(value): + if value is None: + return '' + else: + return value diff --git a/app/rollerverbrauch/forms.py b/app/rollerverbrauch/forms.py index d8a708f..2f2b87f 100644 --- a/app/rollerverbrauch/forms.py +++ b/app/rollerverbrauch/forms.py @@ -1,5 +1,5 @@ from flask_wtf import Form -from wtforms import DateField, IntegerField, DecimalField, StringField, SelectField +from wtforms import DateField, IntegerField, DecimalField, StringField, SelectField, SubmitField from wtforms.validators import ValidationError, Length @@ -20,12 +20,14 @@ def litres_check(form, field): class SelectVehicleForm(Form): vehicle = SelectField('Vehicle', coerce=int) + submit = SubmitField(label='Do it!') class CreatePitstopForm(Form): date = DateField('Date of Pitstop', validators=[date_check]) odometer = IntegerField('Odometer (km)', validators=[odometer_check]) - litres = DecimalField('Litres (l)', places=1, validators=[litres_check]) + litres = DecimalField('Litres (l)', places=2, validators=[litres_check]) + submit = SubmitField(label='Do it!') pitstop = None def set_pitstop(self, pitstop): @@ -34,7 +36,8 @@ class CreatePitstopForm(Form): class EditVehicleForm(Form): name = StringField('Name', validators=[Length(1, 255)]) + submit = SubmitField(label='Do it!') class DeleteVehicleForm(Form): - pass + submit = SubmitField(label='Do it!') diff --git a/app/rollerverbrauch/templates/createVehicleForm.html b/app/rollerverbrauch/templates/createVehicleForm.html index d09daa8..4ea3b84 100644 --- a/app/rollerverbrauch/templates/createVehicleForm.html +++ b/app/rollerverbrauch/templates/createVehicleForm.html @@ -5,7 +5,7 @@
{{ form.hidden_tag() }} {{ render_field_with_errors(form.name) }} - + {{ render_field_with_errors(form.submit) }}
diff --git a/app/rollerverbrauch/templates/deleteVehicleForm.html b/app/rollerverbrauch/templates/deleteVehicleForm.html index 73678cf..5e957c3 100644 --- a/app/rollerverbrauch/templates/deleteVehicleForm.html +++ b/app/rollerverbrauch/templates/deleteVehicleForm.html @@ -4,7 +4,7 @@

Delete vehicle '{{vehicle.name}}'

{{ form.hidden_tag() }} - + {{ render_field_with_errors(form.submit) }}
diff --git a/app/rollerverbrauch/templates/editVehicleForm.html b/app/rollerverbrauch/templates/editVehicleForm.html index 3d7958a..627a24f 100644 --- a/app/rollerverbrauch/templates/editVehicleForm.html +++ b/app/rollerverbrauch/templates/editVehicleForm.html @@ -3,9 +3,9 @@ {% block body %}

Edit vehicle

- {{ form.hidden_tag() }} - {{ render_field_with_errors(form.name) }} - + {{ form.hidden_tag() }} + {{ render_field_with_errors(form.name) }} + {{ render_field_with_errors(form.submit) }}
diff --git a/app/rollerverbrauch/templates/layout.html b/app/rollerverbrauch/templates/layout.html index 4f6a810..e44af45 100644 --- a/app/rollerverbrauch/templates/layout.html +++ b/app/rollerverbrauch/templates/layout.html @@ -15,19 +15,46 @@ {% macro render_field_with_errors(field) %}
- -
- {{ field(**kwargs)|safe }} - {% if field.errors %} -

- {% for error in field.errors %} - {{ error }} - {% endfor %} -

- {% endif %} -
+ {% if field.type == 'SubmitField' %} +
+ +
+ {% else %} + +
+ {% if field.type == 'SelectField' %} + + {% elif field.type == 'BooleanField' %} + + {% elif field.type == 'StringField' %} + + {% elif field.type == 'PasswordField' %} + + {% elif field.type == 'DateField' %} + + {% elif field.type == 'IntegerField' %} + + {% elif field.type == 'DecimalField' %} + + {% else %} + {{ field(**kwargs)|safe }} + {% endif %} + {% if field.errors %} +

+ {% for error in field.errors %} + {{ error }} + {% endfor %} +

+ {% endif %} +
+ {% endif %} +
{% endmacro %} diff --git a/app/rollerverbrauch/templates/newPitStopForm.html b/app/rollerverbrauch/templates/newPitStopForm.html index e82133e..849432e 100644 --- a/app/rollerverbrauch/templates/newPitStopForm.html +++ b/app/rollerverbrauch/templates/newPitStopForm.html @@ -3,11 +3,11 @@ {% block body %}

New Pitstop for '{{ vehicle.name }}'

- {{ form.hidden_tag() }} - {{ render_field_with_errors(form.date) }} + {{ form.hidden_tag() }} + {{ render_field_with_errors(form.date) }} {{ render_field_with_errors(form.odometer) }} {{ render_field_with_errors(form.litres) }} - + {{ render_field_with_errors(form.submit) }}
diff --git a/app/rollerverbrauch/templates/security/change_password.html b/app/rollerverbrauch/templates/security/change_password.html index 27f5d62..4cc83e1 100644 --- a/app/rollerverbrauch/templates/security/change_password.html +++ b/app/rollerverbrauch/templates/security/change_password.html @@ -8,6 +8,6 @@ {{ render_field_with_errors(change_password_form.password) }} {{ render_field_with_errors(change_password_form.new_password) }} {{ render_field_with_errors(change_password_form.new_password_confirm) }} - {{ render_field(change_password_form.submit) }} + {{ render_field_with_errors(change_password_form.submit) }} {% endblock %} diff --git a/app/rollerverbrauch/templates/security/forgot_password.html b/app/rollerverbrauch/templates/security/forgot_password.html index 556f254..729b28f 100644 --- a/app/rollerverbrauch/templates/security/forgot_password.html +++ b/app/rollerverbrauch/templates/security/forgot_password.html @@ -6,6 +6,6 @@
{{ forgot_password_form.hidden_tag() }} {{ render_field_with_errors(forgot_password_form.email) }} - {{ render_field(forgot_password_form.submit) }} + {{ render_field_with_errors(forgot_password_form.submit) }}
{% endblock %} diff --git a/app/rollerverbrauch/templates/security/login_user.html b/app/rollerverbrauch/templates/security/login_user.html index 9bc86c2..081f13f 100644 --- a/app/rollerverbrauch/templates/security/login_user.html +++ b/app/rollerverbrauch/templates/security/login_user.html @@ -9,7 +9,7 @@ {{ render_field_with_errors(login_user_form.password) }} {{ render_field_with_errors(login_user_form.remember) }} {{ render_field(login_user_form.next) }} - {{ render_field(login_user_form.submit) }} + {{ render_field_with_errors(login_user_form.submit) }} {% if security.recoverable %} Forgot password {% endif %} diff --git a/app/rollerverbrauch/templates/security/register_user.html b/app/rollerverbrauch/templates/security/register_user.html index 9cad77d..b269de4 100644 --- a/app/rollerverbrauch/templates/security/register_user.html +++ b/app/rollerverbrauch/templates/security/register_user.html @@ -10,6 +10,6 @@ {% if register_user_form.password_confirm %} {{ render_field_with_errors(register_user_form.password_confirm) }} {% endif %} - {{ render_field(register_user_form.submit) }} + {{ render_field_with_errors(register_user_form.submit) }} {% endblock %} diff --git a/app/rollerverbrauch/templates/selectVehice.html b/app/rollerverbrauch/templates/selectVehice.html index f3677bf..f46075d 100644 --- a/app/rollerverbrauch/templates/selectVehice.html +++ b/app/rollerverbrauch/templates/selectVehice.html @@ -1,10 +1,11 @@ {% extends "layout.html" %} {% block body %} +

Select Vehicle

{{ form.hidden_tag() }} {{ render_field_with_errors(form.vehicle) }} - + {{ render_field_with_errors(form.submit) }}
{% endblock %}