class totalPriceDeliveryPossible(View): def __init__(self): #Get model webshopRestaurant data for hd2900 restaurant for location id for this restaurant self.hd2900RestaurantObject = RestaurantUtils( restaurantName=restaurantName) self.deliveryStatus = self.hd2900RestaurantObject.isDeliveryOpenToday() def get(self, request, *args, **kwargs): context = dict() #Check if session is valid sessionValid = webshopUtils.checkSessionIdValidity( request=request, session_id_key=session_id_key, validPeriodInDays=self.hd2900RestaurantObject.restaurantModelData. session_valid_time) if sessionValid is False: context["pageRefresh"] = True return JsonResponse(context, status=200) #Check if all items still are available. This is to assure that the products are not sold out #Get all active products offered by the restaurant allActiveProducts = self.hd2900RestaurantObject.get_all_active_products( ) sessionItems = CartItem.objects.filter( cart_id=request.session[session_id_key]) number_of_products_ordered_beforeCheck = len(sessionItems) sessionItems = self.hd2900RestaurantObject.validateSessionOrderedProducts( allActiveProducts=allActiveProducts, sessionItems=sessionItems) if not sessionItems: context["pageRefresh"] = True return JsonResponse(context, status=200) number_of_products_ordered_afterCheck = len(sessionItems) if number_of_products_ordered_beforeCheck != number_of_products_ordered_afterCheck: context["pageRefresh"] = True return JsonResponse(context, status=200) #Get the total price context['totalPrice'] = webshopUtils.get_BasketTotalPrice( request.session[session_id_key]) #Provide the item total price for each item to be updated into the table context['ordered_product_items_list'] = list() for item in sessionItems: tmp = dict() tmp['productSlug'] = item.product.slug #tmp['productPrice'] = item.product.price #tmp['orderedQuantity'] = item.quantity tmp['totalPrice_for_ordered_item'] = item.product.price * item.quantity context['ordered_product_items_list'].append(tmp) #If both restaurant offers delivery today and the total price is above the limit, the signal for delivery button is sent back deliveryPossible = self.hd2900RestaurantObject.isDeliveryPossible() if deliveryPossible and context[ 'totalPrice'] >= self.hd2900RestaurantObject.restaurantModelData.minimum_order_total_for_delivery: context['deliveryButtonActive'] = True else: context['deliveryButtonActive'] = False context[ 'minimum_totalPrice_for_delivery'] = self.hd2900RestaurantObject.restaurantModelData.minimum_order_total_for_delivery return JsonResponse(context, status=200)
class TakeawayCheckout(View): def __init__(self): #Get model webshopRestaurant data for hd2900 restaurant for location id for this restaurant self.hd2900RestaurantObject = RestaurantUtils( restaurantName=restaurantName) self.deliveryStatus = self.hd2900RestaurantObject.isDeliveryOpenToday() def get(self, request, *args, **kwargs): #Check if session is still valid sessionValid = webshopUtils.checkSessionIdValidity( request=request, session_id_key=session_id_key, validPeriodInDays=self.hd2900RestaurantObject.restaurantModelData. session_valid_time) if sessionValid is False: #the session has expired and the user needs to start over return redirect('/hd2900_takeaway_webshop') #Check if delivery is still possible at this given date and time deliveryPossible = self.hd2900RestaurantObject.isDeliveryPossible() #Get all active products offered by the restaurant allActiveProducts = self.hd2900RestaurantObject.get_all_active_products( ) #Check if the shopping cart items are still offered by the restaurant sessionItems = CartItem.objects.filter( cart_id=request.session[session_id_key]) sessionItems = self.hd2900RestaurantObject.validateSessionOrderedProducts( allActiveProducts=allActiveProducts, sessionItems=sessionItems) #Check if total in sessionItems are above the limit for local delivery totalPrice = webshopUtils.get_BasketTotalPrice( request.session[session_id_key]) if totalPrice < self.hd2900RestaurantObject.restaurantModelData.minimum_order_total_for_delivery: deliveryButtonActive = False totalPriceDeliveryMessage = "Minimum order for takeaway delivery : " + str( self.hd2900RestaurantObject.restaurantModelData. minimum_order_total_for_delivery) + ' kr' else: deliveryButtonActive = True totalPriceDeliveryMessage = '' #Check delivery status context = { 'title': 'Hidden Dimsum takeaway checkout', 'checkoutProducts': sessionItems, 'totalPrice': totalPrice, 'deliveryPossible': deliveryPossible, #Relates to if it at all is possible to order delivery for today at the given time 'deliveryButtonActive': deliveryButtonActive, #checks if the total price is above the minimum limit for delivery 'totalPriceDeliveryMessage': totalPriceDeliveryMessage } return render( request, template_name= 'takeawayWebshop/takeawayWebshopPickupDeliveryCheckout.html', context=context)
class hd2900_webshop_Main(View): def __init__(self): #Get model webshopRestaurant data for hd2900 restaurant for location id for this restaurant self.hd2900RestaurantObject = RestaurantUtils( restaurantName=restaurantName) self.emailSignUp = newsLetterForm() def get(self, request, *args, **kwargs): #Inform visitor the delivery status today deliveryStatus = self.hd2900RestaurantObject.isDeliveryOpenToday() if deliveryStatus: takeawayStatusMsg = "We offer local delivery today" else: takeawayStatusMsg = "Order online and pickup at Hidden Dimsum 2900. Local delivery not available today" #Check if visitor has a cookie sessionValid = webshopUtils.checkSessionIdValidity( request=request, session_id_key=session_id_key, validPeriodInDays=self.hd2900RestaurantObject.restaurantModelData. session_valid_time) allActiveProducts = self.hd2900RestaurantObject.get_all_active_products( ) if sessionValid: sessionItems = CartItem.objects.filter( cart_id=request.session[session_id_key]) #Assure that the products in the session cart is still valid otherwise they should be removed. This #validation is made to assure that the products in the cart is still offered by the restaurant sessionItems = self.hd2900RestaurantObject.validateSessionOrderedProducts( allActiveProducts=allActiveProducts, sessionItems=sessionItems) #Merge sessionItems with all active products and add the quantity productToDisplay = self.hd2900RestaurantObject.generateProductsForView( allActiveProducts=allActiveProducts, sessionItems=sessionItems) totalItemsInBasket = webshopUtils.get_totalBasketItemQuantity( request.session[session_id_key]) else: productToDisplay = self.hd2900RestaurantObject.generateProductsForView( allActiveProducts=allActiveProducts, sessionItems=[]) totalItemsInBasket = 0 context = { 'title': restaurantName + ' online takeaway', 'deliveryStatus': deliveryStatus, 'deliveryStartTime': self.hd2900RestaurantObject.get_deliveryOpenTime().strftime( '%H:%M'), 'deliveryEndTime': self.hd2900RestaurantObject.get_deliveryEndtime().strftime( '%H:%M'), 'products': productToDisplay, 'totalItemsInBasket': totalItemsInBasket, 'deliveryRadius': self.hd2900RestaurantObject.restaurantModelData.delivery_radius, 'deliveryFee': self.hd2900RestaurantObject.restaurantModelData.delivery_fee, 'minimumOrderForDelivery': self.hd2900RestaurantObject.restaurantModelData. minimum_order_total_for_delivery, 'emailSignUpForm': self.emailSignUp, 'facebookLink ': 'https://www.facebook.com/pages/category/Dim-Sum-Restaurant/Hidden-Dimsum-2900-100653481855726/', 'instagramLink': 'https://www.instagram.com/hiddendimsum2900/', 'youtubeLink': 'https://www.youtube.com/channel/UC-ryuXvGrMK2WQHBDui2lxw', 'shopTitle': 'Hidden Dimsum 2900', 'addressStreet': 'Strandvejen 163, 2900 Hellerup', 'addressPhone': 'Phone : 40 38 88 84', 'addressCVR': 'CVR : 38908901' } return render(request, template_name="takeawayWebshop/takeawayWebshopMain.html", context=context)