コード例 #1
0
ファイル: views.py プロジェクト: Orekhov/DB_project
def adddelpoint(request):
    if request.method == 'POST':
        form = AddDelpointForm(request.POST)
        if form.is_valid():
            # getting data from forms
            cd = form.cleaned_data
            del_address= cd['del_address']
            zone       = cd['zone']
            floor      = cd['floor']
            elevator   = int(cd['elevator'])
            entrance   = cd['entrance']
            code       = cd['code']
            if elevator ==2:
                elevator="False"
            elif elevator==1:
                elevator="True" 
            
            # calculating order_amount and order_total
            query="INSERT INTO delpoints (del_address,zone,floor,elevator,entrance,code) "
            query+=" VALUES ('"+del_address+"','"+zone+"','"+floor+"',"+elevator+",'"+entrance+"','"+code+"');"
            if util.simpleSqlCheck(query):
                util.execute_sql(query)
            else:
                return HttpResponseBadRequest(content='<b>Error 400</b><br><br>Bad Request')
            return HttpResponseRedirect('thanks')
        return render_to_response('adddelpoint.html',locals())
    else:
        form = AddDelpointForm()
        return render_to_response('adddelpoint.html',locals())
コード例 #2
0
ファイル: views.py プロジェクト: Orekhov/DB_project
def delivorderdirectly(request):
    if 'order_to_deliver' in request.POST:
        otd=request.POST['order_to_deliver']
        otd=str(otd).strip()
        query =" UPDATE delivery_diagrams SET status=True, fact_date=CURRENT_TIMESTAMP "
        query+=" WHERE diagram_id=(SELECT diagram_id FROM orders WHERE order_id="+otd+");"
        if util.simpleSqlCheck(query):
            util.execute_sql(query)
            return HttpResponse('заказ '+otd+' доставлен')
    return HttpResponse('Не доставлено')
コード例 #3
0
ファイル: views.py プロジェクト: Orekhov/DB_project
def addoutput(request):
    if request.method == 'POST':
        form = AddOutputForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            output_name  = cd['output_name']
            output_price = str(cd['output_price'])
            query =" INSERT INTO outputs (output_name,output_price) "
            query+=" VALUES ('"+output_name+"',"+output_price+");"
            if util.simpleSqlCheck(query):
                util.execute_sql(query)
            else:
                return HttpResponseBadRequest(content='<b>Error 400</b><br><br>Bad Request')
            return HttpResponseRedirect('thanks')
        return render_to_response('addoutput.html',locals())
    else:
        form = AddOutputForm()
        return render_to_response('addoutput.html',locals())
コード例 #4
0
ファイル: views.py プロジェクト: Orekhov/DB_project
def delivorder(request):
    if request.method == 'POST':
        form = DelivOrderForm(request.POST)
        form.updateNonStaticForm()
        if form.is_valid():
            cd = form.cleaned_data
            delivering_order  = str(cd['delivering_order'])
            query =" UPDATE delivery_diagrams SET status=True, fact_date=CURRENT_TIMESTAMP "
            query+=" WHERE diagram_id=(SELECT diagram_id FROM orders WHERE order_id="+delivering_order+");"
            if util.simpleSqlCheck(query):
                util.execute_sql(query)
            else:
                return HttpResponseBadRequest(content='<b>Error 400</b><br><br>Bad Request')
            return HttpResponseRedirect('thanks')
        return render_to_response('delivorder.html',locals())
    else:
        form = DelivOrderForm()
        form.updateNonStaticForm()
        return render_to_response('delivorder.html',locals())
コード例 #5
0
ファイル: views.py プロジェクト: Orekhov/DB_project
def addcustomer(request):
    if request.method == 'POST':
        form = AddCustomerForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            name    = cd['name']
            address = cd['address']
            phone   = cd['phone']
            fax     = cd['fax']
            email   = cd['email']
            type    = int(cd['type'])
            if type ==2:
                bank    = cd['bank']
                account = str(cd['account'])
                bik     = str(cd['bik'])
                inn     = str(cd['inn'])
                okonh   = str(cd['okonh'])
                okpo    = str(cd['okpo'])
                type="False"
            elif type==1:
                type="True"
                
            query="INSERT INTO customers (name,address,phone,fax,email,type) "
            query+=" VALUES ('"+name+"','"+address+"','"+phone+"','"+fax+"','"+email+"',"+type+");"
            if util.simpleSqlCheck(query):
                util.execute_sql(query)
            else:
                return HttpResponseBadRequest(content='<b>Error 400</b><br><br>Bad Request')
            if type=="False":
                dat=util.fetchone_from_sql("SELECT max(customer_id) FROM customers;")
                new_customer_id=dat[0]
                query2 ="INSERT INTO customers_lp (customer_id,bank,account,bik,inn,okonh,okpo) "
                query2+=" VALUES ("+str(new_customer_id)+",'"+bank+"',"+account+","+bik+","+inn+","+okonh+","+okpo+");"
                if util.simpleSqlCheck(query2):
                    util.execute_sql(query2)
                else:
                    return HttpResponseBadRequest(content='<b>Error 400</b><br><br>Bad Request')
            return HttpResponseRedirect('thanks')
        return render_to_response('addcustomer.html',locals())
    else:
        form = AddCustomerForm()
        return render_to_response('addcustomer.html',locals())
コード例 #6
0
ファイル: views.py プロジェクト: Orekhov/DB_project
def addorder(request):
    if request.method == 'POST':
        form = AddOrderForm(request.POST)
        form.updateNonStaticFields()
        if form.is_valid():
            # getting data from forms
            cd = form.cleaned_data
            customer_id =str(cd['customer_id'])
            delpoint_id =str(cd['delpoint_id'])
            responsible =cd['responsible']
            vehicle =cd['vehicle']
            agent =cd['agent']
            plan_date =str(cd['plan_date'])
            output_id1 = str(cd['output_id1'])
            output_id1q = int(cd['output_id1q'])
            output_id1d = int(cd['output_id1d'])
    
            # calculating order_amount and order_total
            squery="SELECT output_price FROM outputs "
            squery+=" WHERE output_id="+output_id1+";"
            info=util.fetchone_from_sql(squery)
            order_amount=str(int(info[0])*output_id1q)
            order_total=str(int(order_amount)*(100-output_id1d)/100)
            
            # calculating current date
            info=util.fetchone_from_sql("SELECT CURRENT_DATE;")
            order_date=str(info[0])
            
            # inserting new delivery_diagram row
            query= " INSERT into delivery_diagrams (vehicle,agent,plan_date,status) "
            query+=" VALUES ('"+vehicle+"','"+agent+"','"+plan_date+"',False);" 
            if util.simpleSqlCheck(query):
                util.execute_sql(query)
            else:
                return HttpResponseBadRequest(content='<b>Error 400</b><br><br>Bad Request')
            
            # getting new diagram_id from delivery_diagrams
            dat=util.fetchone_from_sql("SELECT max(diagram_id) FROM delivery_diagrams;")
            diagram_id=str(dat[0])
            
            # inserting new order row
            query2="INSERT into orders(diagram_id,customer_id,delpoint_id,"
            query2+="responsible,order_date,order_amount,order_total) "
            query2+=" VALUES("+diagram_id+","+customer_id+","+delpoint_id
            query2+=",\'"+responsible+"\','"+order_date+"',"+order_amount+","+order_total+");"
            if util.simpleSqlCheck(query2):
                util.execute_sql(query2)
            else:
                return HttpResponseBadRequest(content='<b>Error 400</b><br><br>Bad Request')
            
            # getting new order_id from orders
            dat=util.fetchone_from_sql("SELECT max(order_id) FROM orders;")
            oid=dat[0]
            
            # inserting new order_output row
            discount=int(order_amount)-int(order_total)
            query3="INSERT into orders_outputs(order_id,output_id,quantity,discount) values"
            query3+=" ("+str(oid)+","+str(output_id1)+","+str(output_id1q)+","+str(discount)+");"
            if util.simpleSqlCheck(query3):
                util.execute_sql(query3)
            else:
                return HttpResponseBadRequest(content='<b>Error 400</b><br><br>Bad Request')
            return HttpResponseRedirect('thanks')
        return render_to_response('addorder.html',locals())
    else:
        form = AddOrderForm()
        form.updateNonStaticFields()
        return render_to_response('addorder.html',locals())