Beispiel #1
0
def rig(request):
    components = sql_script.get_rig(str(request.user))
    total_price = 0
    for i in components:
        total_price += float(i['Price'])

    dic = {'components': components, 'total': total_price}
    dic.update(user_info(request))
    return render(request, 'user/rig.html', dic)
Beispiel #2
0
def cart(request):
    components = sql_script.get_cart(str(request.user))
    total_price = 0
    for i in components:
        total_price += float(i['Price']) * int(i['in_qty'])
    #print(components[1]['Name'])

    dic = {'components': components, 'total': total_price}
    dic.update(user_info(request))
    return render(request, 'user/cart.html', dic)
Beispiel #3
0
def change(request,Type,Rig,Inven):
    #return HttpResponse(request.POST['rig']+'  '+request.POST['action'].split('|')[0]+ "        " + request.POST['action'].split('|')[1])
    if request.method == 'POST':
        sql_script.add(request)
        return redirect('/rig/home')
    else:
        sql_script.remove(Rig,Inven)
        dic = {'rig_msg':Type+' is removed from Rig Chose another '+ Type}
        dic['products'] = sql_script.show(request,Type)
        dic.update(user_info(request))
        return render(request,'rig/rig_inven.html',dic)
Beispiel #4
0
def index(request):
    if request.method == "POST":
        print(request.POST['action'])
        if request.POST['action'].split("|")[0]=='add':
            return redirect('/rig/%s/add' %(request.POST['action'].split("|")[1]))
        elif request.POST['action'].split("|")[0]=='change':
            return redirect('/rig/%s/%s/%s/change' %(request.POST['action'].split("|")[2],request.POST['rig'],request.POST['action'].split("|")[1]))
        else:
            return remove(request.POST['rig'],request.POST['action'].split('|')[1])
    else:
        dic = sql_script.get_rig(request)
        dic.update(user_info(request))
        return render(request,'rig/rig.html',context=dic)
Beispiel #5
0
def add(request,Type=None):
    if not sql_script.check(request,Type):
         return HttpResponse(Type+" is already in your Rig.")

    if request.method == 'POST':
        sql_script.add(request)
        return redirect('/rig/home')
    
    else:
        dic = {}
        dic['products'] = sql_script.show(request,Type)
        dic.update(user_info(request))
        return render(request,'rig/rig_inven.html',dic)
Beispiel #6
0
def comp(request, comp):
    companies = sql_script.distinct_companies(comp)
    companies_chosen = {}

    for c in companies:
        companies_chosen[c] = False
    if request.method == 'POST':
        companies_required = []
        for i in companies:
            if request.POST.get(i) == 'on':
                companies_required.append(i)
                companies_chosen[i] = True
        desc = sql_script.intro(comp, companies=companies_required)
    else:
        desc = sql_script.intro(comp)
    dic = {'companies': companies, 'components': desc}
    dic.update(companies_chosen)
    dic.update(user_info(request))
    print(dic)
    return render(request, 'products/products.html', dic)
Beispiel #7
0
def item(request, comp, product):
    dic = sql_script.sel_item(product)
    print(dic)
    seller = sql_script.get_seller(dic['id'])
    dic.update({'seller': seller})
    print(seller)
    msg = ''
    dic.update(user_info(request))
    if request.method == 'POST':
        if not request.user.is_authenticated:
            return redirect('/user/login')
        else:
            if 'add' in request.POST:
                if request.POST['add'] == 'cart':
                    msg = sql_script.add_to_cart(str(request.user),
                                                 request.POST['seller'],
                                                 request.POST['qty'])
                    if msg == "Inserted to cart":
                        return redirect('/user/cart')
                # elif request.POST['add'] == 'rig':
                #     sql_script.add_to_rig(str(request.user),request.POST['seller'])
    dic.update({'msg': msg})
    return render(request, 'products/item.html', dic)
Beispiel #8
0
def index(request):
    dic = {}
    dic.update(user_info(request))
    return render(request, 'products/main.html', dic)