def get_restaurant_carts_page(request): """ Gets the list of carts which have been sent, and are not completed, with this restaurant_id """ restaurant_id = request.GET.get('restaurant_id') carts = Cart.restaurants_carts(Cart, restaurant_id) carts_dict = {'carts': models_to_json(carts)} return JsonResponse(carts_dict)
def get(self, request): """ Retrieve all dishes from restaurant owned by user """ user = request.user check_user_status(user) user_id = user.id restaurant = PendingRestaurant.get_by_owner(user_id) rest_id = restaurant._id dishes = PendingFood.get_by_restaurant(rest_id) response = {'Dishes': models_to_json(dishes)} return JsonResponse(response)
def test_get_all_restaurants(self): """ Test if all approved restaurants are retrieved """ response = self.client.get('/api/restaurant/all/') restaurants = [ Restaurant.objects.get(email="*****@*****.**"), Restaurant.objects.get(email="*****@*****.**"), Restaurant.objects.get(email="*****@*****.**") ] for rest in restaurants: rest.restaurant_image_url = ['/'] rest.payment_methods = ['/'] rest.offer_options = [''] rest.save() expected = {"Restaurants": models_to_json(restaurants)} self.assertDictEqual(expected, json.loads(response.content))
def get_users_cart_page(request): """ Gets the user's active cart based on the given user_id, if 'is_sent' is 'true', give all sent carts otherwise give the only existing active cart """ try: user_id = request.GET.get('user_email') if is_sent(request.GET.get('is_sent')): carts = Cart().users_sent_carts(user_id) carts_dict = {'carts': models_to_json(carts)} # serialize carts return JsonResponse(carts_dict) else: cart = Cart().users_active_cart(user_id) return JsonResponse({'carts': [model_to_json(cart)]}) except ObjectDoesNotExist: # something went wrong (invalid user/no cart) return JsonResponse({'NoCart': 'Closed'})
def get_items_by_cart_page(request): """Get all items associated with a given cart""" items = Item.get_items_by_cart(request.GET['cart_id']) items = models_to_json(items) return JsonResponse({'items': items})
def all_dishes_page(request): """Retrieve all dishes from the database""" foods = Food.objects.all() response = {'Dishes': models_to_json(foods)} return JsonResponse(response)
def get_dish_by_restaurant_page(request): """Retrieve all dishes from a restaurant""" rest_id = request.GET.get('restaurant_id') dishes = Food.get_by_restaurant(rest_id) response = {'Dishes': models_to_json(dishes)} return JsonResponse(response)
def get_all_restaurants_page(request): """Retrieve all restaurants""" restaurants = list(Restaurant.objects.all()) response = {'Restaurants': models_to_json(restaurants)} return JsonResponse(response)
def auto_tag_page(request): """Automatically generate tags for food""" validate(instance=request.body, schema=food_schema) body = json.loads(request.body) tags = models_to_json(ManualTag.auto_tag_food(body['_id'])) return JsonResponse({'tags': tags})
def get(self, request, rest_id): """ Retrieve all approved dishes from a restaurant """ dishes = Food.get_by_restaurant(rest_id) response = {'Dishes': models_to_json(dishes)} return JsonResponse(response)
def get(self, request): """ Retrieve all approved restaurants """ restaurants = models_to_json(list(Restaurant.objects.all())) response = {'Restaurants': restaurants} return JsonResponse(response)