from django.core.mail import send_mail
from django.db.models.signals import post_save
from django.dispatch import receiver
from posts.models import Signup
from django.template import Context, Template


@receiver(post_save, sender=Signup)
def signup_post_save(sender, instance, created, **kwargs):
    pass
    # if created:
    #     assert isinstance(instance, Signup)
    #     mentor = instance.offer.user
    #     refugee = instance.user
    #
    #     ctx = Context({
    #         'mentor': mentor.get_full_name(),
    #         'refugee': refugee.get_full_name(),
    #         'location': instance.offer.location.name,
    #         'begin': instance.offer.begin,
    #         'email': mentor.email,
    #         'phone': mentor.profile.phone if mentor.profile.phone else 'N/A',
    #     })
    #     tmpl = Template('{{refugee}} just signed up for your mentoring!\n'
    #                     + 'The meeting point is {{location}} and meeting time {{begin}}.\n'
    #                     + '{refugee} email is {{email}} and phone number {{phone}}.\n'
    #                     + '\n'
    #                     + 'Thanks for supporting!\n'
    #                     + 'CitizenMatch\n')
    #
    #     send_mail('New signup!', tmpl.render(ctx), 'info@citizenmatch.org', [mentor.email], fail_silently=True)
