Пример #1
0
def page_reservation_wizard_3_search_existing_guest():
    '''
    The user has selected to search for an existing guest.
    Display the results of the search and allow the selection of one.

    TODO: Also have an option for making a new guest in case the user
    doesn't find the guest they were looking for.
    '''
    from RoomReserve.admin.guestsearch import guestsearch, form_SearchGuest
    form = form_SearchGuest()

    formdata = request.form
    myResID = int(formdata['resID'])
    # myRes = getReservationByID(int(formdata['resID']))
    print("___+++___previous information processed")

    guests = getAllGuests()

    return render('guestsearch.html', resID=myResID, form=form, target="/res/new/guest/search", guests=guests)
Пример #2
0
def page_newres():

  def pullAvailableRooms(itemlist):

    [capacity, indatey, indatem, indated, outdatey, outdatem, outdated] = itemlist

    indate = str(indatey) + "/" +  str(indatem) + "/" +  str(indated)
    outdate = str(outdatey) + "/" +  str(outdatem) + "/" +  str(outdated)
    indate = delorean.parse(indate).naive()
    outdate = delorean.parse(outdate).naive()

    availableRooms = find_available_rooms(indate, outdate, capacity=capacity)

    return availableRooms

  def allowEdit():
    '''
    Figures out if the current user should be allowed
    to edit the guest object.
    Parameters: GuestID for the guest we want to edit
    '''
    if current_user.is_standard():
      # Only admins and standard users can edit guests
      return True
    else:
      return False
      
  if request.method == 'POST' and 'roomID' in request.form:
    formdata = request.form
    try:
      res = getReservationByID(int(formdata['resID']))
      res.setRoom(formdata['roomID'])
    except:
      return render("basic.html", content="Could not set room")
    return render("newReservation.html", pullAvailableRooms=pullAvailableRooms, getGuest=getGuest, allowEdit=allowEdit, guests=getAllGuests(), form=NewGuestForm(), successpage=True)

  if request.method == 'POST' and 'dates' in request.form:
    formdata = request.form
    indate = formdata['dates'].split()[0].split('/')
    indate = indate[2] + '/' + indate[1] + '/' + indate[0] 
    outdate = formdata['dates'].split()[2].split('/')
    outdate = outdate[2] + '/' + outdate[1] + '/' + outdate[0] 
    if formdata['capacity'] == "":
        capacity = 1
    else:
        capacity = int(formdata['capacity'])

    indate = delorean.parse(indate).naive()
    outdate = delorean.parse(outdate).naive()


    #availableRooms = find_available_rooms(indate, outdate, capacity=capacity)
    if formdata['newguestfirst'] != "" and formdata['newguestfirst'] != None:
      if formdata['guestID'] != "" and formdata['guestID'] != None:
        return render("basic.html", content="Tried to create new guest and use existing guest in same instance.")
      else:
        try:
          firstname = formdata['newguestfirst']
          lastname = formdata['newguestlast']
          email = formdata['newguestemail']

          phone = re.sub(r'[^\w]', '', formdata['newguestphone'])
          phone = int(phone)

          address = formdata['newguestaddress']

          payment = re.sub(r'[^\w]', '', formdata['newguestpayment'])
          try:
              payment = int(payment)
          except ValueError:
              payment = 0

          notes = formdata['newguestnotes']
        except Exception as e:
          print(e)
          return render("basic.html", content="An issue with new guest data occured.")

        myguest = createGuest(firstname, lastname, email, phone, address, payment, notes)
        if myguest == False:
          return render("basic.html", content="Could not create guest.")
        myguestid = myguest.get_id()
    elif formdata['guestID'] != "" and formdata['guestID'] != None:
      myguestid = int(formdata['guestID'])
      print("Got the guest (existing)")

    else:
      return render("basic.html", content="No guest selected")


    if 'roomselect' in formdata.keys():
      firstroom = find_first_available_room(indate, outdate, capacity=capacity)
      if firstroom == None:
        return render("basic.html", content="No rooms are available for selected capacity and date range. Try a different date range or try splitting the group into multiples.")
      else:
        firstroomid = firstroom.getID()
      try:
        createReservation(guestID=myguestid, madeby=current_user.getID(), roomID=firstroomid, checkin=indate, checkout=outdate, status=CONST.unarrived_status)
      except:
        return render("basic.html", content="Could not complete reservation")

    else:
      availableRooms = find_available_rooms(indate, outdate, capacity=capacity)
      
      if len(availableRooms) == 0:
        return render("basic.html", content="No rooms are available for selected capacity and date range. Try a different date range or try splitting the group into multiples.")
      try:
        myres = createReservation(guestID=myguestid, madeby=current_user.getID(), roomID=-1, checkin=indate, checkout=outdate, status=CONST.draft_status)
      except:
        return render("basic.html", content="Could not complete draft reservation")

      return render("roompick.html", resID = myres.getID(), rooms=availableRooms)
    return render("newReservation.html", pullAvailableRooms=pullAvailableRooms, getGuest=getGuest, allowEdit=allowEdit, guests=getAllGuests(), form=NewGuestForm(), successpage=True)


  return render("newReservation.html", pullAvailableRooms=pullAvailableRooms, getGuest=getGuest, allowEdit=allowEdit, guests=getAllGuests(), form=NewGuestForm())