Added comfirmation mails.

This commit is contained in:
Robert Kolner committed 2013-09-03 18:49:59 +02:00
1 parent 7a19780fe3
commit ae3e9502bd
5 files changed
+27 -6

No files matched your search

+23 -3
View File
@@ -1,5 +1,6 @@
from datetime import datetime, timedelta
from django.core.context_processors import csrf
from django.core import mail
from django.core.exceptions import ObjectDoesNotExist
from django.http import HttpResponse, Http404
from django.template import Context
@@ -11,12 +12,13 @@ from lib import trello
import utils
class BaseFormView(TemplateView):
template_name = None
mail_template_name = "confirmation_mail.txt"
form_template_name = None
trello_board_id = None
params_list = None
def get(self, request):
template = get_template(self.template_name)
template = get_template(self.form_template_name)
context_data = {}
context_data.update(csrf(request))
@@ -29,7 +31,7 @@ class BaseFormView(TemplateView):
# If there were errors in parsing form (missing parameters etc.):
if errors is not None and len(errors) > 0:
template = get_template(self.template_name)
template = get_template(self.form_template_name)
context_data = params.copy()
context_data['errors'] = errors
context_data.update(csrf(request))
@@ -38,6 +40,8 @@ class BaseFormView(TemplateView):
return HttpResponse(response)
order = self._save_data(request, params)
self._send_confirmation_mail(request, order)
template = get_template('form_success.html')
context_data = {
'url' : self._get_order_url(request, order),
@@ -81,6 +85,21 @@ class BaseFormView(TemplateView):
card.client.fetch_json('/cards/'+card.id+'/labels', http_method="POST", post_args = { 'value' : card_colour })
return card
def _send_confirmation_mail(self, request, order):
template = get_template(self.mail_template_name)
context_data = {
'order' : order,
'url' : self._get_order_url(request, order),
}
mail_from = "noreply@studentersamfundet.no"
mail_to = order.contact_email
mail_subject = "{id}: Bestillingen din er mottatt.".format(id=order.client)
mail_content = template.render(Context(context_data))
mail.send_mail(mail_subject, mail_content, mail_from, [ mail_to ], fail_silently=True)
class BaseOrderView(TemplateView):
template_name = None
@@ -149,3 +168,4 @@ class BaseOrderView(TemplateView):
card.fetch()
return map(lambda member_id: client.get_member(member_id).fetch(), card.member_ids)
+1 -1
View File
@@ -11,7 +11,7 @@ from django.template.loader import get_template
class DesignFormView(BaseFormView):
template_name = 'design/form.html'
form_template_name = 'design/form.html'
trello_board_id = settings.TRELLO_DESIGN_BOARD_ID
params_list = [
'client',
+1 -1
View File
@@ -11,7 +11,7 @@ from django.template.loader import get_template
from prm.models import PrmOrder
class PrmFormView(BaseFormView):
template_name = 'prm/form.html'
form_template_name = 'prm/form.html'
trello_board_id = settings.TRELLO_PRM_BOARD_ID
params_list = [
'client',
+1 -1
View File
@@ -11,7 +11,7 @@ from django.template.loader import get_template
from tekst.models import TekstOrder
class TekstFormView(BaseFormView):
template_name = 'tekst/form.html'
form_template_name = 'tekst/form.html'
trello_board_id = settings.TRELLO_TEKST_BOARD_ID
params_list = [
'client',
@@ -0,0 +1 @@
Takk for din bestilling! Du kan alltid finne den igjen under følgende lenke: {{ url }}