|
|
@ -296,6 +296,7 @@ class UserRatesDrinkViewSet(viewsets.ModelViewSet): |
|
|
|
|
|
|
|
def perform_create(self, serializer): |
|
|
|
user = self.request.user |
|
|
|
print(self.request) |
|
|
|
|
|
|
|
try: |
|
|
|
drink = Drink.objects.get(pk=self.request._data.get('drink')) |
|
|
@ -419,8 +420,11 @@ class RestaurantUserView(APIView): |
|
|
|
restaurantRatings = restaurantRatings.annotate(username = F('user__username')) \ |
|
|
|
.annotate(diet_name = F('diet__diet_name')).values() |
|
|
|
|
|
|
|
restaurantFoods = Food.objects.all().filter(restaurant=restaurant).filter(food_is_approved=True) |
|
|
|
restaurantDrinks = Drink.objects.all().filter(restaurant=restaurant).filter(drink_is_approved=True) |
|
|
|
restaurantFoods = Food.objects.all().filter(restaurant=restaurant) |
|
|
|
restaurantDrinks = Drink.objects.all().filter(restaurant=restaurant) |
|
|
|
if not user.role.role_id == 1: |
|
|
|
restaurantFoods = restaurantFoods.filter(food_is_approved=True) |
|
|
|
restaurantDrinks = restaurantDrinks.filter(drink_is_approved=True) |
|
|
|
foods = [FoodSerializer(food).data for food in list(restaurantFoods)] |
|
|
|
drinks = [DrinkSerializer(drink).data for drink in list(restaurantDrinks)] |
|
|
|
|
|
|
@ -607,6 +611,11 @@ class AddFood(APIView): |
|
|
|
ingredientInstance = serializer.save() |
|
|
|
ingredientsList += [ingredientInstance] |
|
|
|
|
|
|
|
if request.user.role.role_id == 1: |
|
|
|
requestData['food_is_approved'] = True |
|
|
|
else: |
|
|
|
requestData['food_is_approved'] = False |
|
|
|
|
|
|
|
foodSerializer = FoodSerializer(data = requestData) |
|
|
|
if foodSerializer.is_valid(): |
|
|
|
food = foodSerializer.save() |
|
|
@ -864,4 +873,84 @@ class AddIngredientToDrink(APIView): |
|
|
|
else: |
|
|
|
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) |
|
|
|
|
|
|
|
return Response(serializer.data) |
|
|
|
return Response(serializer.data) |
|
|
|
|
|
|
|
class AcceptRestaurant(APIView): |
|
|
|
authentication_classes = (SessionAuthentication, BasicAuthentication) |
|
|
|
permission_classes = (IsAuthenticated,) |
|
|
|
|
|
|
|
def patch(self, request, restaurant, format=None): |
|
|
|
user = request.user |
|
|
|
if not user.role.role_id == 1: |
|
|
|
raise PermissionDenied({"message":"You don't have permission to access"}) |
|
|
|
|
|
|
|
try: |
|
|
|
restaurant = Restaurant.objects.get(pk=restaurant) |
|
|
|
except Restaurant.DoesNotExist: |
|
|
|
raise Http404 |
|
|
|
|
|
|
|
serializer = RestaurantSerializer(restaurant, data={'restaurant_is_approved': True}, partial=True) |
|
|
|
if serializer.is_valid(): |
|
|
|
serializer.save() |
|
|
|
return Response(serializer.data) |
|
|
|
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) |
|
|
|
|
|
|
|
class AcceptFood(APIView): |
|
|
|
authentication_classes = (SessionAuthentication, BasicAuthentication) |
|
|
|
permission_classes = (IsAuthenticated,) |
|
|
|
|
|
|
|
def patch(self, request, food, format=None): |
|
|
|
user = request.user |
|
|
|
if not user.role.role_id == 1: |
|
|
|
raise PermissionDenied({"message":"You don't have permission to access"}) |
|
|
|
|
|
|
|
try: |
|
|
|
food = Food.objects.get(pk=food) |
|
|
|
except Food.DoesNotExist: |
|
|
|
raise Http404 |
|
|
|
|
|
|
|
serializer = FoodSerializer(food, data={'food_is_approved': True}, partial=True) |
|
|
|
if serializer.is_valid(): |
|
|
|
serializer.save() |
|
|
|
return Response(serializer.data) |
|
|
|
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) |
|
|
|
|
|
|
|
class AcceptDrink(APIView): |
|
|
|
authentication_classes = (SessionAuthentication, BasicAuthentication) |
|
|
|
permission_classes = (IsAuthenticated,) |
|
|
|
|
|
|
|
def patch(self, request, drink, format=None): |
|
|
|
user = request.user |
|
|
|
if not user.role.role_id == 1: |
|
|
|
raise PermissionDenied({"message":"You don't have permission to access"}) |
|
|
|
|
|
|
|
try: |
|
|
|
drink = Drink.objects.get(pk=drink) |
|
|
|
except Drink.DoesNotExist: |
|
|
|
raise Http404 |
|
|
|
|
|
|
|
serializer = DrinkSerializer(drink, data={'drink_is_approved': True}, partial=True) |
|
|
|
if serializer.is_valid(): |
|
|
|
serializer.save() |
|
|
|
return Response(serializer.data) |
|
|
|
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) |
|
|
|
|
|
|
|
class AcceptDiet(APIView): |
|
|
|
authentication_classes = (SessionAuthentication, BasicAuthentication) |
|
|
|
permission_classes = (IsAuthenticated,) |
|
|
|
|
|
|
|
def patch(self, request, diet, format=None): |
|
|
|
user = request.user |
|
|
|
if not user.role.role_id == 1: |
|
|
|
raise PermissionDenied({"message":"You don't have permission to access"}) |
|
|
|
|
|
|
|
try: |
|
|
|
diet = Diet.objects.get(pk=diet) |
|
|
|
except Diet.DoesNotExist: |
|
|
|
raise Http404 |
|
|
|
|
|
|
|
serializer = DietSerializer(diet, data={'diet_is_approved': True}, partial=True) |
|
|
|
if serializer.is_valid(): |
|
|
|
serializer.save() |
|
|
|
return Response(serializer.data) |
|
|
|
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) |