# Path: disparity/apps/core/emails.py
# class DisparityEmail(MarkdownEmail):
#     from_email = settings.DEFAULT_FROM_EMAIL
# 
#     def get_subject(self):
#         return "[Are We Being Underpaid] {0}".format(self.subject)
# 
# Path: disparity/apps/salary/utils.py
# def unsign_survey_token(token):
#     data = signing.loads(
#         token, salt=SURVEY_TOKEN_SALT, max_age=SURVEY_TOKEN_MAX_AGE,
#     )
#     expires_at_str = data.pop('expires_at')
#     data['expires_at'] = parser.parse(expires_at_str)
#     return data


from emailtools import mixins
from django.core.urlresolvers import reverse
from disparity.apps.core.emails import DisparityEmail
from disparity.apps.salary.utils import (
    unsign_survey_token,
)




class SurveyCreationEmail(mixins.BuildAbsoluteURIMixin, DisparityEmail):
    template_name = 'salary/mail/survey_created.html'
    subject = 'Salary Survey Created'

    def __init__(self, email, all_emails, token):
        self.to = email
        self.all_emails = all_emails
        self.token = token

    def get_context_data(self, **kwargs):
        context = super(SurveyCreationEmail, self).get_context_data(**kwargs)
        context.update({
            'token': self.token,
            'all_emails': self.all_emails,
            'survey_url': self.build_absolute_uri(
                reverse('survey-detail', kwargs={'token': self.token})
            ),
        })

# Path: disparity/apps/core/emails.py
# class DisparityEmail(MarkdownEmail):
#     from_email = settings.DEFAULT_FROM_EMAIL
# 
#     def get_subject(self):
#         return "[Are We Being Underpaid] {0}".format(self.subject)
# 
# Path: disparity/apps/salary/utils.py
# def unsign_survey_token(token):
#     data = signing.loads(
#         token, salt=SURVEY_TOKEN_SALT, max_age=SURVEY_TOKEN_MAX_AGE,
#     )
#     expires_at_str = data.pop('expires_at')
#     data['expires_at'] = parser.parse(expires_at_str)
#     return data


# Path: disparity/apps/salary/emails.py
from emailtools import mixins
from django.core.urlresolvers import reverse
from disparity.apps.core.emails import DisparityEmail
from disparity.apps.salary.utils import (
    unsign_survey_token,
)





class SurveyCreationEmail(mixins.BuildAbsoluteURIMixin, DisparityEmail):
    template_name = 'salary/mail/survey_created.html'
    subject = 'Salary Survey Created'

    def __init__(self, email, all_emails, token):
        self.to = email
        self.all_emails = all_emails
        self.token = token

    def get_context_data(self, **kwargs):
        context = super(SurveyCreationEmail, self).get_context_data(**kwargs)
        context.update({
            'token': self.token,
            'all_emails': self.all_emails,
            'survey_url': self.build_absolute_uri(
                reverse('survey-detail', kwargs={'token': self.token})
            ),
        })

        context.update(unsign_survey_token(self.token))