review shopping list in MealPlan modal

This commit is contained in:
Chris Scoggins
2022-01-29 14:10:14 -06:00
parent a7796cbf5c
commit e00794bbdf
7 changed files with 54 additions and 15 deletions

View File

@@ -8,7 +8,7 @@ from django.utils import timezone
from django.utils.translation import gettext as _
from cookbook.helper.HelperFunctions import Round, str2bool
from cookbook.models import (Ingredient, ShoppingListEntry, ShoppingListRecipe,
from cookbook.models import (Ingredient, MealPlan, Recipe, ShoppingListEntry, ShoppingListRecipe,
SupermarketCategoryRelation)
from recipes import settings
@@ -45,6 +45,8 @@ class RecipeShoppingEditor():
self._kwargs = {**kwargs}
self.mealplan = self._kwargs.get('mealplan', None)
if type(self.mealplan) in [int, float]:
self.mealplan = MealPlan.objects.filter(id=self.mealplan, space=self.space)
self.id = self._kwargs.get('id', None)
self._shopping_list_recipe = self.get_shopping_list_recipe(self.id, self.created_by, self.space)
@@ -55,6 +57,8 @@ class RecipeShoppingEditor():
self.created_by = getattr(self._shopping_list_recipe.entries.first(), 'created_by', self.created_by)
self.recipe = getattr(self._shopping_list_recipe, 'recipe', None) or self._kwargs.get('recipe', None) or getattr(self.mealplan, 'recipe', None)
if type(self.recipe) in [int, float]:
self.recipe = Recipe.objects.filter(id=self.recipe, space=self.space)
try:
self.servings = float(self._kwargs.get('servings', None))

View File

@@ -644,7 +644,6 @@ class RecipeViewSet(viewsets.ModelViewSet):
schema = QueryParamAutoSchema()
def get_queryset(self):
if self.detail:
self.queryset = self.queryset.filter(space=self.request.space)
return super().get_queryset()
@@ -718,7 +717,8 @@ class RecipeViewSet(viewsets.ModelViewSet):
ingredients = request.data.get('ingredients', None)
servings = request.data.get('servings', None)
list_recipe = request.data.get('list_recipe', None)
SLR = RecipeShoppingEditor(request.user, request.space, id=list_recipe, recipe=obj)
mealplan = request.data.get('mealplan', None)
SLR = RecipeShoppingEditor(request.user, request.space, id=list_recipe, recipe=obj, mealplan=mealplan)
content = {'msg': _(f'{obj.name} was added to the shopping list.')}
http_status = status.HTTP_204_NO_CONTENT