Skip to content

Commit 05e04f0

Browse files
Merge branch 'develop' of https://github.com/TandoorRecipes/recipes into develop
� Conflicts: � docs/install/manual.md
2 parents 236e1b7 + 9fcfa17 commit 05e04f0

34 files changed

+901
-674
lines changed

cookbook/helper/permission_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def has_permission(self, request, view):
206206

207207
def has_object_permission(self, request, view, obj):
208208
# temporary hack to make old shopping list work with new shopping list
209-
if obj.__class__.__name__ == 'ShoppingList':
209+
if obj.__class__.__name__ in ['ShoppingList', 'ShoppingListEntry']:
210210
return is_object_shared(request.user, obj) or obj.created_by in list(request.user.get_shopping_share())
211211
return is_object_shared(request.user, obj)
212212

cookbook/helper/shopping_helper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def list_from_recipe(list_recipe=None, recipe=None, mealplan=None, servings=None
7979
elif ingredients:
8080
ingredients = Ingredient.objects.filter(pk__in=ingredients, space=space)
8181
else:
82-
ingredients = Ingredient.objects.filter(step__recipe=r, space=space)
82+
ingredients = Ingredient.objects.filter(step__recipe=r, food__ignore_shopping=False, space=space)
8383

8484
if exclude_onhand := created_by.userpreference.mealplan_autoexclude_onhand:
8585
ingredients = ingredients.exclude(food__onhand_users__id__in=[x.id for x in shared_users])
@@ -101,9 +101,9 @@ def list_from_recipe(list_recipe=None, recipe=None, mealplan=None, servings=None
101101
if ingredients.filter(food__recipe=x).exists():
102102
for ing in ingredients.filter(food__recipe=x):
103103
if exclude_onhand:
104-
x_ing = Ingredient.objects.filter(step__recipe=x, space=space).exclude(food__onhand_users__id__in=[x.id for x in shared_users])
104+
x_ing = Ingredient.objects.filter(step__recipe=x, food__ignore_shopping=False, space=space).exclude(food__onhand_users__id__in=[x.id for x in shared_users])
105105
else:
106-
x_ing = Ingredient.objects.filter(step__recipe=x, space=space)
106+
x_ing = Ingredient.objects.filter(step__recipe=x, food__ignore_shopping=False, space=space).exclude(food__ignore_shopping=True)
107107
for i in [x for x in x_ing]:
108108
ShoppingListEntry.objects.create(
109109
list_recipe=list_recipe,

cookbook/locale/de/LC_MESSAGES/django.po

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ msgstr ""
1515
"Project-Id-Version: PACKAGE VERSION\n"
1616
"Report-Msgid-Bugs-To: \n"
1717
"POT-Creation-Date: 2022-01-18 14:52+0100\n"
18-
"PO-Revision-Date: 2022-01-26 14:06+0000\n"
19-
"Last-Translator: Leni <[email protected]>\n"
18+
"PO-Revision-Date: 2022-01-28 00:06+0000\n"
19+
"Last-Translator: Alex Hanselmann <[email protected]>\n"
2020
"Language-Team: German <http://translate.tandoor.dev/projects/tandoor/"
2121
"recipes-backend/de/>\n"
2222
"Language: de\n"
@@ -425,27 +425,27 @@ msgstr "Separator für CSV-Export."
425425

426426
#: .\cookbook\forms.py:504
427427
msgid "Prefix to add when copying list to the clipboard."
428-
msgstr ""
428+
msgstr "Zusatz wird der in die Zwischenablage kopierten Liste vorangestellt."
429429

430430
#: .\cookbook\forms.py:508
431431
msgid "Share Shopping List"
432432
msgstr "Einkaufsliste teilen"
433433

434434
#: .\cookbook\forms.py:509
435435
msgid "Autosync"
436-
msgstr ""
436+
msgstr "Automatischer Abgleich"
437437

438438
#: .\cookbook\forms.py:510
439439
msgid "Auto Add Meal Plan"
440-
msgstr ""
440+
msgstr "automatisch dem Menüplan hinzufügen"
441441

442442
#: .\cookbook\forms.py:511
443443
msgid "Exclude On Hand"
444444
msgstr ""
445445

446446
#: .\cookbook\forms.py:512
447447
msgid "Include Related"
448-
msgstr ""
448+
msgstr "dazugehörend"
449449

450450
#: .\cookbook\forms.py:513
451451
msgid "Default Delay Hours"
@@ -459,11 +459,11 @@ msgstr "Supermarkt filtern"
459459

460460
#: .\cookbook\forms.py:515
461461
msgid "Recent Days"
462-
msgstr ""
462+
msgstr "Vergangene Tage"
463463

464464
#: .\cookbook\forms.py:516
465465
msgid "CSV Delimiter"
466-
msgstr ""
466+
msgstr "CSV Trennzeichen"
467467

468468
#: .\cookbook\forms.py:517 .\cookbook\templates\shopping_list.html:322
469469
msgid "List Prefix"
@@ -525,7 +525,7 @@ msgstr ""
525525

526526
#: .\cookbook\helper\recipe_search.py:473
527527
msgid "One of queryset or hash_key must be provided"
528-
msgstr ""
528+
msgstr "Es muss die Abfrage oder der Hash_Key angeben werden"
529529

530530
#: .\cookbook\helper\scrapers\cookidoo.py:21
531531
msgid "Linkslauf"
@@ -550,7 +550,7 @@ msgstr "Mindestens ein Rezept oder ein Essensplan müssen angegeben werden"
550550

551551
#: .\cookbook\helper\shopping_helper.py:58
552552
msgid "You must supply a created_by"
553-
msgstr ""
553+
msgstr "Die Angabe der Verfassers ist notwendig"
554554

555555
#: .\cookbook\helper\template_helper.py:61
556556
#: .\cookbook\helper\template_helper.py:63
@@ -743,7 +743,7 @@ msgstr "Stichwort Alias"
743743

744744
#: .\cookbook\serializer.py:175
745745
msgid "A user is required"
746-
msgstr ""
746+
msgstr "Ein Benutzername ist notwendig"
747747

748748
#: .\cookbook\serializer.py:195
749749
msgid "File uploads are not enabled for this Space."

cookbook/serializer.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ExtendedRecipeMixin(serializers.ModelSerializer):
3333
images = None
3434

3535
image = serializers.SerializerMethodField('get_image')
36-
numrecipe = serializers.ReadOnlyField(source='count_recipes_test')
36+
numrecipe = serializers.ReadOnlyField(source='recipe_count')
3737

3838
def get_fields(self, *args, **kwargs):
3939
fields = super().get_fields(*args, **kwargs)
@@ -58,9 +58,6 @@ def get_image(self, obj):
5858
if obj.recipe_image:
5959
return MEDIA_URL + obj.recipe_image
6060

61-
def count_recipes(self, obj):
62-
return Recipe.objects.filter(**{self.recipe_filter: obj}, space=obj.space).count()
63-
6461

6562
class CustomDecimalField(serializers.Field):
6663
"""
@@ -169,6 +166,11 @@ class UserPreferenceSerializer(WritableNestedModelSerializer):
169166
food_inherit_default = FoodInheritFieldSerializer(source='space.food_inherit', many=True, allow_null=True, required=False, read_only=True)
170167
plan_share = UserNameSerializer(many=True, allow_null=True, required=False, read_only=True)
171168
shopping_share = UserNameSerializer(many=True, allow_null=True, required=False)
169+
food_children_exist = serializers.SerializerMethodField('get_food_children_exist')
170+
171+
def get_food_children_exist(self, obj):
172+
space = getattr(self.context.get('request', None), 'space', None)
173+
return Food.objects.filter(depth__gt=0, space=space).exists()
172174

173175
def create(self, validated_data):
174176
if not validated_data.get('user', None):
@@ -183,7 +185,7 @@ class Meta:
183185
'user', 'theme', 'nav_color', 'default_unit', 'default_page', 'use_fractions', 'use_kj', 'search_style', 'show_recent', 'plan_share',
184186
'ingredient_decimals', 'comments', 'shopping_auto_sync', 'mealplan_autoadd_shopping', 'food_inherit_default', 'default_delay',
185187
'mealplan_autoinclude_related', 'mealplan_autoexclude_onhand', 'shopping_share', 'shopping_recent_days', 'csv_delim', 'csv_prefix',
186-
'filter_to_supermarket', 'shopping_add_onhand', 'left_handed'
188+
'filter_to_supermarket', 'shopping_add_onhand', 'left_handed', 'food_children_exist'
187189
)
188190

189191

@@ -429,7 +431,7 @@ class Meta:
429431
model = Food
430432
fields = (
431433
'id', 'name', 'description', 'shopping', 'recipe', 'food_onhand', 'supermarket_category',
432-
'image', 'parent', 'numchild', 'numrecipe', 'inherit_fields', 'full_name'
434+
'image', 'parent', 'numchild', 'numrecipe', 'inherit_fields', 'full_name', 'ignore_shopping'
433435
)
434436
read_only_fields = ('id', 'numchild', 'parent', 'image', 'numrecipe')
435437

@@ -683,14 +685,15 @@ def get_name(self, obj):
683685
value = Decimal(value)
684686
value = value.quantize(Decimal(1)) if value == value.to_integral() else value.normalize() # strips trailing zero
685687
return (
686-
obj.name
687-
or getattr(obj.mealplan, 'title', None)
688-
or (d := getattr(obj.mealplan, 'date', None)) and ': '.join([obj.mealplan.recipe.name, str(d)])
689-
or obj.recipe.name
690-
) + f' ({value:.2g})'
688+
obj.name
689+
or getattr(obj.mealplan, 'title', None)
690+
or (d := getattr(obj.mealplan, 'date', None)) and ': '.join([obj.mealplan.recipe.name, str(d)])
691+
or obj.recipe.name
692+
) + f' ({value:.2g})'
691693

692694
def update(self, instance, validated_data):
693-
if 'servings' in validated_data:
695+
# TODO remove once old shopping list
696+
if 'servings' in validated_data and self.context.get('view', None).__class__.__name__ != 'ShoppingListViewSet':
694697
list_from_recipe(
695698
list_recipe=instance,
696699
servings=validated_data['servings'],

cookbook/signals.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,3 @@ def auto_add_shopping(sender, instance=None, created=False, weak=False, **kwargs
121121
'servings': instance.servings
122122
}
123123
list_recipe = list_from_recipe(**kwargs)
124-
125-
126-
# user = self.context['request'].user
127-
# if user.userpreference.shopping_add_onhand:
128-
# if checked := validated_data.get('checked', None):
129-
# instance.food.onhand_users.add(*user.userpreference.shopping_share.all(), user)
130-
# elif checked == False:
131-
# instance.food.onhand_users.remove(*user.userpreference.shopping_share.all(), user)

cookbook/templates/shopping_list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ <h2>{% trans 'Shopping List' %}</h2>
834834
this.$http.get('{% url 'api:recipe-detail' 123456 %}'.replace('123456', recipe.id)).then((response) => {
835835
for (let s of response.data.steps) {
836836
for (let i of s.ingredients) {
837-
if (!i.is_header && i.food !== null && i.food.food_onhand === false) {
837+
if (!i.is_header && i.food !== null && !i.food.ignore_food) {
838838
this.shopping_list.entries.push({
839839
'list_recipe': slr.id,
840840
'food': i.food,

cookbook/views/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def annotate_recipe(self, queryset=None, request=None, serializer=None, tree=Fal
118118
# add a recipe count annotation to the query
119119
# explanation on construction https://stackoverflow.com/a/43771738/15762829
120120
recipe_count = Recipe.objects.filter(**{recipe_filter: OuterRef('id')}, space=space).values(recipe_filter).annotate(count=Count('pk')).values('count')
121-
queryset = queryset.annotate(recipe_count_test=Coalesce(Subquery(recipe_count), 0))
121+
queryset = queryset.annotate(recipe_count=Coalesce(Subquery(recipe_count), 0))
122122

123123
# add a recipe image annotation to the query
124124
image_subquery = Recipe.objects.filter(**{recipe_filter: OuterRef('id')}, space=space).exclude(image__isnull=True).exclude(image__exact='').order_by("?").values('image')[:1]
@@ -400,7 +400,7 @@ class SupermarketCategoryViewSet(viewsets.ModelViewSet, StandardFilterMixin):
400400
permission_classes = [CustomIsUser]
401401

402402
def get_queryset(self):
403-
self.queryset = self.queryset.filter(space=self.request.space)
403+
self.queryset = self.queryset.filter(space=self.request.space).order_by('name')
404404
return super().get_queryset()
405405

406406

0 commit comments

Comments
 (0)