From 2247d5f9e63cfd4a44a337661b107cb2f894c6a9 Mon Sep 17 00:00:00 2001 From: Christopher Charbonneau Wells Date: Sun, 13 Aug 2017 18:23:56 -0400 Subject: [PATCH] Add an initial New Baby form (WIP). --- babyblotter/urls.py | 4 ++++ core/forms.py | 24 ++++++++++++++++++++++++ core/templates/baby-form.html | 9 +++++++++ core/views.py | 13 +++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 core/forms.py create mode 100644 core/templates/baby-form.html create mode 100644 core/views.py diff --git a/babyblotter/urls.py b/babyblotter/urls.py index f048260a..a6a30dbf 100644 --- a/babyblotter/urls.py +++ b/babyblotter/urls.py @@ -4,7 +4,11 @@ from __future__ import unicode_literals from django.conf.urls import url, include from django.contrib import admin +from core import views + urlpatterns = [ + url(r'^baby/new/$', views.BabyFormView.as_view(), name='baby_new'), + url(r'^admin/', admin.site.urls), url(r'', include('api.urls')), ] diff --git a/core/forms.py b/core/forms.py new file mode 100644 index 00000000..c4ea0dc6 --- /dev/null +++ b/core/forms.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.forms import fields, widgets +from djng.styling.bootstrap3.forms import Bootstrap3Form + + +class BabyForm(Bootstrap3Form): + use_required_attribute = False + + first_name = fields.CharField( + label='First name', + min_length=3, + max_length=20) + + last_name = fields.RegexField( + r'^[A-Z][a-z -]?', + label='Last name', + error_messages={'invalid': 'Last names shall start in upper case'}) + + birth_date = fields.DateField( + label='Date of birth', + widget=widgets.DateInput(attrs={'validate-date': '^(\d{4})-(\d{1,2})-(\d{1,2})$'}), + help_text='Allowed date format: yyyy-mm-dd') diff --git a/core/templates/baby-form.html b/core/templates/baby-form.html new file mode 100644 index 00000000..b71ead50 --- /dev/null +++ b/core/templates/baby-form.html @@ -0,0 +1,9 @@ + + +
+ {% csrf_token %} + {{ form.as_div }} + +
diff --git a/core/views.py b/core/views.py new file mode 100644 index 00000000..30999460 --- /dev/null +++ b/core/views.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.core.urlresolvers import reverse_lazy +from django.views.generic.edit import FormView + +from core.forms import BabyForm + + +class BabyFormView(FormView): + template_name = 'baby-form.html' + form_class = BabyForm + success_url = reverse_lazy('form_data_valid')