def index(request): debt_owner1= User.objects.get(username=str(request.user)) firstname = "" lastname = "" idNo = "" Address = "" HomeAddress = "" PhoneNumber = "" About = "" if request.method == 'GET': context={} return render(request, 'myapp/d-NewCus.html', context) elif request.method == 'POST': firstname = request.POST['txtFirstName'] lastname = request.POST['txtLastName'] idNo = request.POST['txtidNo'] Address = request.POST['txtAddress'] HomeAddress = request.POST['txtHomeAddress'] PhoneNumber = request.POST['txtPhoneNumber'] About = request.POST['txaAbout'] type = request.POST['typeSave'] try: #user = User() #user.username = firstname + lastname #user.first_name = firstname #user.last_name = lastname #user.set_password(idNo); #user.save() _customer = Customer() _customer.id_no = idNo _customer.first_name = firstname _customer.last_name = lastname _customer.full_name = firstname +' '+ lastname _customer.cus_code = lastname _customer.address = Address _customer.home_address = HomeAddress _customer.fone_number = PhoneNumber _customer.about = About _customer.status = 1 _customer.debt_owner = debt_owner1 if len(Customer.objects(debt_owner=debt_owner1,id_no=idNo,full_name=_customer.full_name))> 0: return getNewCusError(request,'Đã tồn tại thông tin khách hàng tương tư trong hệ thống',firstname,lastname,idNo,Address,HomeAddress,PhoneNumber,About) else: _customer.save() #user.backend = 'mongoengine.django.auth.MongoEngineBackend' except e: print(e) if type == "normalsave": return HttpResponseRedirect('/newcustomer') elif type == "saveandredirect": return HttpResponseRedirect('/custom-debit-detail?type=loan')
def createcustomer(user,id_no, address,home_address, fone_number, about): try: vtoday = date.today() ct = Customer() ct.cus_id= user ct.cus_code = user.username ct.first_name = user.first_name ct.last_name = user.last_name ct.full_name = user.first_name + user.last_name ct.id_no = id_no ct.address = address ct.home_address = home_address ct.fone_number = fone_number ct.create_date = vtoday ct.status = 1 ct.about = about ct.save() except Exception as ex: print(ex)
def index(request): if request.method == 'GET': context={} return render(request, 'myapp/d-NewCus.html', context) elif request.method == 'POST': firstname = request.POST['txtFirstName'] lastname = request.POST['txtLastName'] idNo = request.POST['txtidNo'] Address = request.POST['txtAddress'] HomeAddress = request.POST['txtHomeAddress'] PhoneNumber = request.POST['txtPhoneNumber'] About = request.POST['txaAbout'] try: user_name='student' debt_owner=User.objects.get(username=user_name) user = User() user.username = firstname + lastname user.first_name = firstname user.last_name = lastname user.set_password(idNo); user.save() _customer = Customer() _customer.cus_id = user _customer.id_no = idNo _customer.cus_code=firstname _customer.address = Address _customer.home_address = HomeAddress _customer.fone_number = PhoneNumber _customer.about = About _customer.status = 1 _customer.debt_owner = debt_owner _customer.save() user.backend = 'mongoengine.django.auth.MongoEngineBackend' context={"status":"success"} return render(request, 'myapp/d-mainScreen.html', context) except Exception as e: print(e)