Exemplo n.º 1
0
def restaurant(req, restaurantId):
    """
    Retrive, modify or delete single restaurant by id
    """
    try:
        restaurant = Restaurant.objects.get(id=restaurantId)
    except Restaurant.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if req.method == 'GET':
        serializer = RestaurantDetailSerializer(restaurant)
        data = serializer.data
        RestaurantService.calculateRate(data)
        return Response(data)

    elif req.method == 'PUT':
        req.data['user'] = req.user.id
        serializer = RestaurantSerializer(restaurant, data=req.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        else:
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

    elif req.method == 'DELETE':
        restaurant.delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT)
Exemplo n.º 2
0
def restaurants(req):
    """
    Get all restaurants, or create a new one
    """
    if req.method == 'GET':
        restaurants = Restaurant.objects.all()
        serializer = RestaurantDetailSerializer(restaurants, many=True)
        data = serializer.data
        for restaurant in data:
            RestaurantService.calculateRate(restaurant)
        return Response(data)

    elif req.method == 'POST':
        req.data['user'] = req.user.id
        serializer = RestaurantSerializer(data=req.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 3
0
def myRestaurants(req):
    """
    Get all restaurants, or create a new one
    """
    if req.method == 'GET':
        restaurants = Restaurant.objects.filter(user=req.user.id)
        serializer = RestaurantDetailSerializer(restaurants, many=True)
        data = serializer.data
        for restaurant in data:
            RestaurantService.calculateRate(restaurant)
        return Response(data)
Exemplo n.º 4
0
def restaurant(req, restaurantId):
    """
    Retrive, modify or delete single restaurant by id
    """
    try:
        restaurant = Restaurant.objects.get(id=restaurantId)
    except Restaurant.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if req.method == 'GET':
        serializer = RestaurantDetailSerializer(restaurant)
        data = serializer.data
        RestaurantService.calculateRate(data)
        return Response(data)

    elif req.method == 'PUT':
        req.data['user'] = req.user.id
        serializer = RestaurantSerializer(restaurant, data=req.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        else:
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)

    elif req.method == 'DELETE':
        restaurant.delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT)
Exemplo n.º 5
0
def getDetailedUser(id):
    userModelObj = User.objects.get(id=id)
    # serializer = UserReadSerializer(user)
    user = UserReadSerializer(userModelObj).data

    foods = Food.objects.filter(user=id)
    serializer = FoodPureSerializer(foods, many=True)
    data = serializer.data
    for food in data:
        FoodService.calculateRate(food)
    user['foods'] = data

    restaurants = Restaurant.objects.filter(user=id)
    serializer = RestaurantDetailSerializer(restaurants, many=True)
    data = serializer.data
    for restaurant in data:
        RestaurantService.calculateRate(restaurant)
    user['restaurants'] = data
    user['isServer'] = len(data) > 0

    serializer = DietReadSerializer(userModelObj.diet_set, many=True)
    user['diets'] = serializer.data

    foodComments = FoodComment.objects.filter(user=id)
    user['foodComments'] = FoodCommentPureSerializer(foodComments,
                                                     many=True).data
    foodRates = FoodRate.objects.filter(user=id)
    user['foodRates'] = FoodRatePureSerializer(foodRates, many=True).data
    restaurantComments = RestaurantComment.objects.filter(user=id)
    user['restaurantComments'] = RestaurantCommentPureSerializer(
        restaurantComments, many=True).data
    restaurantRates = RestaurantRate.objects.filter(user=id)
    user['restaurantRates'] = RestaurantRatePureSerializer(restaurantRates,
                                                           many=True).data

    return user
Exemplo n.º 6
0
def restaurants(req):
    """
    Get all restaurants, or create a new one
    """
    if req.method == 'GET':
        restaurants = Restaurant.objects.all()
        serializer = RestaurantDetailSerializer(restaurants, many=True)
        data = serializer.data
        for restaurant in data:
            RestaurantService.calculateRate(restaurant)
        return Response(data)

    elif req.method == 'POST':
        req.data['user'] = req.user.id
        serializer = RestaurantSerializer(data=req.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)