tickets: Generalize the confirm_booking function.
authorMatthijs Kooijman <matthijs@stdin.nl>
Tue, 19 Oct 2010 13:38:44 +0000 (15:38 +0200)
committerMatthijs Kooijman <matthijs@stdin.nl>
Tue, 19 Oct 2010 13:40:26 +0000 (15:40 +0200)
It can now be reused for sending payment confirmations.

tickets/views.py

index f8ec3ba874e1a87e7659420e57ede3e87c9249fc..a06086d593646c7ad7ccd7bf4cfbd4150abd49c3 100644 (file)
@@ -13,12 +13,12 @@ class BookingForm(django.forms.ModelForm):
         model=Booking
         exclude=['payment']
 
-def confirm_booking(booking):
+def confirm_booking(booking, template):
     from django.core.mail import EmailMessage
 
     context = {'booking' : booking}
 
-    rendered = django.template.loader.render_to_string('tickets/booked.eml', context)
+    rendered = django.template.loader.render_to_string(template, context)
     (headers, body) = rendered.strip().split('\n\n', 1)
 
     # Turn the headers into a dict so EmailMessage can turn them into a
@@ -60,7 +60,7 @@ def book(request):
 
     if f.is_valid():
         booking = f.save()
-        confirm_booking(booking)
+        confirm_booking(booking, 'tickets/booked.eml')
         return render_to_response('tickets/booked.html', {'booking' : booking}, context_instance=RequestContext(request))
 
     return render_to_response('tickets/bookingform.html', {'form' : f}, context_instance=RequestContext(request))