def post(self, request): form = AddCustomerForm(request.POST) if form.is_valid(): newcustomername = form.cleaned_data['New_Customer_Name'] newcustomernumber = form.cleaned_data['New_Customer_Number'] if SortedCustomerList.objects.filter( Sorted_Customer_Number=newcustomernumber).exists(): print 'Error. Previously entered Customer Number entered.' else: sortedcustomer = SortedCustomerList( Sorted_Customer_Name=newcustomername, Sorted_Customer_Number=newcustomernumber) sortedcustomer.save() form = AddCustomerForm() return render(request, self.template_name, {'form': form})
def add_customer(): form = AddCustomerForm(request.form) if form.validate() and request.method == 'POST': success = add_customer_controller(form) if success: flash("Added new customer to database.") return redirect(url_for('add_customer')) else: flash( "Failed to add new customer to database. Is the username unique?" ) return render_template('/customerreptasks/addcustomer.html', form=form) print("not implemented") else: form = AddCustomerForm() return render_template('/customerreptasks/addcustomer.html', form=form)
def get(self, request): form = AddCustomerForm() return render(request, self.template_name, { 'form': form, })
def customer(action): """ 用户列表 """ if action == 'add': form = AddCustomerForm() if form.validate_on_submit(): name = form.data['name'] sex = form.data['sex'] phone = form.data['phone'] email = form.data['email'] company = form.data['company'] addr = form.data['addr'] note = form.data['note'] tax_id = form.data['tax_id'] CustomerCtl.add(name, sex, phone, email, company, addr, note, tax_id, current_user.id) flash(u'添加成功', 'success') return redirect(url_for('Common.customer', action='list')) return render_template('customer_add.html', form=form) if action == 'edit': form = EditCustomerForm() if form.validate_on_submit(): uid = form.data['uid'] name = form.data['name'] sex = form.data['sex'] phone = form.data['phone'] email = form.data['email'] company = form.data['company'] addr = form.data['addr'] note = form.data['note'] tax_id = form.data['tax_id'] customer = CustomerCtl.update(uid, name, sex, phone, email, company, addr, note, tax_id, current_user.id) if customer: flash(u'编辑成功', 'success') else: flash(u'编辑失败', 'error') return redirect(url_for('Common.customer', action='list')) uid = request.args.get('uid', '0') customer = CustomerCtl.get_by_id(uid) if customer: form.uid.data = customer.id form.name.data = customer.name form.sex.data = customer.sex form.phone.data = customer.phone form.email.data = customer.email form.company.data = customer.company form.addr.data = customer.addr form.note.data = customer.note form.tax_id.data = customer.tax_id else: flash(u'找不到该客户', 'error') return redirect(url_for('Common.customer', action='list')) return render_template('customer_edit.html', form=form) if action == 'list': result = CustomerCtl.get_all() owner_dict = {} for i in result: try: owner_dict[i.owner] = AdminCtl.get(i.owner).name except: # 如果用户被删除,则AdminCtl.get可能引发异常 pass kwargs = { 'result': result, 'STATUS_LIST': settings.CUSTOMER_STATUS_DICT, 'owner_dict': owner_dict } return render_template("customer.html", **kwargs) return render_template("404.html")