--- /dev/null
+{% autoescape off %}
+From: Dorestad 1493 <dorestad@evolution-events.nl>
+Subject: Bevestiging reservering Dorestad 1493
+
+Beste {{ booking.name }},
+
+je hebt {{ booking.tickets }} kaarten gereserveerd voor de Dorestad 1493
+voorstelling op: {{ booking.get_show_display }}.
+
+Veel plezier bij de voorstelling!
+
+Evolution Events
+{% endautoescape %}
class Meta:
model=Booking
+def confirm_booking(booking):
+ from django.core.mail import EmailMessage
+
+ context = {'booking' : booking}
+
+ rendered = django.template.loader.render_to_string('tickets/booked.eml', context)
+ (headers, body) = rendered.strip().split('\n\n', 1)
+
+ # Turn the headers into a dict so EmailMessage can turn them into a
+ # string again. Bit pointless, but it works.
+ # Perhaps we should just use python email stuff directly. OTOH, we
+ # still always need to parse for the From header.
+
+ headers_dict = {}
+ # If no From header is present, let EmailMessage do the default
+ # thing
+ from_email = None
+ for header in headers.split('\n'):
+ (field, value) = header.split(':')
+ if (field == 'From'):
+ from_email = value
+ elif (field == 'Subject'):
+ subject = value
+ else:
+ # Don't put From and Subject in the dict, else they'll be
+ # present twice.
+ headers_dict[field] = value
+
+ msg = EmailMessage(
+ # Only setting the From address through headers won't set the
+ # envelope address right.
+ from_email = from_email,
+ subject = subject,
+ body = body,
+ to = [booking.email],
+ headers = headers_dict
+ )
+ msg.send()
+
def book(request):
if request.method == "POST":
f = BookingForm(request.POST)
if f.is_valid():
booking = f.save()
+ confirm_booking(booking)
return render_to_response('tickets/booked.html', {'booking' : booking})
return render_to_response('tickets/bookingform.html', {'form' : f})