From dd11419305f99d0de662adea620cc5d4b9edad85 Mon Sep 17 00:00:00 2001 From: Joachim Lusiardi Date: Tue, 1 Nov 2016 11:18:40 +0100 Subject: [PATCH] add the crud forms for services --- app/forms.py | 66 +++++++++++++++++++++++++++- app/templates/createServiceForm.html | 30 +++++++++++++ app/templates/deleteServiceForm.html | 42 ++++++++++++++++++ app/templates/editServiceForm.html | 29 ++++++++++++ 4 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 app/templates/createServiceForm.html create mode 100644 app/templates/deleteServiceForm.html create mode 100644 app/templates/editServiceForm.html diff --git a/app/forms.py b/app/forms.py index 5a51f8c..96af2f7 100644 --- a/app/forms.py +++ b/app/forms.py @@ -1,5 +1,6 @@ from flask_wtf import Form -from wtforms import DateField, IntegerField, DecimalField, StringField, SelectField, SubmitField, SelectMultipleField, BooleanField +from wtforms import DateField, IntegerField, DecimalField, StringField, SelectField, SubmitField, SelectMultipleField, \ + BooleanField, TextAreaField from wtforms.validators import ValidationError, Length from datetime import date @@ -167,3 +168,66 @@ class EditConsumableForm(Form): class DeletConsumableForm(Form): submit = SubmitField(label='Do it!') + + +class CreateServiceForm(Form): + date = DateField('Date of Service', validators=[date_check]) + odometer = IntegerField('Odometer (km)', validators=[odometer_check]) + costs = DecimalField('Costs (€, overall)', places=2, validators=[costs_check]) + description = TextAreaField('Description', validators=[Length(1, 4096)]) + submit = SubmitField(label='Do it!') + last_pitstop = None + + def set_pitstop(self, last_pitstop): + self.last_pitstop = last_pitstop + + def preinit_with_data(self): + if self.date.data: + self.date.default = self.date.data + else: + self.date.default = date.today() + + if self.odometer.data: + self.odometer.default = self.odometer.data + else: + self.odometer.default = self.last_pitstop.odometer + + if self.costs.data: + self.costs.default = self.costs.data + else: + self.costs.default = 0 + + +class DeleteServiceForm(Form): + submit = SubmitField(label='Really delete this service!') + + +class EditServiceForm(Form): + date = DateField('Date of Service', validators=[date_check]) + odometer = IntegerField('Odometer (km)', validators=[odometer_check]) + costs = DecimalField('Costs (€, overall)', places=2, validators=[costs_check]) + description = TextAreaField('Description', validators=[Length(1, 4096)]) + submit = SubmitField(label='Do it!') + last_pitstop = None + same_odometer_allowed = True + + def set_pitstop(self, last_pitstop): + self.last_pitstop = last_pitstop + + def preinit_with_data(self): + if self.date.data: + self.date.default = self.date.data + else: + self.date.default = date.today() + + if self.odometer.data: + self.odometer.default = self.odometer.data + else: + self.odometer.default = self.last_pitstop.odometer + + if self.costs.data: + self.costs.default = self.costs.data + else: + self.costs.default = 0 + + diff --git a/app/templates/createServiceForm.html b/app/templates/createServiceForm.html new file mode 100644 index 0000000..68758f4 --- /dev/null +++ b/app/templates/createServiceForm.html @@ -0,0 +1,30 @@ +{% extends "layout.html" %} + +{% block body %} +
+
+
+
+

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

+
+ {{ form.hidden_tag() }} + {{ render_field_with_errors(form.date) }} + + {{messages['date']}} + + {{ render_field_with_errors(form.odometer) }} + + {{messages['odometer']}} + + {{ render_field_with_errors(form.costs) }} + + {{messages['costs']}} + + {{ render_field_with_errors(form.description) }} + {{ render_field_with_errors(form.submit) }} +
+
+
+
+
+{% endblock %} diff --git a/app/templates/deleteServiceForm.html b/app/templates/deleteServiceForm.html new file mode 100644 index 0000000..06f2bec --- /dev/null +++ b/app/templates/deleteServiceForm.html @@ -0,0 +1,42 @@ +{% extends 'layout.html' %} + +{% block body %} +
+
+
+
+

Delete service?

+ + + + + + + + + + + + + + + + + +
Date of Pitstop{{ service.date }}
Odometer{{ service.odometer }} km
Description{{ service.description }}
Costs (overall) + {% if service.costs %} + {{service.costs}} + {% else %} + -- + {% endif %} + € +
+
+ {{ form.hidden_tag() }} + {{ render_field_with_errors(form.submit) }} +
+
+
+
+
+{% endblock %} diff --git a/app/templates/editServiceForm.html b/app/templates/editServiceForm.html new file mode 100644 index 0000000..c1bfe62 --- /dev/null +++ b/app/templates/editServiceForm.html @@ -0,0 +1,29 @@ +{% extends "layout.html" %} + +{% block body %} +
+
+
+
+

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

+
+ {{ form.hidden_tag() }} + {{ render_field_with_errors(form.date) }} + + {{messages['date']}} + + {{ render_field_with_errors(form.odometer) }} + + {{messages['odometer']}} + + {{ render_field_with_errors(form.description) }} + {{ render_field_with_errors(form.costs) }} + + {{messages['costs']}} + + {{ render_field_with_errors(form.submit) }} +
+
+
+
+{% endblock %}