aboutsummaryrefslogtreecommitdiff
path: root/contact
diff options
context:
space:
mode:
Diffstat (limited to 'contact')
-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
6 files changed, 59 insertions, 0 deletions
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 })