from models import *
from modules.notifications.models import *

def theory_application_form_completed(request,exam_application):

    try:
        template = EmailTemplate.objects.get(key='theory_exam_submitted')

        message = template.content % (exam_application.exam)
        subject = template.subject

        send_mail(template.key,subject,message,template.from_address.email_address,exam_application.email_address)
    except Exception, e:
        raise e

    #admin email
    try:
        template = EmailTemplate.objects.get(key='theory_exam_submitted_admin')
        if exam_application.get_payment_amount():
            extra = "<br/><strong>Payment Method:</strong> %s" % (exam_application.get_payment_type_display())
        else:
            extra = ""
        message = template.content % (exam_application.first_name, exam_application.surname,exam_application.email_address,exam_application.exam,extra,request.META['HTTP_HOST'],reverse('admin_theory_exam_view_application',args=[exam_application.exam.id,exam_application.id]))
        subject = template.subject

        send_mail(template.key,subject,message,template.from_address.email_address,template.get_to_addresses())
    except Exception, e:
        raise e


def theory_application_form_completed_unpaid(request,exam_application):

    try:
        template = EmailTemplate.objects.get(key='theory_exam_submitted_unpaid')

        message = template.content % (exam_application.exam)
        subject = template.subject

        send_mail(template.key,subject,message,template.from_address.email_address,exam_application.email_address)
    except Exception, e:
        raise e

    #admin email
    try:
        template = EmailTemplate.objects.get(key='theory_exam_submitted_admin')
        extra = "<br/><strong>Payment Method:</strong> %s" % (exam_application.get_payment_type_display())
        message = template.content % (exam_application.first_name, exam_application.surname,exam_application.email_address,exam_application.exam,extra,request.META['HTTP_HOST'],reverse('admin_theory_exam_view_application',args=[exam_application.exam.id,exam_application.id]))
        subject = template.subject

        send_mail(template.key,subject,message,template.from_address.email_address,template.get_to_addresses())
    except Exception, e:
        raise e


def theory_application_form_paid(request,exam_application):

    try:
        template = EmailTemplate.objects.get(key='theory_exam_paid')

        message = template.content % (exam_application.exam)
        subject = template.subject

        send_mail(template.key,subject,message,template.from_address.email_address,exam_application.email_address)
    except Exception, e:
        raise e
