def clean(self):
'''
Only allow submission if there are not already slots in the submitted window,
and only allow rooms associated with the chosen location.
'''
super(SlotCreationForm,self).clean()
startDate = self.cleaned_data.get('startDate')
endDate = self.cleaned_data.get('endDate')
startTime = self.cleaned_data.get('startTime')
endTime = self.cleaned_data.get('endTime')
instructor = self.cleaned_data.get('instructorId')
existingSlots = InstructorAvailabilitySlot.objects.filter(
instructor=instructor,
startTime__gt=(
ensure_localtime(datetime.combine(startDate,startTime)) -
timedelta(minutes=getConstant('privateLessons__lessonLengthInterval'))
),
startTime__lt=ensure_localtime(datetime.combine(endDate,endTime)),
)
if existingSlots.exists():
raise ValidationError(_('Newly created slots cannot overlap existing slots for this instructor.'),code='invalid')
评论列表
文章目录