Exemplo n.º 1
0
def prod_review(request, pid):
    ret_mail = "*****@*****.**"
    ret = retailer.objects(email=ret_mail).get()
    mail = request.session['username']
    farm = farmer.objects(email=mail).get()
    name = farm.l_name

    for i in ret.products:
        if i.product_id == pid:
            current = i

    if request.method == 'POST':
        title = request.POST.get('title')
        content = request.POST.get('content')
        rating = request.POST.get('rate')
        rating = int(rating)
        date = datetime.now()
        print(content, rating)
        comment = Comment(title=title,
                          content=content,
                          rating=rating,
                          name=name,
                          date=date)
        current.reviews.append(comment)
        print(current.reviews)
        if current.rating != None:
            current.rating = (current.rating + rating) / len(
                current.reviews) + 1
        else:
            current.rating = rating
        ret.save()
        return prod_page(request, pid)
    else:
        content = {'status': 2}
        return render(request, 'farmer/review_prod.html', content)
Exemplo n.º 2
0
def subtract(request, pid):
    mail = request.session['username']
    print(mail)
    ret = retailer.objects(email=mail).get()
    if request.method == 'POST':
        for i in ret.products:
            if i.product_id == pid:
                qty = request.POST.get('qty')
                cost = request.POST.get('cost')

                i.qty = i.qty - qty
                i.cost = cost
                ret.save()
                break
Exemplo n.º 3
0
def prod_profile(request):
    mail = request.session['username']
    ret = retailer.objects(email=mail).get()
    ilist = []
    for i in ret.products:
        lmg = i["photo"].grid_id
        col = db.images.chunks.find({"files_id": lmg})
        my_string = base64.b64encode(col[0]["data"])
        l = my_string.decode('utf-8')
        ilist.append(l)

    map = zip(ret.products, ilist)
    content = {'prods': ret.products, 'map': map, 'status': 1}
    return render(request, 'vendor/inv.html', content)
Exemplo n.º 4
0
def prod_page(request, pid):
    ret_mail = "*****@*****.**"
    ret = retailer.objects(email=ret_mail).get()

    for i in ret.products:
        if i.product_id == pid:
            prod = i
            lmg = i["photo"].grid_id
            col = db.images.chunks.find({"files_id": lmg})
            my_string = base64.b64encode(col[0]["data"])
            l = my_string.decode('utf-8')
            prod_image = l
            break
    print(prod.reviews)
    content = {'prod': prod, 'prod_image': prod_image, 'status': 2}
    return render(request, 'farmer/prod.html', content)
Exemplo n.º 5
0
def cat_page(request, cid):
    ret_mail = "*****@*****.**"
    ret = retailer.objects(email=ret_mail).get()
    prod = []
    prod_image = []
    for i in ret.products:
        if i.cat_id == cid:
            prod.append(i)
            lmg = i["photo"].grid_id
            col = db.images.chunks.find({"files_id": lmg})
            my_string = base64.b64encode(col[0]["data"])
            l = my_string.decode('utf-8')
            prod_image.append(l)
    map = zip(prod, prod_image)
    content = {'product': prod, 'map': map, 'status': 2, 'cid': cid}
    return render(request, 'farmer/cat.html', content)
Exemplo n.º 6
0
def add(request, pid):
    mail = request.session['username']
    ret = retailer.objects(email=mail).get()
    for i in ret.products:
        if i.product_id == pid:
            break

    if request.method == 'POST':
        cost = request.POST.get('cost')
        qty = request.POST.get('qty')
        cost = int(cost)
        qty = int(qty)
        i.stock = i.stock + qty
        i.cost = cost
        ret.save()

        return prod_profile(request)
    content = {'status': 1, 'prod': i}
    return render(request, 'vendor/add.html', content)
Exemplo n.º 7
0
def add_new(request):
    mail = request.session['username']
    ret = retailer.objects(email=mail).get()
    already = 0
    if request.method == 'POST':
        product_id = random.randint(0, 1000000)
        cat_id = request.POST.get('cat')
        name = request.POST.get('name')
        qty = request.POST.get('qty')
        img = request.FILES["img"]
        cost = request.POST.get('cost')
        desc = request.POST.get('desc')
        qty = int(qty)
        cost = int(cost)
        w = name[0]
        if w.isupper():
            pass
        else:
            w = w.upper()
        name = w + name[1:]

        pro = Product(product_id=product_id,
                      cat_id=cat_id,
                      name=name,
                      description=desc,
                      photo=img,
                      stock=qty,
                      cost=cost)
        #inv.photo.put(img, content_type = 'image/jpeg')
        #inv.save()
        ret.products.append(pro)
        ret.save()

        return prod_profile(request)
    content = {'status': 1}
    return render(request, 'vendor/add_new.html', content)