Commit 8d1a2bae authored by David Haynes's avatar David Haynes 🙆

Playing with crispy-forms

- Only pushing so I can git diff this stuff out after I figure things out
- lovely
parent d10fc148
......@@ -2,7 +2,9 @@ from django import forms
from go.models import URL, RegisteredUser
from django.core.exceptions import ValidationError
from captcha.fields import CaptchaField
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Fieldset, ButtonHolder, Submit
from crispy_forms.bootstrap import StrictButton
class URLForm(forms.ModelForm):
......@@ -96,3 +98,53 @@ class SignupForm(forms.ModelForm):
class Meta:
model = RegisteredUser
fields = '__all__'
class ExampleForm(forms.Form):
like_website = forms.TypedChoiceField(
label = "Do you like this website?",
choices = ((1, "Yes"), (0, "No")),
coerce = lambda x: bool(int(x)),
widget = forms.RadioSelect,
initial = '1',
required = True,
)
favorite_food = forms.CharField(
label = "What is your favorite food?",
max_length = 80,
required = True,
)
favorite_color = forms.CharField(
label = "What is your favorite color?",
max_length = 80,
required = True,
)
favorite_number = forms.IntegerField(
label = "Favorite number",
required = False,
)
notes = forms.CharField(
label = "Additional notes or feedback",
required = False,
)
def __init__(self, *args, **kwargs):
super(ExampleForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_id = 'id-exampleForm'
self.helper.form_method = 'post'
self.helper.form_action = 'submit_survey'
self.helper.form_class = 'form-horizontal'
self.helper.label_class = 'col-md-4'
self.helper.field_class = 'col-md-4'
self.helper.layout = Layout(
'like_website',
'favorite_food',
'favorite_color',
'favorite_number',
'notes',
StrictButton('Sign in', css_class='btn-default'),
)
{% extends 'layouts/base.html' %}
{% load crispy_forms_tags %}
{% block title %}
Go - A Product of Vapor
{% endblock %}
{% block content %}
<style>
.asteriskField {
display: none;
}
</style>
<div class="page-header" id="banner">
<div class="row">
<div class="col-md-12">
<h1><strong>Super secret testing page</strong></h1>
</div>
</div>
</div>
{% crispy form form.helper %}
{% endblock %}
from go.models import URL, RegisteredUser
from go.forms import URLForm, SignupForm
from go.forms import URLForm, SignupForm, ExampleForm
from datetime import timedelta
from django.conf import settings
from django.http import HttpResponseServerError # Http404
......@@ -69,6 +69,16 @@ def error_500(request):
return render(request, '500.html', {
},
)
def test(request):
"""
Testing page, pls ignore.
"""
url_form = ExampleForm()
if request.method == 'POST':
url_form = URLForm(request.POST) # bind dat form
return render(request, 'test.html', {
'form': url_form,
},)
##############################################################################
"""
......
......@@ -34,6 +34,8 @@ urlpatterns = patterns('go.views',
# /useradmin - user approval interface
url(r'^useradmin/?$', 'useradmin', name='useradmin'),
url(r'^test/?$', 'test', name='test')
)
urlpatterns += patterns('django.contrib.auth.views',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment