Enhancements
This commit is contained in:
@@ -24,6 +24,7 @@ from .services.diary import diary_context, selected_date
|
||||
from .services.openfoodfacts import OpenFoodFactsError, cached_product, cached_search
|
||||
from .services.products import local_products
|
||||
from .services.logging import apply_product_snapshot
|
||||
from .services.hydration import sync_food_hydration
|
||||
from planner.timezones import localdate_for_user
|
||||
|
||||
|
||||
@@ -124,6 +125,7 @@ def _save_entry(form, user, day, product):
|
||||
entry.user = user
|
||||
entry.date = day
|
||||
apply_product_snapshot(entry, product)
|
||||
sync_food_hydration(entry)
|
||||
entry.full_clean()
|
||||
entry.save()
|
||||
_save_custom_portion(form, user, product, entry)
|
||||
@@ -135,6 +137,7 @@ def _diary_response(request, day):
|
||||
response = render(request, 'food/partials/diary_content.html',
|
||||
diary_context(request.user, day, get_language_from_request(request)))
|
||||
response['HX-Push-Url'] = f"{reverse('food:diary')}?date={day.isoformat()}"
|
||||
response['HX-Trigger'] = 'hydrationChanged'
|
||||
return response
|
||||
return redirect(f"{reverse('food:diary')}?date={day.isoformat()}")
|
||||
|
||||
@@ -366,6 +369,7 @@ def edit_entry(request, pk):
|
||||
for field, original in original_nutrients.items():
|
||||
setattr(updated, field, (original * factor).quantize(Decimal('0.001')) if original is not None else None)
|
||||
with transaction.atomic():
|
||||
sync_food_hydration(updated)
|
||||
updated.full_clean()
|
||||
updated.save()
|
||||
if product:
|
||||
@@ -383,3 +387,18 @@ def delete_entry(request, pk):
|
||||
day = entry.date
|
||||
entry.delete()
|
||||
return _diary_response(request, day)
|
||||
|
||||
|
||||
@login_required
|
||||
@require_http_methods(['GET', 'POST'])
|
||||
def product_hydration(request, pk):
|
||||
from .forms import FoodProductHydrationForm
|
||||
|
||||
product = get_object_or_404(FoodProduct, pk=pk, owner=request.user)
|
||||
form = FoodProductHydrationForm(request.POST or None, instance=product)
|
||||
if request.method == 'POST' and form.is_valid():
|
||||
product = form.save(commit=False)
|
||||
product.hydration_source = 'manual'
|
||||
product.save()
|
||||
return redirect('food:diary')
|
||||
return render(request, 'food/product_hydration.html', {'product': product, 'form': form})
|
||||
|
||||
Reference in New Issue
Block a user