lmiit SLE endpoint and always fitler for recent days
This commit is contained in:
parent
aac729a3a0
commit
77f81523d0
@ -27,9 +27,6 @@ def shopping_helper(qs, request):
|
|||||||
elif checked in ['true', 1, '1']:
|
elif checked in ['true', 1, '1']:
|
||||||
qs = qs.filter(checked=True)
|
qs = qs.filter(checked=True)
|
||||||
elif checked in ['recent']:
|
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
|
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')
|
return qs.distinct().order_by(*supermarket_order).select_related('unit', 'food', 'ingredient', 'created_by', 'list_recipe', 'list_recipe__mealplan', 'list_recipe__recipe')
|
||||||
|
@ -1165,6 +1165,10 @@ class ShoppingListEntryViewSet(viewsets.ModelViewSet):
|
|||||||
if 'checked' in self.request.query_params or 'recent' in self.request.query_params:
|
if 'checked' in self.request.query_params or 'recent' in self.request.query_params:
|
||||||
return shopping_helper(self.queryset, self.request)
|
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:
|
try:
|
||||||
last_autosync = self.request.query_params.get('last_autosync', None)
|
last_autosync = self.request.query_params.get('last_autosync', None)
|
||||||
if last_autosync:
|
if last_autosync:
|
||||||
@ -1175,7 +1179,7 @@ class ShoppingListEntryViewSet(viewsets.ModelViewSet):
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
# TODO once old shopping list is removed this needs updated to sharing users in preferences
|
# TODO once old shopping list is removed this needs updated to sharing users in preferences
|
||||||
return self.queryset
|
return self.queryset[:1000]
|
||||||
|
|
||||||
@decorators.action(
|
@decorators.action(
|
||||||
detail=False,
|
detail=False,
|
||||||
|
Loading…
Reference in New Issue
Block a user