from django.http import HttpResponse
from django.core.mail import send_mail


def contact_person(request):
    frm = request.user.email
    to_event = request.GET.get("to", None)
    try:
        to = Event.objects.get(pk=to_person)
    except:
        return HttpResponse("An error occurred. Please contact contact@theatreforum.in and let us know. Thanks.")
    message = request.GET.get("message", None)
    if not message:
        return HttpResponse("Please enter a message.")
    if not to.user:
        return HttpResponse("Sorry, person does not have an email address associated on the site.")
    else:
        to_email = to.user.email
        send_mail("Contact about event %s" % to.title, message, frm, [to_email])
        return HttpResponse("Your message has been sent, thanks.")
    
