def process_request(request): params = {} total_price = 0 shopping_cart0 = request.session['shopping_cart0'] shopping_cart1 = request.session['shopping_cart1'] for item in shopping_cart0: qty = shopping_cart0.get(item) product = hmod.Product.objects.get(id=item) total_price += product.current_price * qty for item in shopping_cart1: qty = shopping_cart1.get(item) product = hmod.Item.objects.get(id=item) total_price += product.standard_rental_price * qty if request.user.is_authenticated(): user = request.user form = CheckoutForm( initial={ 'total_cost': total_price, 'first_name': user.first_name, 'last_name': user.last_name, }) if request.method == 'POST': form = CheckoutForm(request.POST) if form.is_valid(): for item in shopping_cart1: product = hmod.Item.objects.get(id=item) print( '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>' ) print(product.name) # product1 = hmod.Item.objects.get(id=product) now = datetime.datetime.now() user = request.user userid = user.id userGuid = hmod.User.objects.get(id=userid) rental = hmod.Rental() rental.userid = userGuid rental.itemid = product rental.rental_time = now rental.due_date = now + datetime.timedelta(days=1, hours=3) rental.save() print('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>') # print(rental.userid) return HttpResponseRedirect('/inventory/shoppingcart.receipt/') pid = request.urlparams[0] qty = request.urlparams[1] params['form'] = form params['shopping_cart0'] = request.session['shopping_cart0'] params['shopping_cart1'] = request.session['shopping_cart1'] request.session.modified = True return templater.render_to_response(request, 'checkout.html', params)
def create(request): rental = hmod.Rental() rental.rental_time = '2000-01-01 00:00:01' rental.due_date = '2000-01-01 00:00:01' rental.discount_percent = 0.00 rental.save() return HttpResponseRedirect('/homepage/rentals.edit/{}/'.format(rental.id))
def create(request): rental = hmod.Rental() rental.rental_time = "2000-01-01" rental.discount_percent = '0.0' rental.Organization_id = hmod.Organization.objects.first().id rental.Person_id = hmod.Person.objects.first().id rental.Agent_id = hmod.Agent.objects.first().id rental.save() return HttpResponseRedirect('/homepage/rental.edit/{}/'.format(rental.id))
def create(request): if not request.user.is_authenticated(): return redirect('/homepage/login/?next=%s' % request.path) if not request.user.is_staff: return HttpResponseRedirect('/homepage/authentication') '''Creates a new rental''' rental = hmod.Rental() user = hmod.User() # rental.time = '' # rental.due_date = '' rental.disocunt_percent = '' rental.save() return HttpResponseRedirect('/homepage/rentals.edit/{}/'.format(rental.id))
def create(request): ''' create: Creates empty rental, sends user to edit page ''' params = {} # create rental object rental = hmod.Rental() # save new rental rental.save() # send user to rental page return HttpResponseRedirect('/manager/rentals.edit/{}/'.format(rental.id))
def create(request): params = {} form = ItemEditForm(initial={ 'name': '', 'description': '', 'value': '', 'standardRentalPrice': '', }) if request.method == 'POST': form = ItemEditForm(request.POST) if form.is_valid(): item = hmod.Rental() item.name = form.cleaned_data['name'] item.description = form.cleaned_data['description'] item.value = form.cleaned_data['value'] item.standardRentalPrice = form.cleaned_data['standardRentalPrice'] item.save() return HttpResponseRedirect('/homepage/items/') params['form'] = form return templater.render_to_response(request, 'items_edit.html', params)
def charge_card(request): ''' charge_card: charges card via REST API, ''' params = {} params['form'] = CheckoutForm() # should i do this in the clean method? When do i want to charge?? # send the request with the data API_URL = 'http://dithers.cs.byu.edu/iscore/api/v1/charges' API_KEY = 'aa846fb6f04d54c4b952561399e40d84' r = requests.post( API_URL, data={ 'apiKey': API_KEY, 'currency': 'usd', 'amount': get_total(request), # my total 'type': 'Visa', 'number': creditcard, 'exp_month': exp_month, 'exp_year': exp_year, 'cvc': cvc, 'name': 'Cosmo Limesandal', 'description': 'Charge for cosmo@[email protected]', }) # parse response dictionary resp = r.json() if 'error' in resp: print('ERROR: ', resp['error']) else: # if order, create order object if len(request.session['shopping_cart']) > 0: order = hmod.Order() order.order_date = datetime.date.today() order.total = get_total(request) user = hmod.User.objects.get(id=request.user.id) order.user = user order.charge_id = resp['ID'] order.save() # if rental, create rental objects for each rental if len(request.session['rental_cart']) > 0: rental_ids = request.session['rental_cart'] for rental_id in rental_ids: r = hmod.Item.objects.get(id=rental_id) rental = hmod.Rental() rental.description = r.name rental.rental_date = datetime.date.today() rental.due_date = (datetime.date.today() + datetime.timedelta(days=30)) rental.available = False rental.charge_id = resp['ID'] user = hmod.User.objects.get(id=request.user.id) rental.user = user rental.item = r rental.save() # redirect to receipt return HttpResponseRedirect('/shop/checkout.receipt') return templater.render_to_response(request, 'enter_payment.html', params)
'standard_rental_price': '3.00', 'is_rentable': 'TRUE', 'owner_id': '1' }, { 'amount_due': '28.15', 'name': 'Rental Item 2', 'description': 'Description 2', 'item_value': '5.00', 'standard_rental_price': '3.00', 'is_rentable': 'TRUE', 'owner_id': '1' }, ]: d = hmod.Rental() for k, v in data.items(): setattr(d, k, v) d.save() # populating data rental item for data in [ { 'condition': 'Like New', 'new_damage': 'True', 'damage_fee': '10.00', 'due_date': '2015-03-04', 'returned': 'TRUE' }, { 'condition': 'Fair',
'2015-03-12 12:00:00', '2015-03-22 12:00:00', 2.00, 15, hmod.Order.objects.get(id=1) ], [ '2015-03-25 12:00:00', '2015-04-22 12:00:00', 2.00, 15, hmod.Order.objects.get(id=3) ], [ '2015-01-25 12:00:00', '2015-01-27 12:00:00', 2.00, 15, hmod.Order.objects.get(id=4) ], [ '2014-12-25 12:00:00', '2014-12-27 12:00:00', 2.00, 15, hmod.Order.objects.get(id=5) ]]: rental = hmod.Rental() rental.rental_time = data[0] rental.due_date = data[1] rental.discount_percent = data[2] rental.total = data[3] rental.order = data[4] rental.save() #Create Return for data in [[ '2015-03-15 12:00:00', True, hmod.Agent.objects.get(id=3), hmod.Rental.objects.get(id=1) ]]: returns = hmod.Return() returns.return_time = data[0]
def process_request(request): template_vars = {} current_time = strftime("%Y-%m-%d %H:%M:%S", gmtime()) user = request.user #hmod.User.objects.get(id=request.urlparams[0]) form = OrderForm() prod_cart_objects = [] item_cart_objects = [] cart_products = request.session.get('shopping_cart') rent_total = 0 pur_total = 0 if not cart_products: pass else: for product in cart_products: qty = request.session['shopping_cart'][product] citem = hmod.Product.objects.get(id=product) print(citem) prod_cart_objects.append([citem.id, qty]) for item in prod_cart_objects: citem = hmod.Product.objects.get(id=item[0]) quant = item[1] pur_total = pur_total + (citem.current_price * quant) cart_items = request.session.get('shopping_cart_items') if not cart_items: pass else: for item in cart_items: qty = request.session['shopping_cart_items'][item] citem = hmod.Item.objects.get(id=item) print(citem) item_cart_objects.append([citem.id, qty]) for item in item_cart_objects: citem = hmod.Item.objects.get(id=item[0]) rent_total = rent_total + citem.standard_rental_price total = rent_total + pur_total print(prod_cart_objects) print(item_cart_objects) prod_cart_size = len(prod_cart_objects) item_cart_size = len(item_cart_objects) print(prod_cart_size) print(item_cart_size) if request.method == 'POST': form = OrderForm(request.POST) if form.is_valid(): print('Form data cleaned') print('Charge ID: ' + form.cleaned_data['charge']) address = hmod.Address() address.address_1 = form.cleaned_data['address_1'] address.address_2 = form.cleaned_data['address_2'] address.city = form.cleaned_data['city'] address.state = form.cleaned_data['state'] address.zip = form.cleaned_data['zip'] address.save() pur_total = 0 rent_total = 0 new_opo_id = 0 new_rent_id = 0 if not prod_cart_objects: pass else: opo = hmod.OnlinePurchaseOrder() opo.save() new_opo_id = opo.id for item in prod_cart_objects: citem = hmod.Product.objects.get(id=item[0]) quant = item[1] pur_total = pur_total + (citem.current_price * quant) opp = hmod.OnlinePurchaseProduct() opp.product_id = citem.id opp.onlinepurchaseorder = hmod.OnlinePurchaseOrder( id=opo.id) opp.quantity = quant opp.save() opo.total = pur_total opo.save() print( '########################################################################' ) if not item_cart_objects: pass else: rental = hmod.Rental() rental.rental_time = current_time mytime = datetime.strptime(current_time, "%Y-%m-%d %H:%M:%S") mytime += timedelta(hours=6) due_date = mytime.strftime("%Y-%m-%d %H:%M:%S") rental.due_date = due_date rental.save() print( '1111111111111111111111111111111111111111111111111111111111111' ) new_rent_id = rental.id for item in item_cart_objects: citem = hmod.Item.objects.get(id=item[0]) rent_total = rent_total + citem.standard_rental_price rentitem = hmod.RentalItem() rentitem.item_id_id = citem.id rentitem.rental_id_id = rental.id rentitem.returns = None rentitem.save() rental.total = rent_total rental.save() print( '########################################################################' ) total = rent_total + pur_total #print(customer) print( '1111111111111111111111111111111111111111111111111111111111111' ) order = hmod.Order() print('1') order.customer = hmod.User.objects.get(id=user.id) print('2') order.ships_to = hmod.Address.objects.get(id=address.id) print('3') #order.payment = form.cleaned_data['charge'] print('4') order.order_date = current_time print('5') order.save() if new_opo_id != 0: new_opo = hmod.OnlinePurchaseOrder.objects.get(id=new_opo_id) new_opo.order = order new_opo.save() if new_rent_id != 0: new_rental = hmod.Rental.objects.get(id=new_rent_id) new_rental.order = order new_rental.save() url = '/homepage/receipt/' + str(user.id) + '/' + str( order.id) + '/' + str(total) + '/' try: del request.session['shopping_cart'] except: pass try: del request.session['shopping_cart_items'] except: pass return HttpResponseRedirect(url) form = OrderForm( initial={ 'total': total, 'Card_Holder_Name': user.first_name + ' ' + user.last_name, }) template_vars['form'] = form template_vars['total'] = total return templater.render_to_response(request, 'checkout.html', template_vars)