def create_lead_from_site(request): allowed_domains = [ 'micropyramid.com', 'test.microsite.com:8000', ] # add origin_domain = request.get_host() in the post body if (request.get_host() in [ 'sales.micropyramid.com', ] and request.POST.get('origin_domain') in allowed_domains): if request.method == 'POST': if request.POST.get('full_name', None): lead = Lead.objects.create( title=request.POST.get('full_name'), email=request.POST.get('email'), phone=request.POST.get('phone'), description=request.POST.get('message'), created_from_site=True) recipients = User.objects.filter(role='ADMIN').values_list( 'id', flat=True) lead.assigned_to.add(*recipients) from leads.tasks import send_email_to_assigned_user send_email_to_assigned_user(recipients, lead.id, domain='sales.micropyramid.com') return HttpResponse('Lead Created') from django.http import HttpResponseBadRequest return HttpResponseBadRequest('Bad Request')
def create_lead_from_site(request): # pragma: no cover allowed_domains = [ 'micropyramid.com', 'test.microsite.com:8000', ] # add origin_domain = request.get_host() in the post body if (request.get_host() in [ 'sales.micropyramid.com', ] and request.POST.get('origin_domain') in allowed_domains): if request.method == 'POST': if request.POST.get('full_name', None): try: description = request.POST.get( 'enquiry_type') + '\n' + request.POST.get('message') except Exception as e: print("e:::", e) country = request.POST.get('country').title() country_codes = list(COUNTRIES) for count in country_codes: if country == count[1]: country = count[0] break phone = request.POST.get('phone') phone_number = phonenumbers.parse(phone, country) lead = Lead.objects.create(title=request.POST.get('full_name'), email=request.POST.get('email'), phone=phone_number, description=description, country=country, created_from_site=True) lead.source = 'micropyramid' lead.save() recipients = User.objects.filter(role='ADMIN').values_list( 'id', flat=True) lead.assigned_to.add(*recipients) from leads.tasks import send_email_to_assigned_user send_email_to_assigned_user( recipients, lead.id, domain='sales.micropyramid.com', source=request.POST.get('origin_domain')) return HttpResponse('Lead Created') from django.http import HttpResponseBadRequest return HttpResponseBadRequest('Bad Request')