Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def overview_view(request):
- context = {}
- if request.method == 'GET':
- start_date = None
- end_date = None
- # If this condition is not met, then start_date and end_date are None, which will not produce an error, just an empty query
- # Booking.objects.filter(organization_id=request.user.organization_id, booking_time__range=(None, None))
- if request.is_ajax():
- booking_times = request.GET.get('day')
- start_date = datetime.strptime(booking_times, "%Y-%m-%d")
- end_date = start_date + timedelta(days=4)
- start_date = start_date.replace(hour=0, minute=0, second=0, microsecond=0, tzinfo=pytz.utc)
- end_date = end_date.replace(hour=0, minute=0, second=0, microsecond=0, tzinfo=pytz.utc)
- # This query is not bad, everything is apparently normal,
- # however the if condition that is above worries me and
- # I think that when you make the request it is not fulfilled causing the logical error
- context['bookings']=Booking.objects.filter(
- Q(organization_id=request.user.organization_id),
- Q(booking_time__range=(start_date, end_date)
- )
- context['office'] = Office.objects.filter(organization_id__exact=request.user.organization_id)
- return render(request, 'overview/overview.html', context)
- return render(request, 'overview/overview.html', context)
Advertisement
Add Comment
Please, Sign In to add comment