Add an initial New Baby form (WIP).

This commit is contained in:
Christopher Charbonneau Wells 2017-08-13 18:23:56 -04:00
parent 6f0b8500fb
commit 2247d5f9e6
4 changed files with 50 additions and 0 deletions

View File

@ -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')),
]

24
core/forms.py Normal file
View File

@ -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')

View File

@ -0,0 +1,9 @@
<script type="text/javascript">
angular.module('djangular-demo', ['djng.forms']);
</script>
<form method="post" action="babyblotter" validate>
{% csrf_token %}
{{ form.as_div }}
<button type="submit" class="btn btn-primary">Subscribe</button>
</form>

13
core/views.py Normal file
View File

@ -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')