Beispiel #1
0
    def testSplit(self):
        reservation = Reservation(room=self.room2, user=self.user, date=self.date, begin=10, end=12)
        reservation.save()

        self.assertTrue(FreeTerm.objects.filter(room=self.room2).filter(date=datetime.date.today())\
                        .filter(begin=5).filter(end=10).exists())
        self.assertTrue(FreeTerm.objects.filter(room=self.room2).filter(date=datetime.date.today())\
                        .filter(begin=12).filter(end=15).exists())
Beispiel #2
0
    def testNoTerm(self):
        err = False
        reservation = Reservation(room=self.room1, user=self.user, date=self.date, begin=2, end=4)

        try:
            reservation.save()
        except IntegrityError:
            err = True
        self.assertTrue(err)
Beispiel #3
0
def confirm(request):
    date = request.session.get('form_date')
    room_id = request.session.get('form_room')
    begin = request.session.get('form_begin')
    end = request.session.get('form_end')

    res_room = Room.objects.get(id=room_id)
    res = Reservation(room=res_room, user=request.user, date=date, begin=begin, end=end)

    try:
        with transaction.atomic():
            res.save()
            messages.success(request, 'The room has been reserved')
    except IntegrityError:
        messages.error(request, 'An error has occurred, please try again')

    return redirect('template')
Beispiel #4
0
def ajax_confirm(request):
    date = request.POST['date']
    room_id = request.POST['room']
    hours = request.POST.getlist('hours[]')
    res_room = Room.objects.get(id=room_id)
    previous = -1
    start = -1
    end = 0

    try:
        for h in hours:
            h1 = int(h)
            if not FreeTerm.objects.all().filter(begin__lte=h1).filter(end__gte=h1):
                args = {}
                args['start'] = h1
                args['end'] = h1 + 1
                return render(request, 'fail.html', args)
            if h1 == previous + 1:
                if start == -1:
                    start = 0

                if not FreeTerm.objects.all().filter(begin__lte=start).filter(end__gte=h1):
                    end = previous
                    res = Reservation(room=res_room, user=request.user, date=date, begin=start, end=end)
                    with transaction.atomic():
                        res.save()

                    start = previous
                    previous = h1
                    end = h1 + 1
                else:
                    previous = h1
                    end = h1 + 1

            else:
                if start != -1:
                    res = Reservation(room=res_room, user=request.user, date=date, begin=start, end=end)
                    with transaction.atomic():
                        res.save()

                previous = h1
                start = h1
                end = h1 + 1

        res = Reservation(room=res_room, user=request.user, date=date, begin=start, end=end)
        with transaction.atomic():
            res.save()

    except IntegrityError:
        args = {}
        args['start'] = start
        args['end'] = end
        return render(request, 'fail.html', args)

    return render(request, 'success.html')