Ejemplo n.º 1
0
def contact(request):
    validate_simplecontact = SimpleContactForm(request.POST)
    validate_contact = ContactForm(request.POST)

    if 'category' in request.POST.keys():
        if validate_simplecontact.is_valid() and validate_contact.is_valid():
            contact = simplecontact.objects.create(full_name=request.POST.get('full_name'), message=request.POST.get('message'),\
                                                    email=request.POST.get('email'), phone=request.POST.get('phone') if request.POST.get('phone') else False)
            Contact.objects.create(contact_info=contact, category=request.POST.get('category'), domain=request.POST.get('domain'),\
                domain_url=request.POST.get('domain_url'), skype=request.POST.get('skype'), country=request.POST.get('country'),\
                budget=request.POST.get('budget'), technology=request.POST.get('technology'),\
                requirements=request.POST.get('requirements'), enquery_type=request.POST.get('enquery_type'))
        else:
            errors = {}
            errors = dict((validate_simplecontact.errors).items() + (validate_contact.errors).items())
            data = {'error': True, 'errinfo': errors}
            return HttpResponse(json.dumps(data), content_type='application/json; charset=utf-8')

    if validate_simplecontact.is_valid():
        simplecontact.objects.get_or_create(full_name=request.POST.get('full_name'), message=request.POST.get('message'), email=request.POST.get('email'),\
                                                phone=request.POST.get('phone') if request.POST.get('phone') else False)
    else:
        errors = {}
        errors = dict((validate_simplecontact.errors).items())
        data = {'error': True, 'errinfo': errors}
        return HttpResponse(json.dumps(data), content_type='application/json; charset=utf-8')

    message = "<p>From: "+request.POST.get('full_name')+"</p><p>Email Id: "+request.POST.get('email')+"</p><p>Message: "+request.POST.get('message')+"</p>"

    if request.POST.get('phone'):
        message += "<p>Contact Number: "+request.POST.get('phone')+"</p>"

    if 'category' in request.POST.keys():
        message += "<p>Skype ID: "+request.POST.get('skype')+"</p><p>Country: "+request.POST.get('country')+"</p><p><b>Domain Details: </b></p><p>Domain: "+\
                    request.POST.get('domain')+ "</p><p>Domain URL: "+request.POST.get('domain_url')+"</p>"

        message += "<p><b>General Information: </b></p><p>Category: "+request.POST.get('category')+"</p><p>Requirements: "+\
                    request.POST.get('requirements')+"</p><p>Technology: "+request.POST.get('technology')+"</p><p>Enquery Type: "+\
                    request.POST.get('enquery_type')+"</p><p>Budget: "+request.POST.get('budget')+"</p>"

    sg = sendgrid.SendGridClient(settings.SG_USER, settings.SG_PWD)

    contact_msg = sendgrid.Mail()
    contact_msg.set_subject("Thank u for ur message")
    contact_msg.set_text('Thank you for contacting us. We will get back to you soon!!!')
    contact_msg.set_from("*****@*****.**")
    contact_msg.add_to(request.POST.get('email'))
    sg.send(contact_msg)

    sending_msg = sendgrid.Mail()
    sending_msg.set_subject("Contact Request")
    sending_msg.set_html(message)
    sending_msg.set_text('Contact Request')
    sending_msg.set_from(request.POST.get('email'))
    sending_msg.add_to("*****@*****.**")
    sg.send(sending_msg)

    data = {'error': False, 'response': 'submitted successfully'}

    return HttpResponse(json.dumps(data), content_type='application/json; charset=utf-8')
Ejemplo n.º 2
0
 def test_ContactForm(self):
     self.client = Client()
     form = SimpleContactForm(
         data={
             'full_name': 'jagadeesh',
             'message': 'sample',
             'email': '*****@*****.**',
             'phone': '94'
         })
     self.assertTrue(form.is_valid())
Ejemplo n.º 3
0
def contact(request):
    validate_simplecontact = SimpleContactForm(request.POST)
    validate_contact = ContactForm(request.POST)

    if 'category' in request.POST.keys():
        if validate_simplecontact.is_valid() and validate_contact.is_valid():
            contact = simplecontact.objects.create(full_name=request.POST.get('full_name'), message=request.POST.get('message'),\
                                                        email=request.POST.get('email'), phone=request.POST.get('phone') if request.POST.get('phone') else False)
            Contact.objects.create(contact_info=contact, category=request.POST.get('category'), domain=request.POST.get('domain'), domain_url=request.POST.get('domain_url'),\
                skype=request.POST.get('skype'), country=request.POST.get('country'), budget=request.POST.get('budget'), technology=request.POST.get('technology'),\
                requirements=request.POST.get('requirements'), enquery_type=request.POST.get('enquery_type'))
        else:
            errors = {}
            errors = dict((validate_simplecontact.errors).items() + (validate_contact.errors).items())
            data = {'error': True, 'errinfo': errors}
            return HttpResponse(json.dumps(data))

    if validate_simplecontact.is_valid():
        simplecontact.objects.get_or_create(full_name=request.POST.get('full_name'), message=request.POST.get('message'), email=request.POST.get('email'), phone=request.POST.get('phone') if request.POST.get('phone') else False)
    else:
        errors = {}
        errors = dict((validate_simplecontact.errors).items())
        data = {'error': True, 'errinfo': errors}
        return HttpResponse(json.dumps(data))

    send_mail('Thank u for ur message', "Thank you for contacting us. We will get back to you soon!!!", "*****@*****.**", [request.POST.get('email')], fail_silently=False)

    message = "<p>From: "+request.POST.get('full_name')+"</p><p>Email Id: "+request.POST.get('email')+"</p><p>Message: "+request.POST.get('message')+"</p>"

    if request.POST.get('phone'):
        message += "<p>Contact Number: "+request.POST.get('phone')+"</p>"

    if 'category' in request.POST.keys():
        message += "<p>Skype ID: "+request.POST.get('skype')+"</p><p>Country: "+request.POST.get('country')+"</p><p><b>Domain Details: </b></p><p>Domain: "+request.POST.get('domain')+\
                    "</p><p>Domain URL: "+request.POST.get('domain_url')+"</p>"

        message += "<p><b>General Information: </b></p><p>Category: "+request.POST.get('category')+"</p><p>Requirements: "+\
                    request.POST.get('requirements')+"</p><p>Technology: "+request.POST.get('technology')+"</p><p>Enquery Type: "+\
                    request.POST.get('enquery_type')+"</p><p>Budget: "+request.POST.get('budget')+"</p>"

    sending_msg = EmailMessage('Contact Request', message, request.POST.get('email'),
                        ["*****@*****.**"])

    sending_msg.content_subtype = "html"

    sending_msg.send()

    data = {'error': False, 'response': 'submitted successfully'}

    return HttpResponse(json.dumps(data))
Ejemplo n.º 4
0
def contact(request):
    if request.method == 'GET':
        return render(request, 'site/pages/contact-us.html')
    validate_simplecontact = SimpleContactForm(request.POST)
    validate_contact = ContactForm(request.POST)
    if 'enquery_type' in request.POST.keys():
        if validate_simplecontact.is_valid() and validate_contact.is_valid():
            contact = simplecontact.objects.create(
                full_name=request.POST.get('full_name'), message=request.POST.get('message'),
                email=request.POST.get('email'),
                phone=request.POST.get('phone') if request.POST.get('phone') else False
            )
            Contact.objects.create(
                contact_info=contact, domain=request.POST.get('domain'),
                domain_url=request.POST.get('domain_url'), country=request.POST.get('country'),
                enquery_type=request.POST.get('enquery_type')
            )
        else:
            errors = {}
            errors = dict((validate_simplecontact.errors).items() + (validate_contact.errors).items())
            data = {'error': True, 'errinfo': errors}
            return HttpResponse(json.dumps(data), content_type='application/json; charset=utf-8')
    else:
        if validate_simplecontact.is_valid():
            simplecontact.objects.get_or_create(
                full_name=request.POST.get('full_name'), message=request.POST.get('message'),
                email=request.POST.get('email'),
                phone=request.POST.get('phone') if request.POST.get('phone') else False
            )
        else:
            errors = {}
            errors = dict((validate_simplecontact.errors).items())
            data = {'error': True, 'errinfo': errors}
            return HttpResponse(json.dumps(data), content_type='application/json; charset=utf-8')

    message = "<p>From: "+request.POST.get('full_name')+"</p><p>Email Id: "
    message += request.POST.get('email')+"</p><p>Message: "+request.POST.get('message')+"</p>"

    if request.POST.get('phone'):
        message += "<p>Contact Number: "+request.POST.get('phone')+"</p>"

    if 'enquery_type' in request.POST.keys():
        message += "<p><b>Domain Details: </b></p><p>Domain: "+request.POST.get('domain')+\
                    "</p><p>Domain URL: "+request.POST.get('domain_url')+"</p>"

        message += "<p><b>General Information: </b></p>"+"<p>Enquery Type: "+\
                    request.POST.get('enquery_type')+"</p><p>Country: "+request.POST.get('country')

    sg = sendgrid.SendGridClient(settings.SG_USER, settings.SG_PWD)

    contact_msg = sendgrid.Mail()
    contact_msg.set_subject("We received your message | MicroPyramid")
    message_reply = 'Hello ' + request.POST.get('full_name') + ',\n\n'
    message_reply = message_reply + 'Thank you for writing in.\n'
    message_reply = message_reply +  'We appreciate that you have taken the time to share your feedback with us! We will get back to you soon.\n\n'
    message_reply = message_reply + 'Regards\n'
    message_reply = message_reply + 'The MicroPyramid Team.'
    contact_msg.set_text(message_reply)
    contact_msg.set_from("*****@*****.**")
    contact_msg.add_to(request.POST.get('email'))
    sg.send(contact_msg)

    sending_msg = sendgrid.Mail()
    sending_msg.set_subject("Contact Request")
    sending_msg.set_html(message)
    sending_msg.set_text('Contact Request')
    sending_msg.set_from(request.POST.get('email'))
    sending_msg.add_to("*****@*****.**")
    sg.send(sending_msg)

    data = {'error': False, 'response': 'Contact submitted successfully'}
    return HttpResponse(json.dumps(data), content_type='application/json; charset=utf-8')
Ejemplo n.º 5
0
 def test_ContactForm(self):
     self.client = Client()
     form = SimpleContactForm(
         data={'full_name': 'ashwin', 'message': 'sample', 'email': '*****@*****.**', 'phone': '94'})
     self.assertTrue(form.is_valid())
Ejemplo n.º 6
0
 def test_SimpleContactForm(self):
     self.client = Client()
     form = SimpleContactForm(
         data={'full_name': 'jagadeesh', 'message': 'sample', 'email': '*****@*****.**', 'phone': '9876543210'})
     self.assertTrue(form.is_valid())
Ejemplo n.º 7
0
def contact(request):
    if request.method == 'GET':
        raise Http404
    validate_simplecontact = SimpleContactForm(request.POST)
    validate_contact = ContactForm(request.POST)

    if 'category' in request.POST.keys():
        if validate_simplecontact.is_valid() and validate_contact.is_valid():
            contact = simplecontact.objects.create(full_name=request.POST.get('full_name'), message=request.POST.get('message'),\
                                                    email=request.POST.get('email'), phone=request.POST.get('phone') if request.POST.get('phone') else False)
            Contact.objects.create(contact_info=contact, category=request.POST.get('category'), domain=request.POST.get('domain'),\
                domain_url=request.POST.get('domain_url'), skype=request.POST.get('skype'), country=request.POST.get('country'),\
                budget=request.POST.get('budget'), technology=request.POST.get('technology'),\
                requirements=request.POST.get('requirements'), enquery_type=request.POST.get('enquery_type'))
        else:
            errors = {}
            errors = dict((validate_simplecontact.errors).items() +
                          (validate_contact.errors).items())
            data = {'error': True, 'errinfo': errors}
            return HttpResponse(json.dumps(data),
                                content_type='application/json; charset=utf-8')

    if validate_simplecontact.is_valid():
        simplecontact.objects.get_or_create(full_name=request.POST.get('full_name'), message=request.POST.get('message'), email=request.POST.get('email'),\
                                                phone=request.POST.get('phone') if request.POST.get('phone') else False)
    else:
        errors = {}
        errors = dict((validate_simplecontact.errors).items())
        data = {'error': True, 'errinfo': errors}
        return HttpResponse(json.dumps(data),
                            content_type='application/json; charset=utf-8')

    message = "<p>From: " + request.POST.get(
        'full_name') + "</p><p>Email Id: " + request.POST.get(
            'email') + "</p><p>Message: " + request.POST.get(
                'message') + "</p>"

    if request.POST.get('phone'):
        message += "<p>Contact Number: " + request.POST.get('phone') + "</p>"

    if 'category' in request.POST.keys():
        message += "<p>Skype ID: "+request.POST.get('skype')+"</p><p>Country: "+request.POST.get('country')+"</p><p><b>Domain Details: </b></p><p>Domain: "+\
                    request.POST.get('domain')+ "</p><p>Domain URL: "+request.POST.get('domain_url')+"</p>"

        message += "<p><b>General Information: </b></p><p>Category: "+request.POST.get('category')+"</p><p>Requirements: "+\
                    request.POST.get('requirements')+"</p><p>Technology: "+request.POST.get('technology')+"</p><p>Enquery Type: "+\
                    request.POST.get('enquery_type')+"</p><p>Budget: "+request.POST.get('budget')+"</p>"

    sg = sendgrid.SendGridClient(settings.SG_USER, settings.SG_PWD)

    contact_msg = sendgrid.Mail()
    contact_msg.set_subject("Thank u for ur message")
    contact_msg.set_text(
        'Thank you for contacting us. We will get back to you soon!!!')
    contact_msg.set_from("*****@*****.**")
    contact_msg.add_to(request.POST.get('email'))
    sg.send(contact_msg)

    sending_msg = sendgrid.Mail()
    sending_msg.set_subject("Contact Request")
    sending_msg.set_html(message)
    sending_msg.set_text('Contact Request')
    sending_msg.set_from(request.POST.get('email'))
    sending_msg.add_to("*****@*****.**")
    sg.send(sending_msg)

    data = {'error': False, 'response': 'submitted successfully'}
    return HttpResponse(json.dumps(data),
                        content_type='application/json; charset=utf-8')
Ejemplo n.º 8
0
def contact(request):
    if request.method == "GET":
        raise Http404
    validate_simplecontact = SimpleContactForm(request.POST)
    validate_contact = ContactForm(request.POST)

    if "category" in request.POST.keys():
        if validate_simplecontact.is_valid() and validate_contact.is_valid():
            contact = simplecontact.objects.create(
                full_name=request.POST.get("full_name"),
                message=request.POST.get("message"),
                email=request.POST.get("email"),
                phone=request.POST.get("phone") if request.POST.get("phone") else False,
            )
            Contact.objects.create(
                contact_info=contact,
                category=request.POST.get("category"),
                domain=request.POST.get("domain"),
                domain_url=request.POST.get("domain_url"),
                skype=request.POST.get("skype"),
                country=request.POST.get("country"),
                budget=request.POST.get("budget"),
                technology=request.POST.get("technology"),
                requirements=request.POST.get("requirements"),
                enquery_type=request.POST.get("enquery_type"),
            )
        else:
            errors = {}
            errors = dict((validate_simplecontact.errors).items() + (validate_contact.errors).items())
            data = {"error": True, "errinfo": errors}
            return HttpResponse(json.dumps(data), content_type="application/json; charset=utf-8")

    if validate_simplecontact.is_valid():
        simplecontact.objects.get_or_create(
            full_name=request.POST.get("full_name"),
            message=request.POST.get("message"),
            email=request.POST.get("email"),
            phone=request.POST.get("phone") if request.POST.get("phone") else False,
        )
    else:
        errors = {}
        errors = dict((validate_simplecontact.errors).items())
        data = {"error": True, "errinfo": errors}
        return HttpResponse(json.dumps(data), content_type="application/json; charset=utf-8")

    message = (
        "<p>From: "
        + request.POST.get("full_name")
        + "</p><p>Email Id: "
        + request.POST.get("email")
        + "</p><p>Message: "
        + request.POST.get("message")
        + "</p>"
    )

    if request.POST.get("phone"):
        message += "<p>Contact Number: " + request.POST.get("phone") + "</p>"

    if "category" in request.POST.keys():
        message += (
            "<p>Skype ID: "
            + request.POST.get("skype")
            + "</p><p>Country: "
            + request.POST.get("country")
            + "</p><p><b>Domain Details: </b></p><p>Domain: "
            + request.POST.get("domain")
            + "</p><p>Domain URL: "
            + request.POST.get("domain_url")
            + "</p>"
        )

        message += (
            "<p><b>General Information: </b></p><p>Category: "
            + request.POST.get("category")
            + "</p><p>Requirements: "
            + request.POST.get("requirements")
            + "</p><p>Technology: "
            + request.POST.get("technology")
            + "</p><p>Enquery Type: "
            + request.POST.get("enquery_type")
            + "</p><p>Budget: "
            + request.POST.get("budget")
            + "</p>"
        )

    sg = sendgrid.SendGridClient(settings.SG_USER, settings.SG_PWD)

    contact_msg = sendgrid.Mail()
    contact_msg.set_subject("Thank u for ur message")
    contact_msg.set_text("Thank you for contacting us. We will get back to you soon!!!")
    contact_msg.set_from("*****@*****.**")
    contact_msg.add_to(request.POST.get("email"))
    sg.send(contact_msg)

    sending_msg = sendgrid.Mail()
    sending_msg.set_subject("Contact Request")
    sending_msg.set_html(message)
    sending_msg.set_text("Contact Request")
    sending_msg.set_from(request.POST.get("email"))
    sending_msg.add_to("*****@*****.**")
    sg.send(sending_msg)

    data = {"error": False, "response": "submitted successfully"}
    return HttpResponse(json.dumps(data), content_type="application/json; charset=utf-8")