예제 #1
0
def add_prod_size(request):
    try:
        vt = ProdType.objects.all()
        try:
            auth = au.authorize_user(request.session['Authenticated'],
                                     request.session['role_id'], 1)
        except:
            return redirect("/user/login")
        if auth == True:
            try:
                if request.method == "POST":
                    form = ProdSizeForm(request.POST)
                    f = form.save(commit=False)
                    f.size_name = request.POST['size_name']
                    f.type_id_id = request.POST['type_name']
                    f.save()
                    return render(request, "add_prod_size.html", {
                        'success': True,
                        'obj': vt
                    })
                else:
                    return render(request, "add_prod_size.html", {'obj': vt})
            except:
                return redirect("/manager/500")
        else:
            auth, message = auth
            if message == "Not Login":
                return redirect("/user/login")
            elif message == "Wrong Level":
                return render(request, "404.html", {'pass': True})
    except:
        return redirect("user/login")
예제 #2
0
def addto_cart(request):
    try:
        auth = au.authorize_user(request.session['Authenticated'],
                                 request.session['role_id'], 2)
    except:
        return redirect("/user/login")
    if auth == True:
        email = request.session['emailid']
        ud = UserDetail.objects.get(user_email=email)
        rn = random.randint(10000, 100000)
        invoice = ud.user_mobile[0:4] + str(rn)
        request.session['invoice'] = invoice
        request.session['token'] = str(random.randint(1000,
                                                      10000)) + str(invoice)
        data = TempProduct.objects.filter(user_email=email)
        total = TempProduct.objects.filter(user_email=email).aggregate(
            Sum('subtotal'))
        return render(request, "add_to_cart.html", {
            'prod': data,
            'total': total
        })
    else:
        auth, message = auth
        if message == "Not Login":
            return redirect("/user/login")
        elif message == "Wrong Level":
            return render(request, "404.html", {'pass': True})
예제 #3
0
def add_prod_category(request):
    try:
        auth = au.authorize_user(request.session['Authenticated'],
                                 request.session['role_id'], 1)
    except:
        return redirect("/user/login")
    if auth == True:
        try:
            if request.method == "POST":
                form = ProdCategoriesForm(request.POST)
                f = form.save(commit=False)
                f.cat_name = request.POST['cat_name']
                f.save()
                return render(request, "add_prod_category.html",
                              {'success': True})
            else:
                return render(request, "add_prod_category.html",
                              {'failed': True})
        except:
            return redirect("/manager/500")
    else:
        auth, message = auth
        if message == "Not Login":
            return redirect("/user/login")
        elif message == "Wrong Level":
            return render(request, "404.html", {'pass': True})
예제 #4
0
def manager_home(request):
    try:
        email = request.session['emailid']
        userdata = UserDetail.objects.get(user_email=email)
        try:
            auth = au.authorize_user(request.session['Authenticated'],
                                     request.session['role_id'], 1)
        except:
            return redirect("/user/login")
        if auth == True:
            request.session['name'] = userdata.user_fname
            request.session['image'] = userdata.user_image
            user = UserDetail.objects.filter(role_id_id=2).count()
            seller = UserDetail.objects.filter(role_id_id=3).count()
            prod = Product.objects.all().count()

            return render(request, "manager_dashboard.html", {
                'su': userdata,
                'user': user,
                'seller': seller,
                'prod': prod
            })
        else:
            auth, message = auth
            if message == "Not Login":
                return render(request, "login.html", {'pass': True})
            elif message == "Wrong Level":
                return render(request, "404.html", {'pass': True})
    except:
        return redirect("/user/login")
예제 #5
0
def page_nfound(request):
    try:
        auth = au.authorize_user(request.session['Authenticated'],
                                 request.session['role_id'], 1)
    except:
        return redirect("/user/login")
    if auth == True:
        return render(request, "404.html")
    else:
        auth, message = auth
        if message == "Not Login":
            return redirect("/user/login")
        elif message == "Wrong Level":
            return render(request, "404.html", {'pass': True})
예제 #6
0
def view_seller(request):
    try:
        auth = au.authorize_user(request.session['Authenticated'],
                                 request.session['role_id'], 1)
    except:
        return redirect("/user/login")
    if auth == True:
        vs = UserDetail.objects.filter(role_id_id=3)
        return render(request, "view_sellers.html", {'seller': vs})
    else:
        auth, message = auth
        if message == "Not Login":
            return redirect("/user/login")
        elif message == "Wrong Level":
            return render(request, "404.html", {'pass': True})
예제 #7
0
def view_size(request):
    try:
        auth = au.authorize_user(request.session['Authenticated'],
                                 request.session['role_id'], 1)
    except:
        return redirect("/user/login")
    if auth == True:
        vs = ProdSize.objects.all()
        return render(request, "view_size.html", {'vs': vs})
    else:
        auth, message = auth
        if message == "Not Login":
            return redirect("/user/login")
        elif message == "Wrong Level":
            return render(request, "404.html", {'pass': True})
예제 #8
0
def addtocart_user(request):
    try:
        auth = au.authorize_user(request.session['Authenticated'],
                                 request.session['role_id'], 2)
    except:
        return render(request, "login.html", {'pass': True})
    if auth == True:
        email = request.session['emailid']
        pid = request.session['prod_id']
        prod_data = Product.objects.get(prod_id=pid)
        prod_name = prod_data.prod_name
        prod_price = prod_data.prod_price
        prod_type = prod_data.type_id_id
        prod_cat = prod_data.cat_id_id
        prod_img = prod_data.prod_img1
        size = request.session['size']
        data = TempProduct.objects.filter(user_email=email, product_id=pid)

        if data:
            return redirect("/addtocart")
        else:
            temp = TempProductForm()
            t = temp.save(commit=False)
            t.product_id = pid
            t.user_email = email
            t.product_name = prod_name
            t.prod_price = prod_price
            t.prod_type = prod_type
            t.prod_size = size
            t.prod_cat = prod_cat
            t.prod_image = prod_img
            t.add_date = dt.datetime.now().date()
            t.prod_qty = 1
            t.subtotal = prod_price
            t.save()
            return redirect("/")
    else:
        auth, message = auth
        if message == "Not Login":
            return redirect("/user/login")
        elif message == "Wrong Level":
            return render(request, "404.html", {'pass': True})
예제 #9
0
파일: views.py 프로젝트: sanyam0626/Hoopla
def seller_home(request):
    try:
        email = request.session['emailid']
        userdata = UserDetail.objects.get(user_email=email)
        try:
            auth = au.authorize_user(request.session['Authenticated'],
                                     request.session['role_id'], 3)
        except:
            return redirect("/user/login")
        if auth == True:
            request.session['name'] = userdata.user_fname
            request.session['image'] = userdata.user_image
            return render(request, "seller_dashboard.html", {'su': userdata})
        else:
            auth, message = auth
            if message == "Not Login":
                return render(request, "login.html", {'pass': True})
            elif message == "Wrong Level":
                return render(request, "404.html", {'pass': True})
    except:
        return redirect("/user/login")
예제 #10
0
def checkout(request):
    try:
        auth = au.authorize_user(request.session['Authenticated'],
                                 request.session['role_id'], 2)
    except:
        return redirect("/user/login")
    if auth == True:
        email = request.session['emailid']
        ud = UserDetail.objects.get(user_email=email)
        invoice = request.session['invoice']
        total = request.GET['total']
        pay_token = PaymentToken.objects.all()
        exist = False
        for i in pay_token:
            if i.invoice == invoice:
                exist = True
                break
        if exist == False:
            form1 = PaymentTokenForm()
            f2 = form1.save(commit=False)
            f2.user_email = email
            f2.invoice = invoice
            f2.token = request.session['token']
            f2.save()

        host = request.get_host()
        paypal_dict = {
            'business':
            settings.PAYPAL_RECEIVER_EMAIL,
            'amount':
            total,
            'item_name':
            email,
            'invoice':
            invoice,
            'currency_code':
            'INR',
            'notify_url':
            'http://{}{}'.format(host, reverse('paypal-ipn')),
            'return_url':
            'http://{}{}?token={}'.format(host, reverse('payment_done'),
                                          request.session['token']),
        }

        form = PayPalPaymentsForm(initial=paypal_dict)

        if request.method == "POST":
            request.session['invoice'] = request.POST['invoice']
            request.session['total'] = request.POST['total']
            request.session['address'] = request.POST['address']
            request.session['landmark'] = request.POST['landmark']
            request.session['pin'] = request.POST['pin']
            request.session['mode'] = request.POST['payment_mode']
            if request.POST['payment_mode'] == "COD":
                return redirect("/cod")
            if request.POST['payment_mode'] == "PayPal":
                return render(request, "checkout.html", {
                    'ud': ud,
                    'total': total,
                    'invoice': invoice,
                    'form': form
                })
        return render(request, "checkout.html", {
            'ud': ud,
            'total': total,
            'invoice': invoice
        })
    else:
        auth, message = auth
        if message == "Not Login":
            return redirect("/user/login")
        elif message == "Wrong Level":
            return render(request, "404.html", {'pass': True})
예제 #11
0
def add_product(request):
    try:
        vt = ProdType.objects.all()
        vc = ProdCategories.objects.all()
        vb = ProdBrand.objects.all()
        vs = ProdSize.objects.all()
        try:
            auth = au.authorize_user(request.session['Authenticated'],
                                     request.session['role_id'], 1)
        except:
            return redirect("/user/login")
        if auth == True:
            try:
                if request.method == "POST":
                    prod_image = None
                    if request.FILES:
                        myfile = request.FILES['prod_img1']
                        fs = FileSystemStorage()
                        filename = fs.save(myfile.name, myfile)
                        fs.url(filename)
                        prod_image = myfile.name
                    form = ProductForm(request.POST)
                    if form.is_valid():
                        f1 = form.save(commit=False)
                        f1.prod_name = (request.POST['prod_name']).capitalize()
                        f1.prod_price = request.POST['prod_price']
                        f1.user_email_id = request.session['emailid']
                        f1.prod_description = request.POST['prod_desc']
                        f1.prod_qty = request.POST['prod_qty']
                        f1.prod_img1 = prod_image
                        f1.cat_id_id = request.POST['cat_name']
                        f1.type_id_id = request.POST['type_name']
                        f1.size_id_id = request.POST['size_name']
                        f1.brand_id_id = request.POST['brand_name']
                        f1.prod_creationdate = dt.datetime.now().date()
                        f1.save()
                        return render(
                            request, "add_product.html", {
                                'success': True,
                                'vt': vt,
                                'vc': vc,
                                'vb': vb,
                                'vs': vs
                            })
                    else:
                        return render(request, "add_product.html", {
                            'vt': vt,
                            'vc': vc,
                            'vb': vb,
                            'vs': vs
                        })
                return render(request, "add_product.html", {
                    'vt': vt,
                    'vc': vc,
                    'vb': vb,
                    'vs': vs
                })
            except:
                return redirect("/manager/500")
        else:
            auth, message = auth
            if message == "Not Login":
                return redirect("/user/login")
            elif message == "Wrong Level":
                return render(request, "404.html", {'pass': True})
    except:
        return redirect("user/login")