aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Crute <mcrute@gmail.com>2012-12-04 15:50:42 -0500
committerMike Crute <mcrute@gmail.com>2012-12-11 15:27:46 -0500
commitfc5ad68e62bd2b82450cdbdd3c83f8c1e94feed2 (patch)
treeb521cb9d395bed84d88bce003327af3020010810
parent39850fe5e8a23b402610167e33540ee615aed3ab (diff)
downloaddjango-precompiler-fc5ad68e62bd2b82450cdbdd3c83f8c1e94feed2.tar.bz2
django-precompiler-fc5ad68e62bd2b82450cdbdd3c83f8c1e94feed2.tar.xz
django-precompiler-fc5ad68e62bd2b82450cdbdd3c83f8c1e94feed2.zip
Add contact form
-rw-r--r--codemash/settings.py8
-rw-r--r--codemash/urls.py3
-rw-r--r--contact/__init__.py0
-rw-r--r--contact/forms.py7
-rw-r--r--contact/models.py3
-rw-r--r--contact/tests.py16
-rw-r--r--contact/urls.py7
-rw-r--r--contact/views.py26
-rw-r--r--templates/contact/form.html17
-rw-r--r--templates/contact/thanks.html14
-rw-r--r--templates/index.html3
11 files changed, 102 insertions, 2 deletions
diff --git a/codemash/settings.py b/codemash/settings.py
index 3bf0f6a..23b1b93 100644
--- a/codemash/settings.py
+++ b/codemash/settings.py
@@ -114,6 +114,12 @@ TEMPLATE_DIRS = (
114 os.path.join(PROJECT_ROOT, "templates"), 114 os.path.join(PROJECT_ROOT, "templates"),
115) 115)
116 116
117# The email backend to use. For possible shortcuts see django.core.mail.
118# The default is to use the SMTP backend.
119# Third-party backends can be specified by providing a Python path
120# to a module that defines an EmailBackend class.
121EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
122
117INSTALLED_APPS = ( 123INSTALLED_APPS = (
118 'django.contrib.auth', 124 'django.contrib.auth',
119 'django.contrib.contenttypes', 125 'django.contrib.contenttypes',
@@ -125,6 +131,8 @@ INSTALLED_APPS = (
125 # 'django.contrib.admin', 131 # 'django.contrib.admin',
126 # Uncomment the next line to enable admin documentation: 132 # Uncomment the next line to enable admin documentation:
127 # 'django.contrib.admindocs', 133 # 'django.contrib.admindocs',
134
135 'contact',
128) 136)
129 137
130# A sample logging configuration. The only tangible logging 138# A sample logging configuration. The only tangible logging
diff --git a/codemash/urls.py b/codemash/urls.py
index 2fae4f3..0431c65 100644
--- a/codemash/urls.py
+++ b/codemash/urls.py
@@ -5,9 +5,8 @@ from django.conf.urls import patterns, include, url
5# admin.autodiscover() 5# admin.autodiscover()
6 6
7urlpatterns = patterns('', 7urlpatterns = patterns('',
8 # Examples: 8 (r'^contact/', include('contact.urls', namespace='contact')),
9 url(r'^$', 'pages.views.home', name='home'), 9 url(r'^$', 'pages.views.home', name='home'),
10 # url(r'^codemash/', include('codemash.foo.urls')),
11 10
12 # Uncomment the admin/doc line below to enable admin documentation: 11 # Uncomment the admin/doc line below to enable admin documentation:
13 # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), 12 # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
diff --git a/contact/__init__.py b/contact/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/contact/__init__.py
diff --git a/contact/forms.py b/contact/forms.py
new file mode 100644
index 0000000..5c77b29
--- /dev/null
+++ b/contact/forms.py
@@ -0,0 +1,7 @@
1from django import forms
2
3
4class ContactForm(forms.Form):
5 subject = forms.CharField(max_length=100)
6 message = forms.CharField()
7 sender = forms.EmailField()
diff --git a/contact/models.py b/contact/models.py
new file mode 100644
index 0000000..71a8362
--- /dev/null
+++ b/contact/models.py
@@ -0,0 +1,3 @@
1from django.db import models
2
3# Create your models here.
diff --git a/contact/tests.py b/contact/tests.py
new file mode 100644
index 0000000..501deb7
--- /dev/null
+++ b/contact/tests.py
@@ -0,0 +1,16 @@
1"""
2This file demonstrates writing tests using the unittest module. These will pass
3when you run "manage.py test".
4
5Replace this with more appropriate tests for your application.
6"""
7
8from django.test import TestCase
9
10
11class SimpleTest(TestCase):
12 def test_basic_addition(self):
13 """
14 Tests that 1 + 1 always equals 2.
15 """
16 self.assertEqual(1 + 1, 2)
diff --git a/contact/urls.py b/contact/urls.py
new file mode 100644
index 0000000..0a28711
--- /dev/null
+++ b/contact/urls.py
@@ -0,0 +1,7 @@
1from django.conf.urls import patterns, include, url
2
3
4urlpatterns = patterns('contact.views',
5 url(r'^thanks/$', 'contact_processor', name='thanks'),
6 url(r'^$', 'contact_form', name='form'),
7)
diff --git a/contact/views.py b/contact/views.py
new file mode 100644
index 0000000..e3a6511
--- /dev/null
+++ b/contact/views.py
@@ -0,0 +1,26 @@
1from django.shortcuts import render, redirect
2from django.core.mail import send_mail
3
4from contact.forms import ContactForm
5
6
7def contact_form(request):
8 return render(request, 'contact/form.html', {
9 'form': ContactForm(),
10 })
11
12
13def contact_processor(request):
14 if request.method != "POST":
15 return redirect("contact:form")
16
17 form = ContactForm(request.POST)
18 if not form.is_valid():
19 return redirect("contact:form")
20
21 send_mail(form.cleaned_data['subject'], form.cleaned_data['message'],
22 form.cleaned_data['sender'], ['codemash@example.com'])
23
24 return render(request, 'contact/thanks.html', {
25 'form': form,
26 })
diff --git a/templates/contact/form.html b/templates/contact/form.html
new file mode 100644
index 0000000..7ada5e0
--- /dev/null
+++ b/templates/contact/form.html
@@ -0,0 +1,17 @@
1<!DOCTYPE html>
2<html>
3 <head>
4 <meta charset="utf-8">
5 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
6 <title>Contact Us</title>
7 <meta name="viewport" content="width=device-width">
8 </head>
9 <body>
10 <h1>Contact Us</h1>
11 <form action="{% url 'contact:thanks' %}" method="post">
12 {% csrf_token %}
13 {{ form.as_p }}
14 <button type="submit">Contact Us</button>
15 </form>
16 </body>
17</html>
diff --git a/templates/contact/thanks.html b/templates/contact/thanks.html
new file mode 100644
index 0000000..67e8336
--- /dev/null
+++ b/templates/contact/thanks.html
@@ -0,0 +1,14 @@
1<!DOCTYPE html>
2<html>
3 <head>
4 <meta charset="utf-8">
5 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
6 <title>Thank You</title>
7 <meta name="viewport" content="width=device-width">
8 </head>
9 <body>
10 <h1>Thanks for contacting us</h1>
11 <p>We have sent the following message to the organizers. Thanks.</p>
12 <p>{{ form.message.value }}</p>
13 </body>
14</html>
diff --git a/templates/index.html b/templates/index.html
index a522fbd..0ea840f 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -8,6 +8,9 @@
8 </head> 8 </head>
9 <body> 9 <body>
10 <h1>Hello Codemash</h1> 10 <h1>Hello Codemash</h1>
11 <ul>
12 <li><a href="{% url 'contact:form' %}">Contact Us</a></li>
13 </ul>
11 <p>You've just created your first Django page. Pretty cool, eh?</p> 14 <p>You've just created your first Django page. Pretty cool, eh?</p>
12 </body> 15 </body>
13</html> 16</html>