예제 #1
0
def create_contact():
    print(request.form)
    if request.method == 'GET':
        return render_template("create_contact.html")
    else:
        name = request.form.get('name')
        address = request.form.get('address')
        ph_num = request.form.get('ph_num')
        email = request.form.get('email')

        contact = Contact(name=name,
                          address=address,
                          ph_num=ph_num,
                          email=email)
        contact.save()
        return render_template("index.html")
예제 #2
0
def contact_mail(request):
    from user.models import User
    # from user.views import send_mail_to_client
    from application.models import Contact
    import json
    data = {"c": True, "sent": False, "ef": False}
    try:
        name = request.POST["name"]
        email = request.POST['email']
        subject = request.POST['subject']
        message = request.POST['message']
        from django.core.exceptions import ValidationError

        from django.core.validators import validate_email
        try:
            validate_email(email)
        except ValidationError:
            data['ef'] = True
            return HttpResponse(json.dumps(data))
        try:
            cu = Contact(name=name,
                         email=email,
                         subject=subject,
                         message=message)
            cu.save()
            data['sent'] = True
        except Exception as e:
            print(e)
            print("error")
            data['c'] = False
            return HttpResponse(json.dumps(data))

        msg = "<style>@import url('https://fonts.googleapis.com/css?family=Open+Sans&display=swap');</style>"
        msg = msg + "<div style=\"font-family:'Open Sans',Arial,sans-serif;\"><div style='min-height:4rem;width:100%;display:block;border-bottom:1px solid #c5c5c5;margin-bottom:10px;'><div style='width:fit-content;height:fit-content;margin:auto;display:flex;justify-content:center;align-content:center;'><a href='https://wasche-services.herokuapp.com' style='color:black;font-size:1.6rem;text-decoration:none;text-transform:uppercase;letter-spacing:2px;font-weight:bold;padding:0;margin:0;text-shadow:1px 1px 1px rgba(0,0,0,0.1);'>Wasche</a></div></div>"
        msg = msg + "<h2 style='margin-bottom:5px;padding:5px;margin-top:10px;'>Thank you for contacting us.</h2><h4> Your information has been sent to our professional workers.<br>You will soon here from us regarding your enquiry.</h4><br><br><p style='font-size:15px'>Than you, <b>Wasche Laundry Services.</b></p></div> "

        send_mail_to_client(
            email, "Contact Information",
            "Thank you for contacting us.\n\nYour information has been sent to our professional workers.\nYou will soon here from us regarding your enquiry.\n\nThank you, \nWasche Laundry Services.",
            msg)

    except:
        data['sent'] = False
    return HttpResponse(json.dumps(data))