def orderSicilian_view(request): size = request.POST["size"] topping1 = request.POST["topping1"] topping2 = request.POST["topping2"] topping3 = request.POST["topping3"] topping4 = request.POST["topping4"] topping5 = request.POST["topping5"] pizza = Pizza(type="Sicilian", topping1=topping1, topping2=topping2, topping3=topping3, topping4=topping4, topping5=topping5, size=size) pizza.save() return render(request, "orders/pizza.html")
def setUp(self): # create pizzas self.pizza_regular = Pizza(name='Margherita') self.pizza_regular.save() self.pizza_medium = Pizza(name='Cheese & Corn', size='medium', type='veg') self.pizza_medium.save() self.pizza_large = Pizza(name='Chicken delight', size='medium', type='non-veg') self.pizza_large.save() self.customer = Customer(customer_name='Madhuri', customer_address='Ecity Bangalore', customer_phone='9483917071') self.customer.save() self.delivered_order = Order.objects.create(ordered_by=self.customer, status='delivered') self.delivered_order.pizza_list.add(self.pizza_medium) self.delivered_order.save()
def setUp(self): self.customer_name = 'Test Name' self.customer_address = 'Test Address' self.customer = Customer(customer_name=self.customer_name, customer_address=self.customer_address) self.pizza_size = True self.pizza_flavor = 'Surprise' self.pizza = Pizza(pizza_size=self.pizza_size, pizza_flavor=self.pizza_flavor) self.order = Order(customer=self.customer, pizza=self.pizza)
def add_order(request): if request.POST.get('name') and request.POST.get('address') and request.POST.get('size')\ and request.POST.get('flavor'): # create customer customer_name = request.POST.get('name') customer_address = request.POST.get('address') customer = Customer(customer_name=customer_name, customer_address=customer_address) customer.save() # create pizza pizza_size = request.POST.get('size') pizza_flavor = request.POST.get('flavor') pizza = Pizza(pizza_size=pizza_size, pizza_flavor=pizza_flavor) pizza.save() # create order c = Customer.objects.latest('customer_id') p = Pizza.objects.latest('pizza_id') order = Order(pizza=p, customer=c) order.save() return render(request, 'orders/order_completed.html') return render(request, 'orders/place_order.html')
import os import csv from orders.models import Pizza f = open("../csv2/pizza.csv") reader = csv.reader(f) for st, top, si, pr in reader: t = Pizza(style=st, size=si, topping=top, price=pr) t.save()
# Sicilian Small (2,1) (2, 1, 0, Decimal("24.45")), (2, 1, 1, Decimal("26.45")), (2, 1, 2, Decimal("28.45")), (2, 1, 3, Decimal("29.45")), (2, 1, 5, Decimal("30.45")), # Sicilian Large (2,2) (2, 2, 0, Decimal("38.70")), (2, 2, 1, Decimal("40.70")), (2, 2, 2, Decimal("42.70")), (2, 2, 3, Decimal("44.70")), (2, 2, 5, Decimal("45.70")), ) for item in PIZZAS: f = Pizza(name=PizzaName.objects.get(pk=item[0]), size=Size.objects.get(pk=item[1]), toppings_count=item[2], price=item[3]) f.save() # SubName SUBNAMES = ( ("Cheese", "Cupidatat consectetur an offendit ut admodum eram sed pariatur consectetur." ), ("Italian", "Quae ubi excepteur ne quem, et ne summis proident."), ("Ham + Cheese", "Amet aut occaecat ut sunt aut e fugiat excepteur."), ("Meatball", "Fore ut iudicem ubi aute, quamquam a tamen laboris."), ("Tuna", "Ea summis fabulas occaecat ad magna commodo praesentibus."), ("Turkey", "Quo iis exquisitaque, fore id fabulas ut quorum."), ("Chicken Parmigiana", "Commodo ne anim hic in fore nisi hic fabulas."), ("Eggplant Parmigiana",
THREE_TOPPINGS = [] for i, top1 in enumerate(Pizza.TOPPING_CODES): for j, top2 in enumerate(Pizza.TOPPING_CODES): if j >= i: for k, top3 in enumerate(Pizza.TOPPING_CODES): if k >= j: THREE_TOPPINGS.append(top1 + top2 + top3) ALL_TOPS = [''] + Pizza.TOPPING_CODES + TWO_TOPPINGS + THREE_TOPPINGS for top in ALL_TOPS: for size in ['S', 'L']: for p_type in ['R', 'Si']: f = Pizza(pizza_type=p_type,pizza_top=top) f.size = size f.save() for size in ['S', 'L']: for p_type in ['R', 'Si']: f = Pizza(pizza_type=p_type,pizza_top='Spec') f.size = size f.save() ### Add everything to MenuItem for class0 in [Salad, Pasta, DinnerPlatter, Sub1, Sub2, Pizza]: for item in class0.objects.all(): f = MenuItem(name=item, price=item.price()) f.save()
def add_default_pizza(): ''' add default items in database ''' pizza = Pizza(name="Cheese", size=BaseItem.SMALL, price=12.70, crust=Pizza.REGULAR, max_toppings=0) pizza.save() pizza = Pizza(name="Cheese", size=BaseItem.LARGE, price=17.95, crust=Pizza.REGULAR, max_toppings=0) pizza.save() pizza = Pizza(name="1 topping", size=BaseItem.SMALL, price=13.70, crust=Pizza.REGULAR, max_toppings=1) pizza.save() pizza = Pizza(name="1 topping", size=BaseItem.LARGE, price=19.95, crust=Pizza.REGULAR, max_toppings=1) pizza.save() pizza = Pizza(name="2 topping", size=BaseItem.SMALL, price=15.20, crust=Pizza.REGULAR, max_toppings=2) pizza.save() pizza = Pizza(name="2 topping", size=BaseItem.LARGE, price=21.95, crust=Pizza.REGULAR, max_toppings=2) pizza.save() pizza = Pizza(name="3 topping", size=BaseItem.SMALL, price=16.20, crust=Pizza.REGULAR, max_toppings=3) pizza.save() pizza = Pizza(name="3 topping", size=BaseItem.LARGE, price=23.95, crust=Pizza.REGULAR, max_toppings=3) pizza.save() pizza = Pizza(name="Special", size=BaseItem.SMALL, price=17.75, crust=Pizza.REGULAR, max_toppings=5) pizza.save() pizza = Pizza(name="Special", size=BaseItem.LARGE, price=25.95, crust=Pizza.REGULAR, max_toppings=5) pizza.save() pizza = Pizza(name="Cheese", size=BaseItem.SMALL, price=24.45, crust=Pizza.SICILIAN, max_toppings=0) pizza.save() pizza = Pizza(name="Cheese", size=BaseItem.LARGE, price=38.70, crust=Pizza.SICILIAN, max_toppings=0) pizza.save() pizza = Pizza(name="1 topping", size=BaseItem.SMALL, price=26.45, crust=Pizza.SICILIAN, max_toppings=1) pizza.save() pizza = Pizza(name="1 topping", size=BaseItem.LARGE, price=40.70, crust=Pizza.SICILIAN, max_toppings=1) pizza.save() pizza = Pizza(name="2 topping", size=BaseItem.SMALL, price=28.45, crust=Pizza.SICILIAN, max_toppings=2) pizza.save() pizza = Pizza(name="2 topping", size=BaseItem.LARGE, price=42.70, crust=Pizza.SICILIAN, max_toppings=2) pizza.save() pizza = Pizza(name="3 topping", size=BaseItem.SMALL, price=29.45, crust=Pizza.SICILIAN, max_toppings=3) pizza.save() pizza = Pizza(name="3 topping", size=BaseItem.LARGE, price=44.70, crust=Pizza.SICILIAN, max_toppings=3) pizza.save() pizza = Pizza(name="Special", size=BaseItem.SMALL, price=30.45, crust=Pizza.SICILIAN, max_toppings=5) pizza.save() pizza = Pizza(name="Special", size=BaseItem.LARGE, price=45.70, crust=Pizza.SICILIAN, max_toppings=5) pizza.save()
import csv from orders.models import Pizza from orders.models import Topping f = open('data.txt', 'r') for line in f: line = line.split(',') product = Pizza() product.product = line[0] product.tipe = line[1] product.size = line[2] product.price = float(line[3]) #data is missing from file product.save() f.close() f = open('data1.txt', 'r') for line in f: line = line.split(',') print(line) product = Topping() product.product = line[0] product.tipo = line[1] product.save() f.close()
def test_string_representation(self): ''' test pizza's string representation ''' pizza = Pizza(name="Margherita") self.assertEqual(str("Margherita"), pizza.name)
def create_order(request): if not request.user.is_authenticated: return render(request, "login.html", {"message": None}) else: order_pending = Order.objects.filter(user=request.user).filter( status=ACTIVE).exists() context = { "user": request.user, "address": request.user.customer.address, "city": request.user.customer.city, "state": request.user.customer.state, "zip_code": request.user.customer.zip_code, "first": request.user.first_name, "last": request.user.last_name, "sizes": Pizza_Size.objects.all(), "toppings": Topping.objects.all(), "styles": Pizza_Style.objects.all(), "types": Pizza_Topping_Type.objects.all(), "order_pending": order_pending, "order": Order.objects.filter(user=request.user).filter( status=ACTIVE).first(), "logged_in": True } if request.method == 'POST': if 'Cancel' in request.POST: the_order = Order.objects.filter(user=request.user).filter( status=ACTIVE).first() the_order.delete() return render(request, "menu.html", context) elif 'Update' in request.POST: current_items = request.POST.getlist('lineitems') quantity_items = request.POST.getlist('quantity') the_order = Order.objects.filter(user=request.user).filter( status=ACTIVE).first() updated_order = Order(user=request.user, status='A') updated_order.save() for i in range(0, len(quantity_items)): pizza = the_order.contents.all()[i] pizza.quantity = quantity_items[i] pizza.save() the_order.total = total( Order.objects.filter(user=request.user).filter( status=ACTIVE).first().contents.all()) the_order.save() return render(request, "cart.html", context) elif 'Order' in request.POST: the_order = Order.objects.filter(user=request.user).filter( status=ACTIVE).first() the_order.status = SUBMITTED the_order.save() return render(request, "confirmation.html", context) else: p_size = Pizza_Size.objects.get(size=request.POST.get("size")) p_style = Pizza_Style.objects.get( style=request.POST.get("style")) p_number_of_toppings = Pizza_Topping_Type.objects.get( value=request.POST.get("number_of_toppings")) p_toppings = request.POST.getlist('toppings') p_quantity = request.POST.get("quantity") p_type = get_object_or_404(Pizza_Type, size=p_size, style=p_style, topping_type=p_number_of_toppings) p = Pizza(pizza_type=p_type, quantity=p_quantity) p.save() for t in p_toppings: topping = get_object_or_404(Topping, name=t) p.toppings.add(topping) p_username = request.user customer = Customer.objects.get(user=p_username) the_order = Order.objects.filter(user=request.user).filter( status=ACTIVE).first() if the_order == None: the_order = Order(user=request.user, status=ACTIVE, total=p_type.price) the_order.save() the_order.contents.add(p) the_order.total = total( Order.objects.filter(user=request.user).filter( status=ACTIVE).first().contents.all()) the_order.save() else: the_order.contents.add(p) the_order.total = total( Order.objects.filter(user=request.user).filter( status=ACTIVE).first().contents.all()) the_order.save() context['order'] = Order.objects.filter( user=request.user).filter(status=ACTIVE).first() return render(request, "cart.html", context) else: return render(request, "create_order.html", context)