def business_add(request): bf = BusinessForm() if request.method == 'POST': bf = BusinessForm(request.POST) if bf.is_valid(): bf_data = bf.save() return HttpResponseRedirect('/allow/welcome/') return render(request, 'business/business_add.html', locals())
def addbusiness(): form = BusinessForm() if request.method == "GET": return render_template('addbusiness.html', form=form, session=session) if request.method == "POST": if form.validate() == True: cursor = mysql.connection.cursor() query = "INSERT INTO customer (customer_id, phone_number, email, street, city, state, postal_code) VALUES (NULL, %s, %s, %s, %s, %s, %s)" variables = [form.phone_number.data, form.email.data, form.street.data, form.city.data, form.state.data, form.postal_code.data] cursor.execute(query, variables) mysql.connection.commit() cursor = mysql.connection.cursor() # cursor.execute("SELECT max(customer_id) from customer") cursor.execute("SELECT LAST_INSERT_ID()") last_customer_id = cursor.fetchall() query = "INSERT INTO business (tax_id_number, customer_id, business_name, pc_name, pc_title) VALUES (%s, %s, %s, %s, %s)" variables = [form.tax_id_number.data, last_customer_id, form.business_name.data, form.pc_name.data, form.pc_title.data] cursor.execute(query, variables) mysql.connection.commit() if session["previous_page"] == "purchase": session["customer"] = { "customer_id": last_customer_id, "customer_type": "Business", "customer_name": "{}".format(form.business_name.data) } return redirect(url_for("purchasevehicle")) else: session["customer"] = { "customer_id": last_customer_id, "customer_type": "Business", "customer_name": "{}".format(form.business_name.data) } return redirect(url_for("sellvehicle", vin=session["vin"])) else: return render_template('addbusiness.html', form=form)
def business_add(request): bf = BusinessForm() if request.method == 'POST': bf = BusinessForm(request.POST) nic_name = request.POST.get('nic_name') if Business.objects.filter(nic_name=nic_name): return HttpResponseRedirect('/allow/welcome/') if bf.is_valid(): bf_data = bf.save() bf_data.full_name = bf_data.name bf_data.status = '0' bf_data.save() siteid = bf_data.nic_name if "new" in siteid: siteid = siteid.replace("new", "") #需要创建测试环境和灰度环境的域名,傻啊,都不分现金网和蛮牛吗? if bf_data.platform == "现金网": test_f = DomainName(name=siteid + ".test.s1118.com", use=0, business=bf_data, classify="test", state=0, supplier="工程") test_f.save() huidu_f = DomainName(name=siteid + ".s1119.com", use=0, business=bf_data, classify="huidu", state=0, supplier="运维") huidu_a = DomainName(name="ag" + siteid + ".s1119.com", use=1, business=bf_data, classify="huidu", state=0, supplier="运维") huidu_a.save() huidu_f.save() elif bf_data.platform == "VUE蛮牛": huidu_f = DomainName(name=siteid.replace("vue", "") + ".kg-8.me", use=0, business=bf_data, classify="huidu", state=0, supplier="工程") huidu_a = DomainName(name="ag" + siteid + ".kg-8.me", use=1, business=bf_data, classify="huidu", state=0, supplier="工程") huidu_a.save() huidu_f.save() return HttpResponseRedirect('/business/business_list/') return render(request, 'business/business_add.html', locals())
def business_edit(request, uuid): business = get_object_or_404(Business, uuid=uuid) status = business.status bf = BusinessForm(instance=business) if request.method == 'POST': bf = BusinessForm(request.POST, instance=business) new_status = request.POST.get('status', '') if bf.is_valid(): status_change_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) bf_data = bf.save(commit=False) if status == new_status: bf_data.save() else: bf_data.status_update_date = status_change_time bf_data.save() return HttpResponseRedirect('/allow/welcome/') return render(request, 'business/business_edit.html', locals())
def addbusiness(): form = BusinessForm(request.form) if request.method == 'POST': title = form.title.data bDescription = form.textarea.data created_by = session['username'] #create cursor cur = mysql.connection.cursor() #execute querry cur.execute( 'INSERT INTO businesses(title, owner, body) VALUES(%s, %s, %s)', (title, created_by, bDescription)) #commit mysql.connection.commit() #close connection cur.close() flash('Your business has been registered, thank you!', 'success') return redirect(url_for('businesses')) else: return render_template('/forms/add_business.html', form=form)