Guest User

Untitled

a guest
Mar 19th, 2021
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. def overview_view(request):
  2.     context = {}
  3.     if request.method == 'GET':
  4.         start_date = None
  5.         end_date = None
  6.        
  7.         # If this condition is not met, then start_date and end_date are None, which will not produce an error, just an empty query
  8.         # Booking.objects.filter(organization_id=request.user.organization_id, booking_time__range=(None, None))
  9.         if request.is_ajax():
  10.             booking_times = request.GET.get('day')
  11.             start_date = datetime.strptime(booking_times, "%Y-%m-%d")
  12.             end_date = start_date + timedelta(days=4)
  13.             start_date = start_date.replace(hour=0, minute=0, second=0, microsecond=0, tzinfo=pytz.utc)
  14.             end_date = end_date.replace(hour=0, minute=0, second=0, microsecond=0, tzinfo=pytz.utc)
  15.  
  16.         # This query is not bad, everything is apparently normal,
  17.         # however the if condition that is above worries me and
  18.         # I think that when you make the request it is not fulfilled causing the logical error
  19.         context['bookings']=Booking.objects.filter(
  20.             Q(organization_id=request.user.organization_id),
  21.             Q(booking_time__range=(start_date, end_date)
  22.         )
  23.         context['office'] = Office.objects.filter(organization_id__exact=request.user.organization_id)
  24.        
  25.         return render(request, 'overview/overview.html', context)
  26.     return render(request, 'overview/overview.html', context)
Advertisement
Add Comment
Please, Sign In to add comment