from models import *
from modules.notifications.models import *
from django.core.mail import EmailMessage
from django.conf import settings

def send_paper_submitted(request,paper_submission):
    
    paper = paper_submission.paper

    message = """
<p>Dear Member</p>

<p>Your submission to the paper <strong>%s</strong> has been completed.</p>

<p>Please find attached your certificate, to confirm your CPD points.</p>

<p>This is an automatic email generated by the %s website.</p>""" % (paper.name, settings.WEBSITE_CODE)

    msg = EmailMessage('%s - Your Certificate' % settings.WEBSITE_CODE, message, 'daniel@calmdigital.com', [paper_submission.member.user.email])
    if paper_submission.certificate:
        msg.attach_file(paper_submission.certificate.path)
    msg.content_subtype = "html"

    msg.send()
    
    admin_message = """
            
<p><strong>%s %s</strong> has completed a submission to the paper <strong>%s</strong> on the %s website.</p>

<p>To view this submission, please go to <a href="http://%s%s">http://%s%s</a></p>

<p>This is an automatic email generated by the %s website.</p>""" % (paper_submission.member.given_name,paper_submission.member.surname,paper.name,settings.WEBSITE_CODE, request.META['HTTP_HOST'],reverse('admin_papers_view_submission',args=[paper.id,paper_submission.id]),request.META['HTTP_HOST'],reverse('admin_papers_view_submission',args=[paper.id,paper_submission.id]), settings.WEBSITE_CODE)
    
    msg = EmailMessage('%s - A Submission has Been Made' % settings.WEBSITE_CODE, admin_message,  'daniel@calmdigital.com',['daniel@calmdigital.com'])
    msg.content_subtype = "html"

    msg.send()