lmiit SLE endpoint and always fitler for recent days

This commit is contained in:
vabene1111 2024-01-29 09:02:11 +01:00
parent aac729a3a0
commit 77f81523d0
2 changed files with 5 additions and 4 deletions

View File

@ -27,9 +27,6 @@ def shopping_helper(qs, request):
elif checked in ['true', 1, '1']:
qs = qs.filter(checked=True)
elif checked in ['recent']:
today_start = timezone.now().replace(hour=0, minute=0, second=0)
week_ago = today_start - timedelta(days=user.userpreference.shopping_recent_days)
qs = qs.filter(Q(checked=False) | Q(completed_at__gte=week_ago))
supermarket_order = ['checked'] + supermarket_order
return qs.distinct().order_by(*supermarket_order).select_related('unit', 'food', 'ingredient', 'created_by', 'list_recipe', 'list_recipe__mealplan', 'list_recipe__recipe')

View File

@ -1165,6 +1165,10 @@ class ShoppingListEntryViewSet(viewsets.ModelViewSet):
if 'checked' in self.request.query_params or 'recent' in self.request.query_params:
return shopping_helper(self.queryset, self.request)
today_start = timezone.now().replace(hour=0, minute=0, second=0)
week_ago = today_start - datetime.timedelta(days=max(self.request.user.userpreference.shopping_recent_days, 14))
self.queryset = self.queryset.filter(Q(checked=False) | Q(completed_at__gte=week_ago))
try:
last_autosync = self.request.query_params.get('last_autosync', None)
if last_autosync:
@ -1175,7 +1179,7 @@ class ShoppingListEntryViewSet(viewsets.ModelViewSet):
traceback.print_exc()
# TODO once old shopping list is removed this needs updated to sharing users in preferences
return self.queryset
return self.queryset[:1000]
@decorators.action(
detail=False,