<commit_before>import datetime

from django.forms import ModelForm, ValidationError, TimeInput, DateInput
from django.shortcuts import get_object_or_404

from reservations.models import Queue, Reservation


class QueueForm(ModelForm):

    class Meta:
        model = Queue
        fields = '__all__'


class ReservationForm(ModelForm):

    class Meta:
        model = Reservation
        fields = ('date', 'start_time', 'end_time', )
        widgets = {
            'date': DateInput(attrs={'class': 'datepicker .no-autoinit'}),
            'start_time': TimeInput(attrs={'class': 'timepicker .no-autoinit'}),
            'end_time': TimeInput(attrs={'class': 'timepicker .no-autoinit'}),
        }

    def __init__(self, *args, **kwargs):
        self.parent_queue = get_object_or_404(Queue, pk=kwargs.pop('pk'))
        super().__init__(*args, **kwargs)

    def clean(self):

        cleaned_data = super(ReservationForm, self).clean()

        start_time = cleaned_data.get('start_time', None)
        end_time = cleaned_data.get('end_time', None)
        date = cleaned_data.get('date', None)

        if start_time > end_time:
            raise ValidationError("Invalid argument parameters")

        if date < datetime.date.today() or start_time > (datetime.datetime.now() - datetime.timedelta(minutes=5)).time():
            raise ValidationError("You cannot make reservations back in time")

        for interval in [(r.start_time, r.end_time) for r in self.parent_queue.reservations.filter(date=date)]:
            reservation_overlap = interval[0] <= start_time, end_time <= interval[1]
            if reservation_overlap.__contains__(True):<commit_msg>Fix faulty logic<commit_after>import datetime

from django.forms import ModelForm, ValidationError, TimeInput, DateInput
from django.shortcuts import get_object_or_404

from reservations.models import Queue, Reservation


class QueueForm(ModelForm):

    class Meta:
        model = Queue
        fields = '__all__'


class ReservationForm(ModelForm):

    class Meta:
        model = Reservation
        fields = ('date', 'start_time', 'end_time', )
        widgets = {
            'date': DateInput(attrs={'class': 'datepicker .no-autoinit'}),
            'start_time': TimeInput(attrs={'class': 'timepicker .no-autoinit'}),
            'end_time': TimeInput(attrs={'class': 'timepicker .no-autoinit'}),
        }

    def __init__(self, *args, **kwargs):
        self.parent_queue = get_object_or_404(Queue, pk=kwargs.pop('pk'))
        super().__init__(*args, **kwargs)

    def clean(self):

        cleaned_data = super(ReservationForm, self).clean()

        start_time = cleaned_data.get('start_time', None)
        end_time = cleaned_data.get('end_time', None)
        date = cleaned_data.get('date', None)

        if start_time > end_time:
            raise ValidationError("Invalid argument parameters")

        if date < datetime.date.today() \
                or (start_time < (datetime.datetime.now() - datetime.timedelta(minutes=5)).time()
                    and date == datetime.date.today()):
            raise ValidationError("You cannot make reservations back in time")

        for interval in [(r.start_time, r.end_time) for r in self.parent_queue.reservations.filter(date=date)]:
            reservation_overlap = interval[0] <= start_time, end_time <= interval[1]
            if reservation_overlap.__contains__(True):
{'fraction_non_alphanumeric': 0.12225153913808268, 'fraction_numerical': 0.005277044854881266, 'mean_word_length': 3.0960384153661464, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3268051', 'n_tokens_mistral': 1023, 'n_tokens_neox': 974, 'n_words': 226}