diff --git a/cookbook/helper/ai_helper.py b/cookbook/helper/ai_helper.py index 584f9a11a..71668e2fd 100644 --- a/cookbook/helper/ai_helper.py +++ b/cookbook/helper/ai_helper.py @@ -5,6 +5,7 @@ from django.db.models import Sum from litellm import CustomLogger from cookbook.models import AiLog +from recipes import settings def get_monthly_token_usage(space): @@ -61,6 +62,8 @@ class AiCallbackHandler(CustomLogger): remaining_balance = self.space.ai_credits_balance - Decimal(str(credit_cost)) if remaining_balance < 0: remaining_balance = 0 + if settings.HOSTED: + self.space.ai_enabled = False self.space.ai_credits_balance = remaining_balance credits_from_balance = True diff --git a/cookbook/integration/mealie1.py b/cookbook/integration/mealie1.py index b43bcbe4b..0e2aae13a 100644 --- a/cookbook/integration/mealie1.py +++ b/cookbook/integration/mealie1.py @@ -1,5 +1,7 @@ import json import re +import traceback +import uuid from decimal import Decimal from io import BytesIO from zipfile import ZipFile @@ -42,7 +44,7 @@ class Mealie1(Integration): keyword = Keyword.objects.create(name=t['name'], space=self.request.space) keywords_tags_dict[t['id']] = keyword.pk - self.import_log.msg +=f"Importing {len(mealie_database["multi_purpose_labels"])} multi purpose labels as supermarket categories...\n" + self.import_log.msg += f"Importing {len(mealie_database["multi_purpose_labels"])} multi purpose labels as supermarket categories...\n" self.import_log.save() supermarket_categories_dict = {} @@ -53,7 +55,7 @@ class Mealie1(Integration): supermarket_category = SupermarketCategory.objects.create(name=m['name'], space=self.request.space) supermarket_categories_dict[m['id']] = supermarket_category.pk - self.import_log.msg +=f"Importing {len(mealie_database["ingredient_foods"])} foods...\n" + self.import_log.msg += f"Importing {len(mealie_database["ingredient_foods"])} foods...\n" self.import_log.save() foods_dict = {} @@ -74,7 +76,7 @@ class Mealie1(Integration): food.onhand_users.add(self.request.user) foods_dict[f['id']] = food.pk - self.import_log.msg +=f"Importing {len(mealie_database["ingredient_units"])} units...\n" + self.import_log.msg += f"Importing {len(mealie_database["ingredient_units"])} units...\n" self.import_log.save() units_dict = {} @@ -121,7 +123,7 @@ class Mealie1(Integration): Recipe.keywords.through.objects.bulk_create(recipe_keyword_relation, ignore_conflicts=True) - self.import_log.msg +=f"Importing {len(mealie_database["recipe_instructions"])} instructions...\n" + self.import_log.msg += f"Importing {len(mealie_database["recipe_instructions"])} instructions...\n" self.import_log.save() steps_relation = [] @@ -148,7 +150,7 @@ class Mealie1(Integration): ingredient_parser = IngredientParser(self.request, True) - self.import_log.msg +=f"Importing {len(mealie_database["recipes_ingredients"])} ingredients...\n" + self.import_log.msg += f"Importing {len(mealie_database["recipes_ingredients"])} ingredients...\n" self.import_log.save() ingredients_relation = [] @@ -201,7 +203,7 @@ class Mealie1(Integration): Recipe.keywords.through.objects.bulk_create(recipe_keyword_relation, ignore_conflicts=True) - self.import_log.msg += f"Importing {len(mealie_database["recipe_nutrition"]) } properties...\n" + self.import_log.msg += f"Importing {len(mealie_database["recipe_nutrition"])} properties...\n" self.import_log.save() property_types_dict = { @@ -227,7 +229,8 @@ class Mealie1(Integration): if r[key]: properties_relation.append( Property(property_type_id=property_types_dict[key].pk, - property_amount=Decimal(str(r[key])) / (Decimal(str(recipe_property_factor_dict[r['recipe_id']])) if r['recipe_id'] in recipe_property_factor_dict else 1), + property_amount=Decimal(str(r[key])) / ( + Decimal(str(recipe_property_factor_dict[r['recipe_id']])) if r['recipe_id'] in recipe_property_factor_dict else 1), open_data_food_slug=r['recipe_id'], space=self.request.space)) properties = Property.objects.bulk_create(properties_relation) @@ -324,6 +327,15 @@ class Mealie1(Integration): )) ShoppingListEntry.objects.bulk_create(shopping_list_items) + self.import_log.msg += f"Importing Images. This might take some time ...\n" + self.import_log.save() + for r in mealie_database['recipes']: + try: + if recipe := Recipe.objects.filter(pk=recipes_dict[r['id']]).first(): + self.import_recipe_image(recipe, BytesIO(file.read(f'data/recipes/{str(uuid.UUID(str(r['id'])))}/images/original.webp')), filetype='.webp') + except Exception: + pass + return recipes def get_file_from_recipe(self, recipe): diff --git a/cookbook/views/api.py b/cookbook/views/api.py index bcd39727e..f119fdc7b 100644 --- a/cookbook/views/api.py +++ b/cookbook/views/api.py @@ -1235,7 +1235,19 @@ class IngredientViewSet(LoggingMixin, viewsets.ModelViewSet): return self.serializer_class def get_queryset(self): - queryset = self.queryset.filter(step__recipe__space=self.request.space) + queryset = self.queryset.prefetch_related('food', + 'food__properties', + 'food__properties__property_type', + 'food__inherit_fields', + 'food__supermarket_category', + 'food__onhand_users', + 'food__substitute', + 'food__child_inherit_fields', + 'unit', + 'unit__unit_conversion_base_relation', + 'unit__unit_conversion_base_relation__base_unit', + 'unit__unit_conversion_converted_relation', + 'unit__unit_conversion_converted_relation__converted_unit', ).filter(step__recipe__space=self.request.space) food = self.request.query_params.get('food', None) if food and re.match(r'^(\d)+$', food): queryset = queryset.filter(food_id=food) diff --git a/vue3/src/components/display/MealPlanCalendarItem.vue b/vue3/src/components/display/MealPlanCalendarItem.vue index 1f40b9d21..f55239420 100644 --- a/vue3/src/components/display/MealPlanCalendarItem.vue +++ b/vue3/src/components/display/MealPlanCalendarItem.vue @@ -11,7 +11,7 @@
- + {{ itemTitle }} @@ -82,4 +82,13 @@ const itemTitle = computed(() => { overflow: hidden; text-overflow: ellipsis; } + +.three-line-text { + display: -webkit-box; + -webkit-line-clamp: 3; + -webkit-box-orient: vertical; + width: 100%; + overflow: hidden; + text-overflow: ellipsis; +} diff --git a/vue3/src/components/display/MealPlanView.vue b/vue3/src/components/display/MealPlanView.vue index d07db46e8..42c485991 100644 --- a/vue3/src/components/display/MealPlanView.vue +++ b/vue3/src/components/display/MealPlanView.vue @@ -98,9 +98,9 @@ const planItems = computed(() => { */ const calendarItemHeight = computed(() => { if (lgAndUp.value && useUserPreferenceStore().deviceSettings.mealplan_displayPeriod == 'week') { - return '2.6rem' + return '3.5rem' } else { - return '1.3rem' + return '1.6rem' } }) diff --git a/vue3/src/components/display/RecipeActivity.vue b/vue3/src/components/display/RecipeActivity.vue index e796ce696..04ea22624 100644 --- a/vue3/src/components/display/RecipeActivity.vue +++ b/vue3/src/components/display/RecipeActivity.vue @@ -33,9 +33,8 @@ {{ c.createdBy.displayName }} - - {{ c.comment }} + {{ c.comment }} @@ -49,7 +48,7 @@