diff --git a/cookbook/helper/recipe_search.py b/cookbook/helper/recipe_search.py index f5560ca1..1e4f72cb 100644 --- a/cookbook/helper/recipe_search.py +++ b/cookbook/helper/recipe_search.py @@ -4,7 +4,7 @@ from datetime import timedelta from django.contrib.postgres.search import SearchQuery, SearchRank, TrigramSimilarity from django.core.cache import caches from django.db.models import Avg, Case, Count, F, Func, Max, OuterRef, Q, Subquery, Sum, Value, When -from django.db.models.functions import Coalesce, Substr +from django.db.models.functions import Coalesce, Lower, Substr from django.utils import timezone, translation from django.utils.translation import gettext as _ @@ -666,9 +666,9 @@ class RecipeFacet(): if not self._request.space.demo and self._request.space.show_facet_count: return queryset.annotate(count=Coalesce(Subquery(self._recipe_count_queryset('keywords', depth, steplen)), 0) ).filter(depth=depth, count__gt=0 - ).values('id', 'name', 'count', 'numchild').order_by('name')[:200] + ).values('id', 'name', 'count', 'numchild').order_by(Lower('name').asc())[:200] else: - return queryset.filter(depth=depth).values('id', 'name', 'numchild').order_by('name') + return queryset.filter(depth=depth).values('id', 'name', 'numchild').order_by(Lower('name').asc()) def _food_queryset(self, queryset, food=None): depth = getattr(food, 'depth', 0) + 1 @@ -677,9 +677,9 @@ class RecipeFacet(): if not self._request.space.demo and self._request.space.show_facet_count: return queryset.annotate(count=Coalesce(Subquery(self._recipe_count_queryset('steps__ingredients__food', depth, steplen)), 0) ).filter(depth__lte=depth, count__gt=0 - ).values('id', 'name', 'count', 'numchild').order_by('name')[:200] + ).values('id', 'name', 'count', 'numchild').order_by(Lower('name').asc())[:200] else: - return queryset.filter(depth__lte=depth).values('id', 'name', 'numchild').order_by('name') + return queryset.filter(depth__lte=depth).values('id', 'name', 'numchild').order_by(Lower('name').asc()) # # TODO: This might be faster https://github.com/django-treebeard/django-treebeard/issues/115 @@ -909,7 +909,7 @@ def old_search(request): params = dict(request.GET) params['internal'] = None f = RecipeFilter(params, - queryset=Recipe.objects.filter(space=request.user.userpreference.space).all().order_by('name'), + queryset=Recipe.objects.filter(space=request.user.userpreference.space).all().order_by(Lower('name').asc()), space=request.space) return f.qs diff --git a/cookbook/helper/shopping_helper.py b/cookbook/helper/shopping_helper.py index 2bd641fe..d8e8046e 100644 --- a/cookbook/helper/shopping_helper.py +++ b/cookbook/helper/shopping_helper.py @@ -65,9 +65,13 @@ class RecipeShoppingEditor(): except (ValueError, TypeError): self.servings = getattr(self._shopping_list_recipe, 'servings', None) or getattr(self.mealplan, 'servings', None) or getattr(self.recipe, 'servings', None) + @property + def _recipe_servings(self): + return getattr(self.recipe, 'servings', None) or getattr(getattr(self.mealplan, 'recipe', None), 'servings', None) or getattr(getattr(self._shopping_list_recipe, 'recipe', None), 'servings', None) + @property def _servings_factor(self): - return self.servings / self.recipe.servings + return Decimal(self.servings)/Decimal(self._recipe_servings) @property def _shared_users(self): diff --git a/cookbook/serializer.py b/cookbook/serializer.py index 9ffbbabf..0f9563f5 100644 --- a/cookbook/serializer.py +++ b/cookbook/serializer.py @@ -14,8 +14,8 @@ from rest_framework.fields import empty from cookbook.helper.HelperFunctions import str2bool from cookbook.helper.shopping_helper import RecipeShoppingEditor -from cookbook.models import (Automation, BookmarkletImport, Comment, CookLog, Food, - FoodInheritField, ImportLog, ExportLog, Ingredient, Keyword, MealPlan, MealType, +from cookbook.models import (Automation, BookmarkletImport, Comment, CookLog, ExportLog, Food, + FoodInheritField, ImportLog, Ingredient, Keyword, MealPlan, MealType, NutritionInformation, Recipe, RecipeBook, RecipeBookEntry, RecipeImport, ShareLink, ShoppingList, ShoppingListEntry, ShoppingListRecipe, Step, Storage, Supermarket, SupermarketCategory, @@ -677,7 +677,6 @@ class MealPlanSerializer(SpacedModelSerializer, WritableNestedModelSerializer): read_only_fields = ('created_by',) -# TODO deprecate class ShoppingListRecipeSerializer(serializers.ModelSerializer): name = serializers.SerializerMethodField('get_name') # should this be done at the front end? recipe_name = serializers.ReadOnlyField(source='recipe.name') @@ -689,11 +688,11 @@ class ShoppingListRecipeSerializer(serializers.ModelSerializer): value = Decimal(value) value = value.quantize(Decimal(1)) if value == value.to_integral() else value.normalize() # strips trailing zero return ( - obj.name - or getattr(obj.mealplan, 'title', None) - or (d := getattr(obj.mealplan, 'date', None)) and ': '.join([obj.mealplan.recipe.name, str(d)]) - or obj.recipe.name - ) + f' ({value:.2g})' + obj.name + or getattr(obj.mealplan, 'title', None) + or (d := getattr(obj.mealplan, 'date', None)) and ': '.join([obj.mealplan.recipe.name, str(d)]) + or obj.recipe.name + ) + f' ({value:.2g})' def update(self, instance, validated_data): # TODO remove once old shopping list diff --git a/cookbook/templates/base.html b/cookbook/templates/base.html index ce70c6cf..4b10cf76 100644 --- a/cookbook/templates/base.html +++ b/cookbook/templates/base.html @@ -75,7 +75,7 @@