def create(request): if request.method == 'POST': if request.POST['username'] and request.POST[ 'password'] and request.POST['fullname'] and request.POST[ 'email'] and request.POST['phone']: try: customers = Customer.objects.get( username=request.POST['username']) return render(request, 'customers/create.html', {'error': 'Tên đăng nhập đã tồn tại'}) except Customer.DoesNotExist: customer = Customer() customer.address = "" customer.avatar = "" customer.email = request.POST['email'] customer.fullname = request.POST['fullname'] customer.gender = "" customer.info = "" customer.password = request.POST['password'] customer.phone = request.POST['phone'] customer.status = 1 customer.username = request.POST['username'] customer.save() follow = Follow() follow.cusdetail_id = customer.id follow.customer_id = customer.id follow.save() request.session['username'] = customer.username return redirect('/customers/detail/' + str(customer.id)) else: return render(request, 'customers/create.html', {'error': 'All fields are required.'}) else: return render(request, 'customers/create.html')
def import_add(request): from magonet.connector import MagoNet conn = MagoNet() conn.connect() rows = conn.getcustomer_byid(str(request.GET['code'])) conn.disconnect() row = rows[0] cust_list = Customer.objects.filter(origin_code=row['CustSupp']) if cust_list: newcust = cust_list[0] else: newcust = Customer() newcust.address = row['Address'] newcust.city = row['City'] newcust.email = row['EMail'] newcust.name = row['CompanyName'] newcust.origin_code = row['CustSupp'] newcust.telephone = row['Telephone1'] + " " + row['Telephone2'] + " " + row['Fax'] newcust.save() return HttpResponseRedirect(reverse("customers:detail", kwargs={"pk": newcust.id}))
def import_add(request): from magonet.connector import MagoNet conn = MagoNet() conn.connect() rows = conn.getcustomer_byid(str(request.GET['code'])) conn.disconnect() row = rows[0] cust_list = Customer.objects.filter(origin_code=row['CustSupp']) if cust_list: newcust = cust_list[0] else: newcust = Customer() newcust.address = row['Address'] newcust.city = row['City'] newcust.email = row['EMail'] newcust.name = row['CompanyName'] newcust.origin_code = row['CustSupp'] newcust.telephone = row['Telephone1'] + " " + row[ 'Telephone2'] + " " + row['Fax'] newcust.save() return HttpResponseRedirect( reverse("customers:detail", kwargs={"pk": newcust.id}))
from customers.models import Customer, WorkSite import random CUSTOMER_NAMES = [ "abc", "pippo", "pluto", "paperino", "paperone", "consulting", "dollar", "information", "fast", "good" ] CUSTOMER_NAMES_TITLE = ["Srl", "Snc", "Sas", "Spa"] for x in range(25): newcust = Customer() newcust.name = CUSTOMER_NAMES[random.randint(0, len(CUSTOMER_NAMES) - 1)].title() + ' ' + \ CUSTOMER_NAMES[random.randint(0, len(CUSTOMER_NAMES) - 1)] + ' ' + \ CUSTOMER_NAMES_TITLE[random.randint(0, len(CUSTOMER_NAMES_TITLE) - 1)] newcust.address = 'via {0}'.format(CUSTOMER_NAMES[random.randint( 0, len(CUSTOMER_NAMES) - 1)]) newcust.city = "City" newcust.email = "*****@*****.**" newcust.reference_person = CUSTOMER_NAMES[random.randint( 0, len(CUSTOMER_NAMES) - 1)] newcust.origin_code = "sample" newcust.telephone = "008881123456" newcust.save() for sx in range(3): newws = WorkSite(customer=newcust) newws.name = "Branch {0} {1}".format(str(sx), newcust.name) newws.address = "via {0}".format(CUSTOMER_NAMES[random.randint( 0, len(CUSTOMER_NAMES) - 1)])