Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
William Fagan
committed
Jun 23, 2011
1 parent
1bf2875
commit 5e44c72
Showing
4 changed files
with
23 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,43 @@ | ||
from django import forms | ||
from django.core.mail.backends.dummy import EmailBackend as DummyEmailBackend | ||
from django.core.mail.backends.smtp import EmailBackend as SmtpEmailBackend | ||
from django.core.mail import send_mail, BadHeaderError, EmailMessage, get_connection | ||
from django.core.mail import BadHeaderError, EmailMessage, get_connection | ||
|
||
import settings | ||
|
||
|
||
class ContactForm(forms.Form): | ||
name = forms.CharField() | ||
email = forms.EmailField() | ||
phone_number = forms.CharField(required=False) | ||
company = forms.CharField(required=False) | ||
message = forms.CharField(widget=forms.widgets.Textarea()) | ||
|
||
def clean(self): | ||
try: | ||
self.send_mail(DummyEmailBackend()) | ||
except BadHeaderError: | ||
raise forms.ValidationError('Invalid header found.') | ||
|
||
return self.cleaned_data | ||
|
||
def send_mail(self, connection=None): | ||
name = self.cleaned_data.get('name', None) | ||
email = self.cleaned_data.get('email') | ||
phone_number = self.cleaned_data.get('phone_number') | ||
company = self.cleaned_data.get('company') | ||
message = self.cleaned_data.get('message') | ||
|
||
if name and company: | ||
subject = 'Contact: {0} ({1})'.format(name, company) | ||
else: | ||
subject = 'Contact: {0}'.format(name) | ||
|
||
body = '{0}\n\n{1}'.format(message, name) | ||
|
||
if (phone_number): | ||
body = '{0}\n{1}'.format(body, phone_number) | ||
|
||
connection = connection or get_connection() | ||
EmailMessage(subject, body, email, zip(*settings.MANAGERS)[1], | ||
|
||
EmailMessage(subject, body, email, zip(*settings.MANAGERS)[1], | ||
connection=connection).send() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
from django.conf.urls.defaults import patterns, include, url | ||
from django.conf.urls.defaults import patterns, url | ||
from django.views.generic.simple import direct_to_template | ||
from django.contrib import admin, sitemaps | ||
from django.contrib import admin | ||
|
||
admin.autodiscover() | ||
|
||
urlpatterns = patterns('', | ||
url(r'^$', direct_to_template, {'template': 'home.html'}, name='home'), | ||
|
||
url(r'^contact/$', 'views.contact', name='contact'), | ||
url(r'^thanks/$', direct_to_template, {'template': 'thanks.html'}, name='thanks'), | ||
|
||
url(r'^thanks/$', direct_to_template, {'template': 'thanks.html'}, | ||
name='thanks'), | ||
|
||
url(r'^404/$', direct_to_template, {'template': '404.html'}, name='404'), | ||
url(r'^500/$', direct_to_template, {'template': '500.html'}, name='500'), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters