Beispiel #1
0
def remove_item_from_bid(request):
    if request.method == 'POST':
        item_id = request.POST.get('item_id')
        f = open('loggedin.txt', 'r')
        email = f.readline()
        i = BidItems.objects.filter(seller_email=email)
        try:
            b = BidItems.objects.get(item_id=item_id)
            b.delete()
            try:
                bi = Bidding.objects.get(item_id=item_id)
                bi.delete()
            except Bidding.DoesNotExist:
                pass
            i = BidItems.objects.filter(seller_email=email)
            notification = "You removed item " + str(item_id) + " from bid"
            to = email
            ns.send_notification(notification, to)
            return render(request, 'Bidding/remove_item_from_bid.html', {'message': 'Item removed', 'items': i})
        except BidItems.DoesNotExist:
            return render(request, 'Bidding/remove_item_from_bid.html',
                          {'message': 'Kindly enter a valid item ID', 'items': i})
    else:
        f = open('loggedin.txt', 'r')
        email = f.readline()
        i = BidItems.objects.filter(seller_email=email)
        return render(request, 'Bidding/remove_item_from_bid.html', {'items': i})
Beispiel #2
0
def put_on_rent_staff(request):
    if request.method == "POST":
        item_name = request.POST.get("item_name")
        item_ab = request.POST.get("item_ab")
        item_desc = request.POST.get("item_desc")
        item_photo = request.FILES["Item_photo"]
        item_type = request.POST.get("item_type")
        rent_id = 100000
        while True:
            rent_id = random.randint(100000, 999999)
            try:
                i = RentItems.objects.get(rent_id=rent_id)
            except RentItems.DoesNotExist:
                break
        fs = FileSystemStorage()
        filename = fs.save(item_photo.name, item_photo)
        i = RentItems(rent_id=rent_id, item_name=item_name, item_type=item_type,
                      item_description=item_desc, item_photo=item_photo, item_ab=item_ab)
        i.save()
        f = open('loggedin.txt', 'r')
        email = f.readline()
        notification = "You put item" + item_name + " on rent"
        to = email
        ns.send_notification(notification, to)
        return render(request, 'renting/rent_options_staff.html', {'message': 'The item has been successfully uploaded!'})
    else:
        return render(request, 'renting/put_on_rent_form.html')
Beispiel #3
0
def place_item_on_bid(request):
    if request.method == "POST":
        item_name = request.POST.get("item_name")
        item_price = request.POST.get("item_price")
        item_desc = request.POST.get("item_desc")
        item_image = request.POST.get("item_pic")
        item_id = 100000
        f = open('loggedin.txt', 'r')
        email = f.readline()
        while True:
            item_id = random.randint(100000, 999999)
            try:
                i = BidItems.objects.get(item_id=item_id)
            except BidItems.DoesNotExist:
                break

        i = BidItems(item_id=item_id, threshold_value=item_price,
                     item_description=item_desc, item_photo=item_image,
                     seller_email=email, item_name=item_name,
                     item_place_date=date.today().strftime("%Y-%m-%d"))
        i.save()
        notification = "You placed item " + str(item_name) + " on bid"
        to = email
        ns.send_notification(notification, to)
        return render(request, 'Bidding/bid_options.html', {'message': 'The item has been successfully uploaded!'})
    else:
        return render(request, 'Bidding/place_on_bid.html')
Beispiel #4
0
def delete_confirm(request):
    global q
    if request.method == 'POST':
        a = q.Item_title
        q.delete()
        f = open('loggedin.txt', 'r')
        email1 = f.readline()
        notification = "You deleted item " + a
        to = email1
        ns.send_notification(notification, to)
        return render(request, 'Check_stock/item_delete.html',
                      {'message': 'Item deletion successful'})
    else:
        return render(request, 'Check_stock/item_delete.html')
Beispiel #5
0
def generate_invoice(request):
    global cart_total
    f = open('loggedin.txt', 'r')
    email = f.readline()
    c = Cart.objects.filter(email_id=email)
    oid = random.randint(100, 999)
    o = []
    f = []
    for item in c:
        o.append(
            Order(Item_id=item.Item_id,
                  Item_title=item.Item_title,
                  Item_price=item.Item_price,
                  Item_quantity=item.Item_quantity,
                  email_id=email,
                  Order_id=oid,
                  Order_date=date.today().strftime("%Y-%m-%d"),
                  Order_time=datetime.now().strftime('%H:%M')))
        x = Items.objects.get(Item_id=item.Item_id)
        x.Item_quantity -= 1
        f.append(x)
        if x.Item_quantity < 0:
            msg = 'Sorry, item ' + x.Item_title + " doesn't have demanded quantity!"
            return render(request, 'buy_student/display_orders.html',
                          {'message': msg})
    for item in o:
        item.save()
    for item in f:
        item.save()
    c.delete()
    c = Order.objects.filter(email_id=email)

    z = Items.objects.all()
    for item in z:
        if item.Item_quantity == 0:
            notification = "Item " + str(
                item.Item_id) + " has gone out of stock"
            for e in Users.objects.filter(type_user='******'):
                ns.send_notification(notification, e.email_id)
            item.delete()
    ig.generate(oid, cart_total, o)
    notification = "You placed an order worth Rs. " + str(
        cart_total) + ". Check in previous orders for more details"
    to = email
    ns.send_notification(notification, to)
    return render(request, 'buy_student/display_orders.html', {
        'items': c[::-1],
        'message': 'Order has been successfully placed'
    })
Beispiel #6
0
def take_return(request):
    if request.method == "POST":
        rentid = request.POST.get('rent_id')
        try:
            r = RentItems.objects.get(rent_id=rentid)
            rdate = r.rent_date
            r.rent_date = datetime.today() + timedelta(150)
            email = r.renter_email
            r.renter_email = ""
            r.rent_var = False
            r.save()
            rent_id = 100000
            while True:
                rent_id = random.randint(100000, 999999)
                try:
                    i = RentItems.objects.get(rent_id=rent_id)
                except RentItems.DoesNotExist:
                    break
            f = OldRentedItems(rent_id=rent_id, renter_email=email, item_name=r.item_name,
                               item_photo=r.item_photo, rent_date=rdate)
            f.save()
            f = open('loggedin.txt', 'r')
            email1 = f.readline()
            notification = "Return taken from " + email + "of item " + r.item_name
            to = email1
            ns.send_notification(notification, to)
            notification = "You returned item " + r.item_name + " to " + email1
            to = email
            ns.send_notification(notification, to)
            return render(request, 'renting/rent_options_staff.html', {'message': 'Item return taken successfully'})
        except RentItems.DoesNotExist:
            r = RentItems.objects.filter(rent_var=True)
            return render(request, 'renting/take_return.html', {'message': 'Kindly enter a valid id', 'items': r})
    else:
        r = RentItems.objects.filter(rent_var=True)
        if len(r):
            return render(request, 'renting/take_return.html', {'items': r})
        else:
            return render(request, 'renting/take_return.html', {'message': 'No one has rented an item yet'})
Beispiel #7
0
def sell(request):
    if request.method == "POST":
        item_name = request.POST.get("item_name")
        item_ab = request.POST.get("item_ab")
        item_price = request.POST.get("item_price")
        quantity = request.POST.get("qty")
        item_desc = request.POST.get("item_desc")
        Item_photo = request.FILES["Item_photo"]
        item_type = request.POST.get("item_type")
        item_id = 100000
        while True:
            item_id = random.randint(100000, 999999)
            try:
                i = Items.objects.get(Item_id=item_id)
            except Items.DoesNotExist:
                break
        fs = FileSystemStorage()
        filename = fs.save(Item_photo.name, Item_photo)
        i = Items(Item_id=item_id,
                  Item_title=item_name,
                  Item_ab=item_ab,
                  Item_price=item_price,
                  Item_quantity=quantity,
                  Item_description=item_desc,
                  Item_photo=Item_photo,
                  Item_type=item_type)
        i.save()
        f = open('loggedin.txt', 'r')
        email1 = f.readline()
        notification = "You put item " + item_name + " on sale"
        to = email1
        ns.send_notification(notification, to)
        return render(request, 'welcome/homepage_staff.html',
                      {'message': 'The item has been successfully uploaded!'})
    else:
        return render(request, 'sell_staff/sell_form.html')
Beispiel #8
0
def make_a_bid(request):
    if request.method == 'POST':
        f = open('loggedin.txt', 'r')
        email = f.readline()
        item_id = request.POST.get('item_id')
        bid_val = request.POST.get('bid_val')
        try:
            i = BidItems.objects.get(item_id=item_id)
        except BidItems.DoesNotExist:
            return render(request, 'Bidding/make_a_bid.html', {'message': 'Kindly enter a valid item id'})
        try:
            i = Bidding.objects.get(item_id=item_id)
            if float(bid_val) <= i.curr_bid_value:
                bi = BidItems.objects.exclude(seller_email=email)
                bid = Bidding.objects.exclude(seller_email=email)
                if len(bid) == 1:
                    return render(request, 'Bidding/make_a_bid.html',
                                  {'message': 'Kindly enter a bid value greater than ' + str(i.curr_bid_value),
                                   'items': bid})
                return render(request, 'Bidding/make_a_bid.html',
                              {'message': 'Kindly enter a bid value greater than ' + str(i.curr_bid_value), 'items': bi})
            bid = BidItems.objects.get(item_id=item_id)
            b = Bidding(buyer_email=email, curr_bid_value=bid_val,
                        prev_bid_value=i.curr_bid_value, item_id=item_id,
                        threshold_value=bid.threshold_value, seller_email=bid.seller_email,
                        item_name=bid.item_name, prev_buyer_email=i.buyer_email,
                        old_bid_date=i.new_bid_date, new_bid_date=date.today().strftime("%Y-%m-%d"))
            b.save()
            notification = "You placed bid on " + str(bid.item_name) + " of Rs. " + str(bid_val)
            to = email
            ns.send_notification(notification, to)
            notification = "Bid was placed on " + str(i.item_name) + " of Rs. " + str(bid_val) + "by " + str(email)
            to = i.seller_email
            ns.send_notification(notification, to)
            notification = "Your bid on " + str(i.item_name) + " was exceeded by " + str(email)
            to = i.buyer_email
            ns.send_notification(notification, to)
            return render(request, 'Bidding/bid_options.html', {'message': 'Your bid has been placed!'})
        except Bidding.DoesNotExist:
            i = BidItems.objects.get(item_id=item_id)
            if float(bid_val) <= i.threshold_value:
                bi = BidItems.objects.exclude(seller_email=email)
                return render(request, 'Bidding/make_a_bid.html',
                              {'message': 'Kindly enter a bid value greater than ' + str(i.threshold_value), 'items1': bi})
            b = Bidding(item_id=item_id, seller_email=i.seller_email,
                        buyer_email=email, curr_bid_value=bid_val,
                        prev_bid_value=i.threshold_value, threshold_value=i.threshold_value,
                        prev_buyer_email=email, item_name=i.item_name, item_place_date=i.item_place_date,
                        new_bid_date=date.today().strftime('%Y-%m-%d'))
            b.save()
            notification = "You placed bid on " + str(i.item_name) + " of Rs. " + str(bid_val)
            to = email
            ns.send_notification(notification, to)
            notification = "Bid was placed on " + str(i.item_name) + " of Rs. " + str(bid_val) + " by " + str(email)
            to = i.seller_email
            ns.send_notification(notification, to)
            return render(request, 'Bidding/bid_options.html', {'message': 'Your bid has been placed!'})
    else:
        f = open('loggedin.txt', 'r')
        email = f.readline()
        i = BidItems.objects.exclude(seller_email=email)
        bi = Bidding.objects.exclude(seller_email=email)
        if len(bi) != 0:
            return render(request, 'Bidding/make_a_bid.html', {'items': bi, 'items1': i})
        return render(request, 'Bidding/make_a_bid.html', {'items1': i})