mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-05 05:25:26 +02:00
fix: Use configured server time when calling RepositoryMeals.get_today() method (#4734)
This commit is contained in:
parent
afd304f9e5
commit
8d325198e8
3 changed files with 8 additions and 4 deletions
|
@ -9,11 +9,11 @@ from .repository_generic import HouseholdRepositoryGeneric
|
||||||
|
|
||||||
|
|
||||||
class RepositoryMeals(HouseholdRepositoryGeneric[ReadPlanEntry, GroupMealPlan]):
|
class RepositoryMeals(HouseholdRepositoryGeneric[ReadPlanEntry, GroupMealPlan]):
|
||||||
def get_today(self) -> list[ReadPlanEntry]:
|
def get_today(self, tz=UTC) -> list[ReadPlanEntry]:
|
||||||
if not self.household_id:
|
if not self.household_id:
|
||||||
raise Exception("household_id not set")
|
raise Exception("household_id not set")
|
||||||
|
|
||||||
today = datetime.now(tz=UTC).date()
|
today = datetime.now(tz=tz).date()
|
||||||
stmt = select(GroupMealPlan).filter(
|
stmt = select(GroupMealPlan).filter(
|
||||||
GroupMealPlan.date == today, GroupMealPlan.household_id == self.household_id
|
GroupMealPlan.date == today, GroupMealPlan.household_id == self.household_id
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from functools import cached_property
|
from functools import cached_property
|
||||||
|
|
||||||
|
from dateutil.tz import tzlocal
|
||||||
from fastapi import APIRouter, Depends, HTTPException
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
|
|
||||||
from mealie.core.exceptions import mealie_registered_exceptions
|
from mealie.core.exceptions import mealie_registered_exceptions
|
||||||
|
@ -115,7 +116,8 @@ class GroupMealplanController(BaseCrudController):
|
||||||
|
|
||||||
@router.get("/today")
|
@router.get("/today")
|
||||||
def get_todays_meals(self):
|
def get_todays_meals(self):
|
||||||
return self.repo.get_today()
|
local_tz = tzlocal()
|
||||||
|
return self.repo.get_today(tz=local_tz)
|
||||||
|
|
||||||
@router.post("/random", response_model=ReadPlanEntry)
|
@router.post("/random", response_model=ReadPlanEntry)
|
||||||
def create_random_meal(self, data: CreateRandomEntry):
|
def create_random_meal(self, data: CreateRandomEntry):
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from datetime import UTC, datetime, time, timedelta
|
from datetime import UTC, datetime, time, timedelta
|
||||||
|
|
||||||
|
from dateutil.tz import tzlocal
|
||||||
from pydantic import UUID4
|
from pydantic import UUID4
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
@ -29,7 +30,8 @@ def _create_mealplan_timeline_events_for_household(
|
||||||
recipes_to_update: dict[UUID4, RecipeSummary] = {}
|
recipes_to_update: dict[UUID4, RecipeSummary] = {}
|
||||||
recipe_id_to_slug_map: dict[UUID4, str] = {}
|
recipe_id_to_slug_map: dict[UUID4, str] = {}
|
||||||
|
|
||||||
mealplans = repos.meals.get_today()
|
local_tz = tzlocal()
|
||||||
|
mealplans = repos.meals.get_today(tz=local_tz)
|
||||||
for mealplan in mealplans:
|
for mealplan in mealplans:
|
||||||
if not (mealplan.recipe and mealplan.user_id):
|
if not (mealplan.recipe and mealplan.user_id):
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue