various fixes

This commit is contained in:
vabene1111
2025-09-18 18:10:58 +02:00
parent f0342d4568
commit bca1ebbf99
9 changed files with 61 additions and 22 deletions

View File

@@ -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

View File

@@ -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):

View File

@@ -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)

View File

@@ -11,7 +11,7 @@
<recipe-image :height="itemHeight" :width="itemHeight" :recipe="mealPlan.recipe"></recipe-image>
</div>
<div class="flex-column flex-grow-0 pa-1">
<span class="font-light" :class="{'two-line-text': detailedItems,'one-line-text': !detailedItems,}">
<span class="font-light" :class="{'three-line-text': detailedItems,'one-line-text': !detailedItems,}">
<i class="fas fa-shopping-cart fa-xs float-left" v-if="mealPlan.shopping"/>
{{ itemTitle }}
</span>
@@ -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;
}
</style>

View File

@@ -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'
}
})

View File

@@ -33,9 +33,8 @@
</template>
<v-list-item-title class="font-weight-bold">
{{ c.createdBy.displayName }}
</v-list-item-title>
<v-list-item-subtitle>{{ c.comment }}</v-list-item-subtitle>
<span>{{ c.comment }}</span>
<v-list-item-subtitle class="font-italic mt-1" v-if="c.servings != null && c.servings > 0">
@@ -49,7 +48,7 @@
<template #append>
<v-list-item-action class="flex-column align-end">
<v-rating density="comfortable" size="x-small" color="tandoor" v-model="c.rating" half-increments readonly
v-if="c.rating != undefined"></v-rating>
v-if="c.rating != undefined" style="overflow: hidden"></v-rating>
<v-spacer></v-spacer>
<v-tooltip location="top" :text="DateTime.fromJSDate(c.createdAt).toLocaleString(DateTime.DATETIME_MED)" v-if="c.createdAt != undefined">
<template v-slot:activator="{ props }">
@@ -121,6 +120,7 @@ function recLoadCookLog(recipeId: number, page: number = 1) {
* reset new cook log from with proper defaults
*/
function resetForm() {
newCookLog.value = {} as CookLog
newCookLog.value.servings = props.recipe.servings
newCookLog.value.createdAt = new Date()
newCookLog.value.recipe = props.recipe.id!

View File

@@ -1,5 +1,5 @@
<template>
<v-list-item class="swipe-container border-t-sm" :id="itemContainerId" @touchend="handleSwipe()" @click="dialog = true;"
<v-list-item class="swipe-container border-t-sm mt-0 mb-0 pt-0 pb-0 pe-0 pa-0" :id="itemContainerId" @touchend="handleSwipe()" @click="dialog = true;"
v-if="isShoppingListFoodVisible(props.shoppingListFood, useUserPreferenceStore().deviceSettings)"
>
<!-- <div class="swipe-action" :class="{'bg-success': !isChecked , 'bg-warning': isChecked }">-->
@@ -9,7 +9,7 @@
<div class="flex-grow-1 p-2">
<div class="d-flex">
<div class="d-flex flex-column pr-2">
<div class="d-flex flex-column pr-2 pl-4">
<span v-for="a in amounts" v-bind:key="a.key">
<span>
<i class="fas fa-check text-success fa-fw" v-if="a.checked"></i>
@@ -30,10 +30,13 @@
</div>
</div>
<template v-slot:[checkBtnSlot]>
<v-btn color="success" @click.native.stop="useShoppingStore().setEntriesCheckedState(entries, !isChecked, true);"
:class="{'btn-success': !isChecked, 'btn-warning': isChecked}" :icon="actionButtonIcon" variant="plain">
</v-btn>
<div class="ps-3 pe-3" @click.native.stop="useShoppingStore().setEntriesCheckedState(entries, !isChecked, true);">
<v-btn color="success" size="large"
:class="{'btn-success': !isChecked, 'btn-warning': isChecked}" :icon="actionButtonIcon" variant="plain">
</v-btn>
</div>
<!-- <i class="d-print-none fa-fw fas" :class="{'fa-check': !isChecked , 'fa-cart-plus': isChecked }"></i>-->
</template>

View File

@@ -71,7 +71,7 @@ const mergedIngredients = computed(() => {
// Add ingredients from steps
props.steps.forEach(step => {
step.ingredients.forEach(ingredient => {
if (ingredient.food && !ingredient.isHeader && !ingredient.noAmount) {
if (ingredient.food && !ingredient.isHeader ) {
ingredients.push(ingredient);
}
});
@@ -80,7 +80,7 @@ const mergedIngredients = computed(() => {
if (step.stepRecipeData) {
step.stepRecipeData.steps?.forEach((subStep: Step) => {
subStep.ingredients.forEach((ingredient: Ingredient) => {
if (ingredient.food && !ingredient.isHeader && !ingredient.noAmount) {
if (ingredient.food && !ingredient.isHeader) {
ingredients.push(ingredient);
}
});

View File

@@ -250,7 +250,7 @@
<v-row>
<v-col>
<model-select model="Keyword" v-model="keywordSelect">
<model-select model="Keyword" v-model="keywordSelect" allow-create>
<template #append>
<v-btn icon="$add" color="success"
@click="keywordSelect.importKeyword = true; importResponse.recipe.keywords.push(keywordSelect); keywordSelect= null"