Skip to content

Commit

Permalink
Easier code
Browse files Browse the repository at this point in the history
  • Loading branch information
JobDoesburg committed Nov 15, 2023
1 parent c7b6edf commit 888f5d6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions website/fridges/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ def user_can_open_fridge(user, fridge):
if not opening_hours.exists():
return False, None

already_opened_today = AccessLog.objects.filter(fridge=fridge, timestamp__date=timezone.now().date()).exists()
if config.FRIDGE_REQUIRE_DAILY_OPENING and not already_opened_today:
return False, None

if opening_hours.filter(Q(restrict_to_groups__in=user.groups.all()) | Q(restrict_to_groups__isnull=True)).exists():
already_opened_today = AccessLog.objects.filter(fridge=fridge, timestamp__date=timezone.now().date()).exists()
if config.FRIDGE_REQUIRE_DAILY_OPENING and not already_opened_today:
return False, None
return True, fridge.unlock_for_how_long

return False, None
Expand Down

0 comments on commit 888f5d6

Please sign in to comment.