Skip to content

Commit

Permalink
Various pep8 fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
William Fagan committed Jun 23, 2011
1 parent 1bf2875 commit 5e44c72
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
22 changes: 11 additions & 11 deletions forms.py
@@ -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()
1 change: 1 addition & 0 deletions templates/base.html
Expand Up @@ -5,6 +5,7 @@
<link href='http://fonts.googleapis.com/css?family=Ubuntu:regular,bold&v1' rel='stylesheet' type='text/css'>
<title>Wichita Code | {% block title %}{% endblock %}</title>
<link rel=stylesheet href="{{ STATIC_URL }}style.css" type="text/css" />
<link rel="shortcut icon" href="{{ STATIC_URL }}favicon.ico" />
<script type="text/javascript">

var _gaq = _gaq || [];
Expand Down
11 changes: 6 additions & 5 deletions urls.py
@@ -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'),
)
11 changes: 5 additions & 6 deletions views.py
@@ -1,23 +1,22 @@
from django.shortcuts import render_to_response, redirect
from django.template import RequestContext
from django.forms.util import ErrorList

from forms import ContactForm
import settings


def contact(request):
if request.method == 'POST':
form = ContactForm(request.POST)

if form.is_valid():
form.send_mail()

return redirect('thanks')
else:
form = ContactForm()

response_data = {
'contact_form': form
'contact_form': form,
}

return render_to_response('contact.html', response_data,
Expand Down

0 comments on commit 5e44c72

Please sign in to comment.