Exemple #1
0
    def post(self, request):
        _from = ContactRegisterForm(request.POST)
        if _from.is_valid():
            name = request.POST.get('name')
            phone = request.POST.get('phone')
            password = request.POST.get('password')
            area = int(request.POST.get('area'))

            contact = Contact.objects.filter(phone=phone)
            if contact.count() > 0:
                return ResponseResult(-1, 'fail', "该号码已经注册")
            else:
                area_object = Area.objects.get(id=int(area))

                contact = Contact()
                contact.name = name
                contact.phone = phone
                contact.password = password
                contact.area = area_object
                contact.save()
                request.session['contact_id'] = contact.id
                return ResponseResult()

        else:
            return ResponseResult(-1, 'fail', "请求失败")
Exemple #2
0
    def post(self, request):
        form = ContactForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            name = data["name"]

            email = data["email"]
            message = data["message"]
            contact = Contact()
            contact.name = name
            contact.email = email
            contact.message = message
            contact.save()
            return HttpResponseRedirect('/merci/')
        else:

            block_script = BlockText.objects.all().filter(
                location="script").order_by("-id")
            script_site = None
            if block_script.count() > 0:
                script_site = block_script[0]

            return render(
                request, self.template_name, {
                    "form": form,
                    "message": "merci de corriger les erreurs suivants",
                    "script_site": script_site
                })
Exemple #3
0
def send(request):
    name = request.POST['name']
    email = request.POST['email']
    phone = request.POST['phone']
    message = request.POST['message']
    ip = request.META.get('REMOTE_ADDR')
    country = ""
    city = ""
    os = ""

    if not name or name == "Name":
        return HttpResponse("no_name")

    if not email or email == "E-mail":
        return HttpResponse("no_email")

    try:
        validate_email(email)
    except:
        return HttpResponse("no_valid_email")

    if not phone or phone == "Phone":
        return HttpResponse("no_phone")

    if not message or message == "Message":
        return HttpResponse("no_message")

    try:
        my_email = '*****@*****.**'
        subject = 'New contact!'
        html = "Name: " + name
        html = html + "<br>E-mail: " + email
        html = html + "<br>Phone: " + phone
        html = html + "<br><br>" + message
        _send_email(my_email, subject, html)
        email_feedback = "sent"

    except: 
        email_feedback = "error"

    try:
        contact = Contact()
        contact.name = name
        contact.email = email
        contact.phone = phone
        contact.message = message
        contact.ip = ip
        contact.country = country
        contact.city = city
        contact.os = os
        contact.email_feedback = email_feedback
        contact.date = datetime.now()
        contact.save()

        return HttpResponse("saved")

    except:
        return HttpResponse("error")
Exemple #4
0
def contact(request):
    if request.method == 'POST':
        contact_data = Contact()
        contact_data.name = request.POST.get('name')
        contact_data.email = request.POST.get('email')
        contact_data.subject = request.POST.get('subject')
        contact_data.message = request.POST.get('message')
        contact_data.save()

    return render(request, 'contact.html')
Exemple #5
0
 def form_valid(self, form):
     emergency_detail = Contact()
     emergency_detail.branch = Branch.objects.get(id=self.request.POST.get('branch'))
     emergency_detail.contact_name = self.request.POST.get('contact_name')
     emergency_detail.extension_number = self.request.POST.get('extension_number')
     emergency_detail.name = self.request.POST.get('name')
     emergency_detail.email = self.request.POST.get('email')
     emergency_detail.image = self.request.FILES.get('image')
     emergency_detail.save()
     return redirect('emergency:emergencyDetails_list')
Exemple #6
0
def home(request):
    if request.method == 'POST':
        name = request.POST.get('name')
        email = request.POST.get('email')
        message = request.POST.get('message')

        contact = Contact()
        contact.name = name
        contact.email = email
        contact.message = message
        contact.save()
        return render(request, template_name='index.html')
    return render(request, template_name='index.html')
Exemple #7
0
def submit_query(request):
    contact = Contact()
    contact.name = request.POST.get('name')
    contact.email = request.POST.get('email')
    contact.subject = request.POST.get('subject')
    contact.query = request.POST.get('message')
    contact.resolved = False
    contact.save()
    message = """Subject:  """ + contact.subject \
              + """ Dear """ + contact.name + """
    
        Thank you for letting us know about your issue and sorry for inconvenience. We will surely get back to you as soon as possible and also thank you for
        using our services.
         
        Yours sincerely 
        D's Blog Team
    """
    return redirect('/')
Exemple #8
0
def vendor(request):
    context = {
        "vendor": Vendor.objects.all()
    }

    if request.method == 'POST':
        vendor = Vendor()
        vendor.vendor_type = request.POST.get('vendor_type')
        vendor.vendor_name = request.POST.get('vendor_name')
        vendor.address = request.POST.get('address')
        vendor.city = request.POST.get('city')
        vendor.state = request.POST.get('state')
        vendor.country = request.POST.get('country')
        vendor.phone_number = request.POST.get('phone_number')
        vendor.mobile1 = request.POST.get('mobile1')
        vendor.email = request.POST.get('email')
        vendor.pan_no = request.POST.get('pan_no')
        vendor.website = request.POST.get('website')
        vendor.tag = request.POST.get('tag')

        contact = Contact()
        contact.name = request.POST.get('vendor_name')

        contact.address = request.POST.get('address')
        contact.city = request.POST.get('city')
        contact.state = request.POST.get('state')
        contact.country = request.POST.get('country')
        contact.phone_number = request.POST.get('phone_number')
        contact.mobile_number = request.POST.get('mobile1')
        contact.email = request.POST.get('email')
        contact.pan_no = request.POST.get('pan_no')
        contact.website = request.POST.get('website')
        contact.tag = request.POST.get('tag')

        contact.save()


        vendor.save()
        return render(request, 'product/vendor/vendor.html', context)

    else:
        return render(request, 'product/vendor/vendor.html', context)
import requests
import sys, os

project_dir = "/Users/femi/PycharmProjects/phonebook_interface/phonebook/phonebook"
sys.path.append(project_dir)
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

import django
django.setup()
from contact.models import Contact
url = "http://www.mocky.io/v2/581335f71000004204abaf83"

contact_list = requests.get(url).json()

for items in contact_list:
    for x in contact_list[items]:
        contact = Contact()
        contact.name = x['name']
        contact.phone_number = x['phone_number']
        contact.address = x['address']
        contact.save()
Exemple #10
0
def add_contact():
    c = Contact()
    c.name = 'me'
    c.address  = 'here'
    c.phone = '42'
    c.save()