Skip to content

Commit 11cb328

Browse files
msomiericksolarissmoke
authored andcommitted
add crispy forms (#2)
* add crispy forms * update requirements in setup.py
1 parent 588a0ba commit 11cb328

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ This field is also added to the content_panels.
66
### Install
77
`pip install https://github.com/regulusweb/wagtail-contact/archive/master.zip`
88

9-
Be sure to add `honeypot` and `wagtailcontact` to INSTALLED_APPS in settings.py.
10-
The contact form uses `django-honeypot` to prevent automated form spam.
9+
Be sure to add `honeypot`, `crispy_forms`, and `wagtailcontact` to INSTALLED_APPS in settings.py.
10+
The contact form uses `django-honeypot` to prevent automated form spam and
11+
`django-crispy-forms` to spice things up.
1112

13+
Note: The crispy helper has `form_tag` set to `False` to make it easy
14+
to render the honeypot field within the form.
1215

13-
`django-honeypot` also requires a few settings to be declared in settings.py.
16+
Set the `CRISPY_TEMPLATE_PACK` in your settings. `django-honeypot` also requires a few settings to be declared in settings.py.
1417
See [django-honeypot](https://github.com/jamesturk/django-honeypot) for more information.
1518

1619

setup.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
author='Regulus Ltd',
2121
author_email='[email protected]',
2222
install_requires=[
23-
'django-honeypot==0.6.0',
24-
'bleach==2.0.0',
23+
'django-honeypot>=0.6.0',
24+
'django-crispy-forms>=1.6.1',
25+
'bleach>=2.0.0',
2526
'wagtail>=1.12'
2627
],
2728
classifiers=[

wagtailcontact/forms.py

+15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
from django.core.mail import EmailMessage
44
from django.template import loader
55

6+
from crispy_forms.bootstrap import StrictButton
7+
from crispy_forms.helper import FormHelper
8+
from crispy_forms.layout import Layout
9+
610

711
class ContactForm(forms.Form):
812

@@ -16,6 +20,17 @@ class ContactForm(forms.Form):
1620
required=True,
1721
)
1822

23+
def __init__(self, *args, **kwargs):
24+
super().__init__(*args, **kwargs)
25+
self.helper = FormHelper()
26+
self.helper.form_tag = False
27+
self.helper.layout = Layout(
28+
'name',
29+
'email',
30+
'message',
31+
StrictButton('Send', type="submit", css_class="btn btn-primary"),
32+
)
33+
1934
def get_email_context(self):
2035
ctx = self.cleaned_data
2136
ctx['subject_prefix'] = settings.EMAIL_SUBJECT_PREFIX

0 commit comments

Comments
 (0)