def get_order_form(ready_by, order_method): site = Site.objects.all()[0] location = site.location_set.all()[0] request = Mock() request.site = site request.location = location form = OrderForm({ 'name': 'John Smith', 'phone': '12345', 'ready_by_0': ready_by.strftime('%I'), 'ready_by_1': ready_by.strftime('%M'), 'ready_by_2': ready_by.strftime('%p'), 'method': order_method, }, request=request) form.total = '40.00' return form
def get_order_form(ready_by, order_method): site = Site.objects.all()[0] location = site.location_set.all()[0] request = Mock() request.site = site request.location = location form = OrderForm( { 'name': 'John Smith', 'phone': '12345', 'ready_by_0': ready_by.strftime('%I'), 'ready_by_1': ready_by.strftime('%M'), 'ready_by_2': ready_by.strftime('%p'), 'method': order_method, }, request=request) form.total = '40.00' return form
return HttpResponseRedirect(reverse('change_location')) i = get_object_or_404(Item, section__slug=section_slug, section__id=section_id, id=item_id, slug=item_slug, site=request.site) try: assert request.site.is_open(request.location) and i.is_available(request.location) except OrderingError, e: if request.is_mobile: return HttpResponse(json.dumps({ 'error': True, 'msg': e.msg })) messages.warning(request, e.msg) return HttpResponseRedirect(e.redirect_to) OrderForm = get_order_form(i) total = i.variant_set.order_by('-price')[0].price if request.method == 'POST': form = OrderForm(request.POST, location=request.location) if form.is_valid(): request.cart.add(i, form) if request.is_mobile: return HttpResponse(request.cart.to_json()) else: msg = """%s added to your order. You can <a href="%s">complete your order now</a> or <a href="/menu/">add more items</a>.""" % ( i.name, reverse('preview_order')) messages.success(request, msg) return HttpResponseRedirect(i.section.get_absolute_url()) elif request.is_mobile: return HttpResponse(json.dumps({ 'error': True, 'msg': "Please correct the highlighted errors.", 'fields': form._errors