22
33
44from django .conf import settings
5+ from django .core .exceptions import ImproperlyConfigured
6+ from django .core .urlresolvers import reverse
7+ from django .views .generic import FormView
58from django .views .generic .base import TemplateView
69from pythonkc_meetups import PythonKCMeetups
710from pythonkc_site .forms import ContactForm
1720num_past_events = getattr (settings , 'MEETUP_SHOW_PAST_EVENTS' , 3 )
1821
1922
20- class PythonKCHome (TemplateView ):
23+ class PythonKCHome (FormView ):
2124 template_name = 'index.html'
25+ form_class = ContactForm
26+
27+ def get_success_url (self ):
28+ return reverse ('home' )
29+
30+ def form_valid (self , form ):
31+ # TODO send email
32+ # TODO create success msg with msg framework
33+ return super (PythonKCHome , self ).form_valid (form )
2234
2335 def get_context_data (self , ** kwargs ):
2436 # NOTE Instead of individually caching next/past events, we're
@@ -35,7 +47,7 @@ def get_past_events():
3547 return {
3648 'next_event' : get_next_event (),
3749 'past_events' : get_past_events (),
38- 'form' : ContactForm ()
50+ 'form' : kwargs . get ( 'form' , None ) or ContactForm ()
3951 }
4052
4153
0 commit comments