def booking_submit(request): if request.method == "POST": form = BookingForm(request.POST) if not request.user.is_authenticated(): return render(request, "booking_submitted.html", {"success":False}) if form.is_valid(): booking = form.save(commit=False) booking.user = request.user # Verify that this booking will not conflict with any others # ie in the same room, with overlapping times # to do this quickly, find all bookings in same room, excluding those with start date after new end date and end date before new start date. This makes sense, I promise... conflicting_bookings = Booking.objects.filter(room=booking.room).exclude(start_date__gte=booking.end_date).exclude(end_date__lte=booking.start_date) print conflicting_bookings if len(conflicting_bookings) > 0: print "conflicts found" return render(request, "booking_submitted.html", {"success":False}) print "no conflicts" booking.save() # block bookings - adds copies of the booking for x number of weeks. TODO conflict res if request.POST['repeat'] == "10times": print "block booking" block_id = uuid.uuid4().int for i in range(1,10): form = BookingForm(request.POST) booking = form.save(commit=False) booking.user = request.user booking.start_date += timedelta(days=7*i) booking.block_booking = block_id booking.save() print booking return render(request, "booking_submitted.html", {"success":True}) return render(request, "booking_submitted.html", {"success":False}) else: return redirect('bookings.views.booking_calendar')
def booking_add(profile_id, day_name, time_value): teachers, booking = read_db() form = BookingForm(request.form) form.clientTeacher.data = profile_id form.clientWeekday.data = day_name form.clientTime.data = time_value if form.validate(): form.save() return redirect('/booking_done') return render_template("booking.html", teacher=teachers[profile_id], day_name=day_name, time_value=time_value, form=form)
def index(request): template = 'booking/index.html' form = BookingForm(request.POST or None) if form.is_valid(): booking = form.save(commit=False) booking.user = request.user booking.save() messages.success(request, "Your booking was completed successfully!") return redirect('/bookings/') context = {'form': form} return render(request, template, context)
def booking_form(request): """ Creation d'un formulaire de reservation """ form = BookingForm(request.POST or None) if form.is_valid(): envoi = True booking = form.save(commit=False) booking.author = request.user.username booking.save() return render(request, 'booking/bookingForm.html', locals())
def post(self, request, *args, **kwargs): try: email_form = EmailForm(request.POST, instance=request.user) phone_form = PhoneForm(request.POST, instance=request.user.profile) booking_form = BookingForm(request.POST) tz = pytz.timezone(settings.TIME_ZONE) my_bookings = Booking.objects.filter( madeBy=request.user, start__gt=datetime.now(tz), app_config=self.config).order_by('start') delete_booking = DeleteBooking(request.POST) except AttributeError: return render(request, 'bookings.html') if email_form.is_valid() and phone_form.is_valid( ) and booking_form.is_valid(): email_form.save() phone_form.save() new_booking = booking_form.save(commit=False) if new_booking.start and new_booking.end: new_booking.app_config = self.config free = Booking.objects.free(new_booking.app_config, new_booking.start, new_booking.end) a_booking_spot = BookingConfig.objects.filter( booking_spots__start__exact=new_booking.start.time(), booking_spots__end__exact=new_booking.end.time()).exists() if free and a_booking_spot: new_booking.made_by = request.user Booking.objects.add_booking(new_booking.app_config, new_booking.name, new_booking.made_by, new_booking.start, new_booking.end) if delete_booking.is_valid(): Booking.objects.filter( id__exact=delete_booking.cleaned_data['id']).delete() return render( request, 'bookings.html', { 'email_form': email_form, 'phone_form': phone_form, 'booking_form': booking_form, 'my_bookings': my_bookings, 'delete_booking': delete_booking })