On Sunday, September 23, 2018 at 12:33:39 AM UTC-7, mostwanted wrote:
>
> I am trying to use the first method but i am failing to get the desired 
> results, how do i check the availability of the selected and wanted room??
> This is my controller code but i figured it not gonna give me results even 
> when i started writing it:
>
> *CONTROLLER:*
>
>
>
>
>
>
>
>
>
>
>
> *def index():    form=SQLFORM(db.rooms)    if form.accepts(request.vars, 
> session):        space=db(db.rooms).select(db.rooms.ALL)        for sp in 
> space:            if sp.vailable==True:                response.flash = 
> T("CLIENT BOOKED")            elif sp.vailable==False:                
> db.rollback()                response.flash = T("FAILED")    return 
> locals();*
>
> *MODEL*
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *db.define_table('client',                Field('Name'),                
> Field('Surname'),                Field('age'),              
>  format='%(Name)s')db.define_table('room_numbers',                
> Field('room'),                format='%(room)s')db.define_table('rooms',    
>             #Field('room_number'),                Field('room', 'reference 
> room_numbers'),                Field('available', 'boolean'),              
>   Field('occupant', 'reference client'))*
>
>
The typo on 'available' is only in the email, I hope.

I don't see why you split room numbers away from the rooms, but maybe it 
fits other parts of your business logic.

 Instead of sending all the rooms to the client (via the SQLFORM() call), I 
would only send the available rooms.   I don't see how to filter SQLFORM() 
directly, but you can use SQLTABLE() to show a list that has links, rather 
than using a dropdown and a submit button.
(You can do even better by searching the group archives for 'datatable', 
which is a 3rd party javascript tool.  There are a couple others 
available.  I don't know if Massimo's Aug '17 promise of a vue.js example 
is available yet.)

This is untested, and my notes at home might have something cleverer, but 
consider this:

(controllers/myhotel.py)
define showempties():
          empties = db(db.rooms.available == T).select(db.rooms.room, db.
rooms.available)
          
          # append a url to each entry.  There may be more efficient ways 
of doing this if empties has lotsa entries,
          # but for a hundred entries this might not be too bad.
          for empty in empties:
                 empty["choose"] = A(T("assign"), _href=URL("assignroom", 
args=dict(room=empty.id)))

          return dict(rooms=empties)

define assignroom():
          roomid = request.vars.room
          room = db.rooms[roomid]
          if not room or not room.available:
               raise HTTP(409, "room unavallable")
          form = SQLFORM(db.client)
          if form.process().accepted:
               db(db.rooms.id == roomid).update(available=F, client = form.
vars.id)
               response.flash = "%s booked room %d" % (form.vars.name, db.
room[room.room])
          else:
               response.flash = "error in client form"
          return dict(form = form)



(views/myhotel/showempties)
{{extend 'layout.html'}}
<h1>Available Rooms</h1>
<style>
    *.odd {background-color: #ddffcc}  /* light green-bar */
</style>
{{=SQLTBLE(rooms, truncate = 25, headers = {'room.room': 'room', 
'room.available': 'available'}) }}


Simplistic, but I hope it helps.

/dps

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to