Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pythonkc_site/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
from django.conf.urls import patterns
from django.conf.urls import url
from django.views.decorators.cache import cache_page
from pythonkc_site.views import PythonKCHome
from pythonkc_site.views import PythonKCHome, home

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

urlpatterns = patterns('',
url(r'^/?$', cache_page(60 * 5)(PythonKCHome.as_view()), name='home'),
#url(r'^/?$', cache_page(60 * 5)(PythonKCHome.as_view()), name='home'),
url(r'^/?$', cache_page(60 * 5)(home), name='home'),

# Examples:
# url(r'^$', 'pythonkc_site.views.home', name='home'),
Expand Down
20 changes: 20 additions & 0 deletions pythonkc_site/views.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
# -*- coding: utf-8 -*-


from django.shortcuts import render, redirect
from django.core.urlresolvers import reverse
from django.views.generic import FormView
from pythonkc_site.contact.email import send_contact_form_email
from pythonkc_site.contact.forms import ContactForm
from pythonkc_site.meetups import events


# 1. function-based view
def home(request):
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
send_contact_form_email(**form.cleaned_data)
return redirect('{0}?contact_sent=yes'.format(reverse('home')))
else:
form = ContactForm()

context = {
'next_event': events.get_next_event(),
'past_events': events.get_past_events(),
'form': form
}
return render(request, 'index.html', context)


# 2. identical class-based view
class PythonKCHome(FormView):
template_name = 'index.html'
form_class = ContactForm
Expand Down