Exemplo n.º 1
0
    def post(self, request, *args, **kwargs):
        staff_data = get_object_or_404(Staff, id=self.kwargs['pk'])
        year = self.kwargs.get('year')
        month = self.kwargs.get('month')
        day = self.kwargs.get('day')
        hour = self.kwargs.get('hour')
        start_time = make_aware(datetime(year=year, month=month, day=day, hour=hour))
        end_time = make_aware(datetime(year=year, month=month, day=day, hour=hour + 1))
        booking_data = Booking.objects.filter(staff=staff_data, start=start_time)
        form = BookingForm(request.POST or None)
        if booking_data.exists():
            form.add_error(None, '既に予約があります。\n別の日時で予約をお願いします。')
        else:
            if form.is_valid():
                booking = Booking()
                booking.staff = staff_data
                booking.start = start_time
                booking.end = end_time
                booking.first_name = form.cleaned_data['first_name']
                booking.last_name = form.cleaned_data['last_name']
                booking.tel = form.cleaned_data['tel']
                booking.remarks = form.cleaned_data['remarks']
                booking.save()
                return redirect('thanks') 

        return render(request, 'app/booking.html', {
            'staff_data': staff_data,
            'year': year,
            'month': month,
            'day': day,
            'hour': hour,
            'form': form,
        })
Exemplo n.º 2
0
def booking(teacher_id, day, hour):
    form = BookingForm()
    if form.validate_on_submit():
        bk = Booking(teacher_id=teacher_id, day=day, hour=hour)
        bk.student_name = form.contact_info.student_name.data
        bk.student_phone = form.contact_info.student_phone.data
        teacher = Teacher.query.get(teacher_id)
        teacher.set_hour_state(day, hour, False)  # теперь время - занято
        bk.save()
        return render_template("done.html",
                               title={
                                   "label": "Тема",
                                   "value": "Пробный урок"
                               },
                               time={
                                   "label": days[bk.day],
                                   "value": f"{bk.hour}:00"
                               },
                               name=bk.student_name,
                               phone=bk.student_phone)

    return render_template("booking.html",
                           teacher=Teacher.query.get(teacher_id),
                           time={
                               "day": day,
                               "hour": hour
                           },
                           days=days,
                           form=form)
Exemplo n.º 3
0
 def register_booking(self, model: RegisterBookingDto):
     booking = Booking()
     booking.flight_id = model.flight_id
     booking.passenger_id = model.passenger_id
     booking.flight_class = model.flight_class
     booking.price = model.price
     booking.booking_reference = model.booking_reference
     booking.save()
Exemplo n.º 4
0
def property(request, property_id):
    prop = Property.objects.get(id=property_id)
    bookings = Booking.objects.filter(property=property_id)
    checker = None
    guest = None

    if request.method == 'POST':
        guest = request.POST.get('guest')
        start_date = request.POST.get('start_date')
        start_date = datetime.strptime(start_date, '%Y-%m-%d').date()
        end_date = request.POST.get('end_date')
        end_date = datetime.strptime(end_date, '%Y-%m-%d').date()
        price = prop.price * (end_date - start_date).days * 1.08

        if len(bookings) > 0:
            for booking in bookings:
                if (booking.start_date <= start_date <= booking.end_date
                        or booking.start_date <= end_date <= booking.end_date
                    ) or (start_date <= booking.start_date
                          and end_date >= booking.end_date):
                    checker = False
                else:
                    checker = True
        else:
            checker = True

        if checker:
            p = Booking(property=prop,
                        start_date=start_date,
                        end_date=end_date,
                        price=price,
                        guest=guest)
            p.save()

    context = {
        'property': prop,
        'checker': checker,
        'guest': guest,
    }

    return render(request, 'app/property.html', context)
Exemplo n.º 5
0
def saveBooking(request):
    name = request.POST.get('u_name')
    block_name = request.POST.get('bn')
    flat_type = request.POST.get('ft')
    flat_no = request.POST.get('fno')
    email = request.POST.get('u_email')
    purpose = request.POST.get('u_pur')
    date = request.POST.get('u_date')
    message = request.POST.get('u_mes')
    # print(name,block_name,flat_type,flat_no,email,purpose,date,message)
    bk = Booking(name=name,
                 flat_no=flat_no,
                 booking_purpose=purpose,
                 booking_date=date,
                 message=message,
                 email=email,
                 flat_type=flat_type,
                 block_name=block_name)
    bk.save()
    res = UserRegister.objects.get(flat_no=flat_no)
    return render(request, 'userhome.html', {'res': res})
Exemplo n.º 6
0
def create_booking(who, when, room_id):
    new_booking = Booking(who=who, when=when, room=room_id, status="pending")
    # new_booking = Booking(who=who, when=when, room=room_id)
    new_booking.save()
    return new_booking.id
Exemplo n.º 7
0
                    rn2 = random.randint(1, 3)
                    if in_building[building] < building_limit and rn2 == 1:
                        bookings.append({
                            "when": when,
                            "who": who,
                            "room": room,
                            "status": status
                        })
                        in_building[building] += 1

#print(bookings)

# Make demo bookings
#bookings = [
#    {"when":"2020-04-05-AM", "who":1, "room":1, "status":"approved"},
#{"when":"2020-04-05-AM", "who":3, "room":1, "status":"approved"},
#{"when":"2020-04-05-AM", "who":4, "room":10, "status":"approved"},
#{"when":"2020-04-08-AM", "who":3, "room":2, "status":"approved"},
#{"when":"2020-04-05-PM", "who":1, "room":35, "status":"approved"},
#{"when":"2020-04-06-PM", "who":3, "room":36, "status":"denied"},
#{"when":"2020-04-05-PM", "who":4, "room":37, "status":"pending"},
#{"when":"2020-04-05-PM", "who":4, "room":40, "status":"pending"},
#]

for bk in bookings:
    b = Booking(when=bk["when"],
                who=bk["who"],
                room=bk["room"],
                status=bk["status"])
    b.save()
Exemplo n.º 8
0
def create_booking(who, when, room_id):
    new_booking = Booking(who=who, when=when, room=room_id)
    new_booking.save()
    return new_booking.id