def booking(request): if request.method == 'POST': form = ReservationForm(request.POST) if form.is_valid(): email = form.cleaned_data['email'].lower() email_liste = [] for each in Guest.objects.all(): if each.email is not None: email_liste.append(each.email.lower()) if email not in email_liste: guest = Guest(email=email, first_name=form.cleaned_data['first_name'], last_name=form.cleaned_data['last_name']) guest.save() else: guest = Guest.objects.all().get(email=email) success = make_reservation(Restaurant.objects.first(), guest, form.cleaned_data['start_date_time'], form.cleaned_data['number_of_people'], 0, reminder=form.cleaned_data['reminder']) if success: send_confirmation( guest, Reservation.objects.all().get(id=success['reservation'])) return render(request, 'reservations/success.html') else: return render(request, 'not_success.html') else: form = ReservationForm() return render(request, 'booking.html', {'form': form})
def res_update(request,id): res_target = get_object_or_404(Res, pk=id) form = ReservationForm(request.POST or None , instance=res_target) if form.is_valid(): res_time_in = list(range(int(request.POST.get('starttime')), int(request.POST.get('endtime')) + 1 )) res_duplicate = Res.objects.filter( Q(arrdate=request.POST.get('arrdate')), Q(roomid=request.POST.get('roomid')), Q(starttime__in=(res_time_in)) | Q(endtime__in=(res_time_in)) ).exclude(pk=id).count() if res_duplicate >= 1: messages.error(request, 'There is already reservation exists') return HttpResponseRedirect(request.path_info) else: messages.info(request,' reservation has been updated') form.save() return redirect('res:list', slug=res_target.arrdate) tester = '' for target_list in res_target.products.values_list('id', flat=True): tester += str(target_list) + ',' context = { 'form': form, 'res_id': id, 'customer': res_target.customerid.name, 'customerid': res_target.customerid.id, 'products': ','.join(list(res_target.products.values_list('name', flat=True))), 'productsid': tester, } return render(request, 'reservation/res_update.html', context)
def edit_reservation(request, reservation_id): if request.POST: if Reservation.objects.filter(pk=reservation_id).exists(): instance = Reservation.objects.get(pk=reservation_id) form = ReservationForm(request.POST, instance=instance) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('reservation', args=(reservation_id,))) else: return HttpResponseNotFound( '<h2>Reservation Not Found</h2>' ) else: if Reservation.objects.filter(pk=reservation_id).exists(): instance = Reservation.objects.get(pk=reservation_id) form = ReservationForm(instance=instance) else: return HttpResponseNotFound( '<h2>Reservation Not Found</h2>' ) args = {} args['form'] = form args['reservation_id'] = reservation_id return render(request, 'reservations/edit_reservation.html', args)
def reservations(request: HttpRequest): if request.method == 'POST': form = ReservationForm(request.POST) else: form = ReservationForm() variables = {'reservations': __fetch_all_reservations(), 'form': form} return render(request, 'list.html', variables)
def new_reservation(request: HttpRequest): if request.method == 'POST': form = ReservationForm(request.POST) if form.is_valid(): __save_new_reservation(form.cleaned_data) return redirect('reservations') else: return reservations(request)
def make_reservation(request): if request.POST: form = ReservationForm(request.POST) if form.is_valid():# else what? form.save() return HttpResponseRedirect(reverse('reservations')) else: form = ReservationForm() args = {} args.update(csrf(request)) args['form'] = form return render(request, 'reservations/make_reservation.html', args)
def testGraphQLRepresentation(self): show = Schedule.available.first() frm = ReservationForm(initial={'show': show}) fieldsList = frm.get_graphql_fields_representation() query = """ { fields { id type value label helpText disabled required customErrorMessages {valueMissing typeMismatch} options {label value} } } """ result = make_graphql_query(query, fieldsList) self.assertEqual(len(result.errors), 0, "Query is successfull")
def reserve(request): if request.method == 'POST': form = ReservationForm(request.POST) if form.is_valid(): reservation = form.save() emails = [rne.email for rne in ReservationNotificationEmail.objects.all()] send_mail("New Groundup Reservation", "Item: %s \n Name: %s \n Quantity: %d" % (reservation.item, reservation.pickup_name, reservation.quantity), "*****@*****.**", emails) return render_to_response('reservations/complete.html', {'reservation': reservation}) else: form = ReservationForm() return render_to_response('reservations/reserve.html', {'form': form}, context_instance=RequestContext(request))
def get(self, request): context = { 'title': 'Ansatt', 'form': DateForm( initial={ 'reservation_date': datetime(datetime.now().year, datetime.now().month, datetime.now().day) }), 'reservations': showRes( request, datetime.strftime( datetime(datetime.now().year, datetime.now().month, datetime.now().day), '%Y-%m-%d')), 'time_range': range(12, 24), 'reservationForm': ReservationForm(), 'walkinForm': WalkinForm(), } return render(request, self.template_name, context)
def res_create(request,): initial_data = {} initial_data['starttime'] = request.GET.get('time') initial_data['roomid'] = request.GET.get('table') initial_data['arrdate'] = request.GET.get('date') form = ReservationForm(request.POST or None, initial = initial_data) if form.is_valid(): if int(request.POST.get('starttime')) >= int(request.POST.get('endtime')): messages.error(request,' the end time should be higher than the start time') return HttpResponseRedirect(request.path_info) instance = form.save(commit=False) print(request.user, ' request.user') instance.user = request.user res_time_in = list(range(int(request.POST.get('starttime')), int(request.POST.get('endtime')) + 1 )) res_duplicate = Res.objects.filter( Q(arrdate=request.POST.get('arrdate')), Q(roomid=request.POST.get('roomid')), Q(starttime__in=(res_time_in)) | Q(endtime__in=(res_time_in)) ).count() if res_duplicate >= 1: messages.error(request,' the room is occupied') else: messages.info(request,' reservation has been created') instance.save() form.save_m2m() context = { 'form': form, } return redirect('res:list', slug=request.POST.get('arrdate') ) context = { 'form': form, } return render(request, 'reservation/res_create.html', context)
def testCheckedTermsAndConditions(self): data = { 'first_name': 'Sander', 'last_name': 'Lindberg', 'email': '*****@*****.**', 'number_of_people': '3', 'start_date': '2019-04-06', 'start_time': '12:00', 'i_have_read_and_agree_checkbox': False } form = ReservationForm(data=data) self.assertFalse(form.is_valid()) data = { 'first_name': 'Sander', 'last_name': 'Lindberg', 'email': '*****@*****.**', 'number_of_people': '3', 'start_date': '2019-04-06', 'start_time': '12:00', 'i_have_read_and_agree_checkbox': True } form = ReservationForm(data=data) self.assertTrue(form.is_valid())
def booking(request): form = ReservationForm(request.POST) if form.is_valid(): email = form.cleaned_data['email'].lower() email_liste = [] for each in Guest.objects.all(): if each.email is not None: email_liste.append(each.email.lower()) if email not in email_liste: guest = Guest(email=email, first_name=form.cleaned_data['first_name'], last_name=form.cleaned_data['last_name']) guest.save() else: guest = Guest.objects.all().get(email=email) start_date = form.cleaned_data['start_date'] start_time = datetime.strptime(str(form.cleaned_data['start_time']), "%H:%M").time() start_date_time = datetime.combine(start_date, start_time) success = make_reservation(Restaurant.objects.first(), guest, start_date_time, form.cleaned_data['number_of_people'], 0, reminder=form.cleaned_data['reminder']) if success: send_confirmation( guest, Reservation.objects.all().get(id=success['reservation'])) return True else: return False else: form = ReservationForm() return render(request, 'newwalkin.html', {'form': form})
def reservation_view(request, pk): if request.is_ajax(): info_pk = request.GET.get('info') info = get_object_or_404(ReservationInfo, pk=info_pk) data = { "max_party": info.acceptable_size_of_party, } return JsonResponse(data) if request.method == 'GET': try: date = request.GET.get('date') restaurant = Restaurant.objects.get(pk=pk) form = ReservationForm(restaurant, date) context = { 'restaurant': restaurant, 'form': form, } return render(request, 'reservation/reservation.html', context) except ParseError: raise Http404 else: restaurant = Restaurant.objects.get(pk=pk) information_pk = request.POST.get('information') information = get_object_or_404(ReservationInfo, pk=information_pk) name = request.POST.get('name') party = int(request.POST.get('party')) phone_number = request.POST.get('phone_number') email = request.POST.get('email') price = information.price * party context = { 'restaurant': restaurant, 'information': information, 'name': name, 'party': party, 'phone_number': phone_number, 'email': email, 'price': price, 'information_pk': information_pk, } return render(request, 'reservation/check.html', context)
def reservation_create(request, slug): appartment = Appartment.objects.get(slug=slug) if request.method == "POST": form = ReservationForm(request.POST) if form.is_valid(): reservation = form.save(commit=False) reservation.appartment = appartment reservation.save() messages.success(request, "Your demand has been sent to the landlord") return redirect('appartment-detail', slug=appartment.slug) else: form = ReservationForm() return render(request, "reservation_create.html", { "appartment": appartment, "form": form })
def testFormCreatesReservation(self): jane = MockData.users['jane'] show = Schedule.objects.first() seatings = { 'seating_adult': 0, 'seating_child': 0, } form = ReservationForm({**jane, **{'show': show.pk}, **seatings}, ) form.show = show if not form.is_valid(): log.debug(form.errors.as_data()) self.assertTrue(form.is_valid(), "Form is valid") reservation = form.save() self.assertEqual( reservation.show, show, "Show set right", ) self.assertEqual(reservation.first_name, jane['first_name'], "User name set right")
def post(self, request, date=datetime.now()): context = { 'title': 'Ansatt', 'form': DateForm( initial={ 'reservation_date': datetime(datetime.now().year, datetime.now().month, datetime.now().day) }), 'reservations': showRes( request, datetime.strftime( datetime(datetime.now().year, datetime.now().month, datetime.now().day), '%Y-%m-%d')), 'time_range': range(12, 24), 'reservationForm': ReservationForm(), 'walkinForm': WalkinForm(), } if request.POST.get('showRes') == 'showRes': date = request.POST.get('reservation_date').split(' ') day = date[1][0:2] month = MONTHS[date[2]] year = date[-1] full_date = year + "-" + month + "-" + day context['reservations'] = showRes(request, full_date) context['form'] = DateForm( initial={ 'reservation_date': request.POST.get('reservation_date') }) return render(request, self.template_name, context) elif request.POST.get('booking') == 'booking': if booking(request): messages.success(request, 'Reservasjonen ble registrert') context['reservations'] = showRes( request, datetime.strftime( datetime(datetime.now().year, datetime.now().month, datetime.now().day), '%Y-%m-%d')) return render(request, self.template_name, context) else: messages.warning(request, 'Reservasjonen ble ikke registrert') return render(request, self.template_name, context) elif request.POST.get('walkin') == 'walkin': if walkin(request): messages.success(request, 'Walkin ble registrert') context['reservations'] = showRes( request, datetime.strftime( datetime(datetime.now().year, datetime.now().month, datetime.now().day), '%Y-%m-%d')) return render(request, self.template_name, context) else: messages.warning(request, 'Walkin ble ikke registrert') return render(request, self.template_name, context) else: messages.warning(request, 'Det er noe galt med utfyllingen av feltene') return render(request, self.template_name, context)
def guest_page(request): if request.method == 'POST': reservation_form = ReservationForm(request.POST) if reservation_form.is_valid(): email = reservation_form.cleaned_data['email'].lower() email_liste = [] for guestobj in Guest.objects.all(): if guestobj.email is not None: email_liste.append(guestobj.email.lower()) if email not in email_liste: guest = Guest( email=email, first_name=reservation_form.cleaned_data['first_name'], last_name=reservation_form.cleaned_data['last_name']) guest.save() else: guest = Guest.objects.all().get(email=email) if reservation_form.is_valid(): start_date = reservation_form.cleaned_data['start_date'] start_time = datetime.strptime( str(reservation_form.cleaned_data['start_time']), "%H:%M").time() start_date_time = datetime.combine(start_date, start_time) success = make_reservation( Restaurant.objects.first(), guest, start_date_time, reservation_form.cleaned_data['number_of_people'], False, reminder=reservation_form.cleaned_data['reminder']) if success: send_confirmation( guest, Reservation.objects.all().get( id=success['reservation'])) messages.success(request, 'Reservasjonen din er registrert') reservation_form = ReservationForm() return render(request, 'guestpage.html', {'form': reservation_form}) else: messages.warning(request, 'Noe gikk galt. Vennligst prøv igjen') reservation_form = ReservationForm() return render(request, 'guestpage.html', {'form': reservation_form}) else: messages.error(request, 'Det er noe galt med utfyllingen av feltene') reservation_form = ReservationForm() return render(request, 'guestpage.html', {'form': reservation_form}) else: reservation_form = ReservationForm() return render(request, 'guestpage.html', {'form': reservation_form})