[web2py] Re: record representation format that refer to another table and that table is refer to another table

2019-04-24 Thread Ray (a.k.a. Iceberg)
I know I'm late to the party, but I have to write to thank Anthony for 
sharing such a wonderful trick!

One more thing, I happen to also discover that we do not have to use 
lambda. The following form is less verbose, more intuitive.

db.define_table('room',
Field('room_no'),
Field('category', 'list:string'),
Field('status', 'list:string'),
Field('branch', 'reference branch'),
format='%(branch.address) %(room_no)s')

Thanks everyone, especially Massimo for building such an amazingly flexible 
web2py!

Regards,
Ray

On Saturday, March 23, 2013 at 6:48:59 AM UTC-7, Anthony wrote:
>
> Oh, yeah, even better, you can make the "format" attribute a function (it 
> takes a record of its own table) -- so:
>
> db.define_table('room',
> Field('room_no'),
> Field('category', 'list:string'),
> Field('status', 'list:string'),
> Field('branch', 'reference branch'),
> format=lambda r: '%s %s' % (r.branch.address, r.room_no))
>
> Anthony
>
> On Saturday, March 23, 2013 1:41:38 AM UTC-4, 黄祥 wrote:
>>
>> just curious, is it possible to add the format function in the table room?
>>
>>
>>
>>
>>

-- 
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.


[web2py] Re: record representation format that refer to another table and that table is refer to another table

2013-03-23 Thread 黄祥
it works, many thanks, anthony
>
>

-- 

--- 
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/groups/opt_out.




[web2py] Re: record representation format that refer to another table and that table is refer to another table

2013-03-23 Thread Anthony
Oh, yeah, even better, you can make the "format" attribute a function (it 
takes a record of its own table) -- so:

db.define_table('room',
Field('room_no'),
Field('category', 'list:string'),
Field('status', 'list:string'),
Field('branch', 'reference branch'),
format=lambda r: '%s %s' % (r.branch.address, r.room_no))

Anthony

On Saturday, March 23, 2013 1:41:38 AM UTC-4, 黄祥 wrote:
>
> just curious, is it possible to add the format function in the table room?
>
> *e.g. 1. no error but the result is not expected*
> db.define_table('room',
> Field('room_no'),
> Field('category', 'list:string'),
> Field('status', 'list:string'),
> Field('branch', 'reference branch'),
> format=lambda r: format_room)
>
> db.define_table('booking',
> Field('scheduled_start', 'datetime'),
> Field('due_date', 'datetime'),
> Field('room', 'reference room'),
> Field('guest', 'reference guest'),
> Field('description', 'text'),
> format='%(scheduled_start)s %(guest)s %(room)s')
>
> my view is return :
> 
>
> *e.g. 2. got an error*
> db.define_table('room',
> Field('room_no'),
> Field('category', 'list:string'),
> Field('status', 'list:string'),
> Field('branch', 'reference branch'),
> format=lambda r: format_room(r.room))
>
> db.define_table('booking',
> Field('scheduled_start', 'datetime'),
> Field('due_date', 'datetime'),
> Field('room', 'reference room'),
> Field('guest', 'reference guest'),
> Field('description', 'text'),
> format='%(scheduled_start)s %(guest)s %(room)s')
> Traceback
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
> 11.
> 12.
> 13.
> 14.
> 15.
> 16.
> 17.
> 18.
> 19.
> 20.
>
> Traceback (most recent call last):
>   File "/host/Downloads/web2py/gluon/restricted.py", line 212, in restricted
> exec ccode in environment
>   File "/host/Downloads/web2py/applications/hotel/controllers/default.py" 
> , line 
> 187, in 
>   File "/host/Downloads/web2py/gluon/globals.py", line 194, in 
> self._caller = lambda f: f()
>   File "/host/Downloads/web2py/gluon/tools.py", line 2971, in f
> return action(*a, **b)
>   File "/host/Downloads/web2py/applications/hotel/controllers/default.py" 
> , line 
> 99, in booking
> editable=has_membership, deletable=has_membership)
>   File "/host/Downloads/web2py/gluon/sqlhtml.py", line 2296, in grid
> value = field.represent(value, row)
>   File "/host/Downloads/web2py/gluon/dal.py", line 6673, in repr_ref
> def repr_ref(id, row=None, r=referenced, f=ff): return f(r, id)
>   File "/host/Downloads/web2py/gluon/dal.py", line 6650, in ff
> return r._format(row)
>   File "/host/Downloads/web2py/applications/hotel/models/db_wizard.py" 
> , line 
> 39, in 
> format=lambda r: format_room(r.room))
> AttributeError: 'Row' object has no attribute 'room'
>
>
> *e.g. 3. got an error*
> db.define_table('room',
> Field('room_no'),
> Field('category', 'list:string'),
> Field('status', 'list:string'),
> Field('branch', 'reference branch'),
> format=lambda id, r: format_room(r.room))
>
> db.define_table('booking',
> Field('scheduled_start', 'datetime'),
> Field('due_date', 'datetime'),
> Field('room', 'reference room'),
> Field('guest', 'reference guest'),
> Field('description', 'text'),
> format='%(scheduled_start)s %(guest)s %(room)s')
> Traceback
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
> 11.
> 12.
> 13.
> 14.
> 15.
> 16.
> 17.
> 18.
>
> Traceback (most recent call last):
>   File "/host/Downloads/web2py/gluon/restricted.py", line 212, in restricted
> exec ccode in environment
>   File "/host/Downloads/web2py/applications/hotel/controllers/default.py" 
> , line 
> 187, in 
>   File "/host/Downloads/web2py/gluon/globals.py", line 194, in 
> self._caller = lambda f: f()
>   File "/host/Downloads/web2py/gluon/tools.py", line 2971, in f
> return action(*a, **b)
>   File "/host/Downloads/web2py/applications/hotel/controllers/default.py" 
> , line 
> 99, in booking
> editable=has_membership, deletable=has_membership)
>   File "/host/Downloads/web2py/gluon/sqlhtml.py", line 2296, in grid
> value = field.represent(value, row)
>   File "/host/Downloads/web2py/gluon/dal.py", line 6673, in repr_ref
> def repr_ref(id, row=None, r=referenced, f=ff): return f(r, id)
>   File "/host/Downloads/web2py/gluon/dal.py", line 6650, in ff
> return r._format(row)
> TypeError: () takes exactly 2 arguments (1 given)
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and st

[web2py] Re: record representation format that refer to another table and that table is refer to another table

2013-03-22 Thread 黄祥
just curious, is it possible to add the format function in the table room?

*e.g. 1. no error but the result is not expected*
db.define_table('room',
Field('room_no'),
Field('category', 'list:string'),
Field('status', 'list:string'),
Field('branch', 'reference branch'),
format=lambda r: format_room)

db.define_table('booking',
Field('scheduled_start', 'datetime'),
Field('due_date', 'datetime'),
Field('room', 'reference room'),
Field('guest', 'reference guest'),
Field('description', 'text'),
format='%(scheduled_start)s %(guest)s %(room)s')

my view is return :


*e.g. 2. got an error*
db.define_table('room',
Field('room_no'),
Field('category', 'list:string'),
Field('status', 'list:string'),
Field('branch', 'reference branch'),
format=lambda r: format_room(r.room))

db.define_table('booking',
Field('scheduled_start', 'datetime'),
Field('due_date', 'datetime'),
Field('room', 'reference room'),
Field('guest', 'reference guest'),
Field('description', 'text'),
format='%(scheduled_start)s %(guest)s %(room)s')
Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.

Traceback (most recent call last):
  File "/host/Downloads/web2py/gluon/restricted.py", line 212, in restricted
exec ccode in environment
  File "/host/Downloads/web2py/applications/hotel/controllers/default.py" 
, line 
187, in 
  File "/host/Downloads/web2py/gluon/globals.py", line 194, in 
self._caller = lambda f: f()
  File "/host/Downloads/web2py/gluon/tools.py", line 2971, in f
return action(*a, **b)
  File "/host/Downloads/web2py/applications/hotel/controllers/default.py" 
, line 
99, in booking
editable=has_membership, deletable=has_membership)
  File "/host/Downloads/web2py/gluon/sqlhtml.py", line 2296, in grid
value = field.represent(value, row)
  File "/host/Downloads/web2py/gluon/dal.py", line 6673, in repr_ref
def repr_ref(id, row=None, r=referenced, f=ff): return f(r, id)
  File "/host/Downloads/web2py/gluon/dal.py", line 6650, in ff
return r._format(row)
  File "/host/Downloads/web2py/applications/hotel/models/db_wizard.py" 
, line 39, 
in 
format=lambda r: format_room(r.room))
AttributeError: 'Row' object has no attribute 'room'


*e.g. 3. got an error*
db.define_table('room',
Field('room_no'),
Field('category', 'list:string'),
Field('status', 'list:string'),
Field('branch', 'reference branch'),
format=lambda id, r: format_room(r.room))

db.define_table('booking',
Field('scheduled_start', 'datetime'),
Field('due_date', 'datetime'),
Field('room', 'reference room'),
Field('guest', 'reference guest'),
Field('description', 'text'),
format='%(scheduled_start)s %(guest)s %(room)s')
Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.

Traceback (most recent call last):
  File "/host/Downloads/web2py/gluon/restricted.py", line 212, in restricted
exec ccode in environment
  File "/host/Downloads/web2py/applications/hotel/controllers/default.py" 
, line 
187, in 
  File "/host/Downloads/web2py/gluon/globals.py", line 194, in 
self._caller = lambda f: f()
  File "/host/Downloads/web2py/gluon/tools.py", line 2971, in f
return action(*a, **b)
  File "/host/Downloads/web2py/applications/hotel/controllers/default.py" 
, line 
99, in booking
editable=has_membership, deletable=has_membership)
  File "/host/Downloads/web2py/gluon/sqlhtml.py", line 2296, in grid
value = field.represent(value, row)
  File "/host/Downloads/web2py/gluon/dal.py", line 6673, in repr_ref
def repr_ref(id, row=None, r=referenced, f=ff): return f(r, id)
  File "/host/Downloads/web2py/gluon/dal.py", line 6650, in ff
return r._format(row)
TypeError: () takes exactly 2 arguments (1 given)

-- 

--- 
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/groups/opt_out.




[web2py] Re: record representation format that refer to another table and that table is refer to another table

2013-03-22 Thread 黄祥
very nice, it's work well, thank you so much for your hints, anthony.
just want to share the code that you've guide.

def format_room(record):
return '%s-%s' % (record.branch.address, record.room_no)

def format_booking(record):
return '%s-%s %s-%s-%s' % (record.scheduled_start, 
record.guest.first_name,
   record.guest.last_name, 
record.room.branch.address, 
   record.room.room_no)

db.define_table('booking',
Field('scheduled_start', 'datetime'),
Field('due_date', 'datetime'),
Field('room', 'reference room', represent=lambda id, r: 
format_room(r.room)),
Field('guest', 'reference guest'),
Field('description', 'text'),
format='%(scheduled_start)s %(guest)s %(room)s')

db.define_table('check_in',
Field('is_booking', 'boolean'),
Field('booking', 'reference booking', represent=lambda id, r: 
format_booking(r.booking)),
Field('room', 'reference room', represent=lambda id, r: 
format_room(r.room)),
Field('guest', 'reference guest'),
Field('description', 'text'),
format='%(guest)s %(room)s')

db.booking.scheduled_start.requires=IS_NOT_EMPTY()
db.booking.due_date.requires=IS_NOT_EMPTY()
db.booking.room.requires=IS_IN_DB(db(db.room.status=='Available'), 
db.room.id, 
 label=format_room)
db.booking.guest.requires=IS_IN_DB(db, db.guest.id, 
   '%(first_name)s %(last_name)s')
db.booking.description.requires=IS_NOT_EMPTY()

db.check_in.booking.requires=IS_EMPTY_OR(IS_IN_DB(db(db.booking.is_active==True),
 
  db.booking.id, 
label=format_booking))
db.check_in.room.requires=IS_EMPTY_OR(IS_IN_DB(db(db.room.status=='Available'), 
   db.room.id, 
label=format_room))
db.check_in.guest.requires=IS_EMPTY_OR(IS_IN_DB(db, db.guest.id, 
'%(first_name)s 
%(last_name)s'))
db.check_in.description.requires=IS_NOT_EMPTY()

-- 

--- 
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/groups/opt_out.




[web2py] Re: record representation format that refer to another table and that table is refer to another table

2013-03-22 Thread Anthony
Sorry, wasn't thinking -- the validator is selecting a record from the 
"room" table, not the "booking" table, so you'll need a slightly different 
function for that:

IS_IN_DB(..., label=lambda r: '%s %s' % (r.branch.address, r.room_no))

or if want to use a single function (not tested):

def format_room(record):
return '%s %s' % (record.branch.address, record.room_no)
...
Field('room', 'reference room', requires=IS_IN_DB(..., label=format_record),
  represent=lambda id, r: format_record(r.room))

Anthony

On Friday, March 22, 2013 2:14:31 AM UTC-4, 黄祥 wrote:
>
> thank you so much for your hint, anthony, but when i test it both of it 
> return an error, any idea about this?
>
> IS_IN_DB(db(db.room.status=='Available'), db.room.id, 
>  label=lambda r: '%s %s' % (r.room.branch.address, r.room.room_no))
> Traceback
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
> 11.
> 12.
> 13.
> 14.
> 15.
> 16.
> 17.
> 18.
> 19.
> 20.
> 21.
> 22.
>
> Traceback (most recent call last):
>   File "/home/stifank/Desktop/web2py/gluon/restricted.py", line 212, in 
> restricted
> exec ccode in environment
>   File 
> "/home/stifank/Desktop/web2py/applications/hotel/controllers/default.py" 
> , 
> line 181, in 
>   File "/home/stifank/Desktop/web2py/gluon/globals.py", line 194, in 
> self._caller = lambda f: f()
>   File "/home/stifank/Desktop/web2py/gluon/tools.py", line 2971, in f
> return action(*a, **b)
>   File 
> "/home/stifank/Desktop/web2py/applications/hotel/controllers/default.py" 
> , 
> line 99, in booking
> editable=has_membership, deletable=has_membership)
>   File "/home/stifank/Desktop/web2py/gluon/sqlhtml.py", line 2084, in grid
> search_menu = SQLFORM.search_menu(sfields, prefix=prefix)
>   File "/home/stifank/Desktop/web2py/gluon/sqlhtml.py", line 1663, in 
> search_menu
> for k,v in field.requires.options()],
>   File "/home/stifank/Desktop/web2py/gluon/validators.py", line 545, in 
> options
> self.build_set()
>   File "/home/stifank/Desktop/web2py/gluon/validators.py", line 542, in 
> build_set
> self.labels = [self.label(r) for r in records]
>   File 
> "/home/stifank/Desktop/web2py/applications/hotel/models/db_wizard_requires.py"
>  
> ,
>  line 57, in 
> label=lambda r: '%s %s' % (r.room.branch.address, r.room.room_no))
> AttributeError: 'Row' object has no attribute 'room'
>
>
> put in db.py
> def format_room(record):
> return '%s %s' % (record.room.branch.address, record.room.room_no)
>
>
> Traceback
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
> 11.
> 12.
> 13.
> 14.
> 15.
> 16.
> 17.
> 18.
> 19.
> 20.
> 21.
> 22.
>
> Traceback (most recent call last):
>   File "/home/stifank/Desktop/web2py/gluon/restricted.py", line 212, in 
> restricted
> exec ccode in environment
>   File 
> "/home/stifank/Desktop/web2py/applications/hotel/controllers/default.py" 
> , 
> line 181, in 
>   File "/home/stifank/Desktop/web2py/gluon/globals.py", line 194, in 
> self._caller = lambda f: f()
>   File "/home/stifank/Desktop/web2py/gluon/tools.py", line 2971, in f
> return action(*a, **b)
>   File 
> "/home/stifank/Desktop/web2py/applications/hotel/controllers/default.py" 
> , 
> line 99, in booking
> editable=has_membership, deletable=has_membership)
>   File "/home/stifank/Desktop/web2py/gluon/sqlhtml.py", line 2084, in grid
> search_menu = SQLFORM.search_menu(sfields, prefix=prefix)
>   File "/home/stifank/Desktop/web2py/gluon/sqlhtml.py", line 1663, in 
> search_menu
> for k,v in field.requires.options()],
>   File "/home/stifank/Desktop/web2py/gluon/validators.py", line 545, in 
> options
> self.build_set()
>   File "/home/stifank/Desktop/web2py/gluon/validators.py", line 542, in 
> build_set
> self.labels = [self.label(r) for r in records]
>   File "/home/stifank/Desktop/web2py/applications/hotel/models/db_wizard.py" 
> , line 
> 7, in format_room
> return '%s %s' % (record.room.branch.address, record.room.room_no)
> AttributeError: 'Row' object has no attribute 'room'
>
>
>
>
>
>>>

-- 

--- 
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/groups/opt_out.




[web2py] Re: record representation format that refer to another table and that table is refer to another table

2013-03-21 Thread 黄祥
thank you so much for your hint, anthony, but when i test it both of it 
return an error, any idea about this?

IS_IN_DB(db(db.room.status=='Available'), db.room.id, 
 label=lambda r: '%s %s' % (r.room.branch.address, r.room.room_no))
Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.

Traceback (most recent call last):
  File "/home/stifank/Desktop/web2py/gluon/restricted.py", line 212, in 
restricted
exec ccode in environment
  File "/home/stifank/Desktop/web2py/applications/hotel/controllers/default.py" 
, line 
181, in 
  File "/home/stifank/Desktop/web2py/gluon/globals.py", line 194, in 
self._caller = lambda f: f()
  File "/home/stifank/Desktop/web2py/gluon/tools.py", line 2971, in f
return action(*a, **b)
  File "/home/stifank/Desktop/web2py/applications/hotel/controllers/default.py" 
, line 
99, in booking
editable=has_membership, deletable=has_membership)
  File "/home/stifank/Desktop/web2py/gluon/sqlhtml.py", line 2084, in grid
search_menu = SQLFORM.search_menu(sfields, prefix=prefix)
  File "/home/stifank/Desktop/web2py/gluon/sqlhtml.py", line 1663, in 
search_menu
for k,v in field.requires.options()],
  File "/home/stifank/Desktop/web2py/gluon/validators.py", line 545, in options
self.build_set()
  File "/home/stifank/Desktop/web2py/gluon/validators.py", line 542, in 
build_set
self.labels = [self.label(r) for r in records]
  File 
"/home/stifank/Desktop/web2py/applications/hotel/models/db_wizard_requires.py" 
, 
line 57, in 
label=lambda r: '%s %s' % (r.room.branch.address, r.room.room_no))
AttributeError: 'Row' object has no attribute 'room'


put in db.py
def format_room(record):
return '%s %s' % (record.room.branch.address, record.room.room_no)


Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.

Traceback (most recent call last):
  File "/home/stifank/Desktop/web2py/gluon/restricted.py", line 212, in 
restricted
exec ccode in environment
  File "/home/stifank/Desktop/web2py/applications/hotel/controllers/default.py" 
, line 
181, in 
  File "/home/stifank/Desktop/web2py/gluon/globals.py", line 194, in 
self._caller = lambda f: f()
  File "/home/stifank/Desktop/web2py/gluon/tools.py", line 2971, in f
return action(*a, **b)
  File "/home/stifank/Desktop/web2py/applications/hotel/controllers/default.py" 
, line 
99, in booking
editable=has_membership, deletable=has_membership)
  File "/home/stifank/Desktop/web2py/gluon/sqlhtml.py", line 2084, in grid
search_menu = SQLFORM.search_menu(sfields, prefix=prefix)
  File "/home/stifank/Desktop/web2py/gluon/sqlhtml.py", line 1663, in 
search_menu
for k,v in field.requires.options()],
  File "/home/stifank/Desktop/web2py/gluon/validators.py", line 545, in options
self.build_set()
  File "/home/stifank/Desktop/web2py/gluon/validators.py", line 542, in 
build_set
self.labels = [self.label(r) for r in records]
  File "/home/stifank/Desktop/web2py/applications/hotel/models/db_wizard.py" 
, line 7, 
in format_room
return '%s %s' % (record.room.branch.address, record.room.room_no)
AttributeError: 'Row' object has no attribute 'room'





>>

-- 

--- 
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/groups/opt_out.




[web2py] Re: record representation format that refer to another table and that table is refer to another table

2013-03-21 Thread Anthony
No, IS_IN_DB does not take a "represent" argument, but it does take a 
"label" argument that works similarly (though the lambda takes only a 
single argument -- the record):

IS_IN_DB(db(db.room.status=='Available'), db.room.id, 
 label=lambda r: '%s %s' % (r.room.branch.address, r.room.room_no))

Actually, you can optionally specify the "represent" function to take only 
a single argument as well, so you could just define the function once and 
use it in both places:

def format_room(record):
return '%s %s' % (record.room.branch.address, rrecord.room.room_no)

Then do Field(..., represent=format_room) and IS_IN_DB(..., 
label=format_room).

Anthony

On Friday, March 22, 2013 1:06:22 AM UTC-4, 黄祥 wrote:
>
> it's work well, thank you very much anthony.
> it seems the 'represent' can't work in validators : requires. actually i'm 
> also want the represent format in the form too. when i try to use the 
> represent in requires an error is occured. did you know how to do it in 
> requires field?
>
> when using :
> db.booking.room.requires=IS_IN_DB(db(db.room.status=='Available'), 
> db.room.id, 
>   represent=lambda id, r: '%s %s' % 
> (r.room.branch.address, r.room.room_no))
> Traceback
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
>
> Traceback (most recent call last):
>   File "/home/stifank/Desktop/web2py/gluon/restricted.py", line 212, in 
> restricted
> exec ccode in environment
>   File 
> "/home/stifank/Desktop/web2py/applications/hotel/models/db_wizard_requires.py",
>  line 57, in 
> represent=lambda id, r: '%s %s' % (r.room.branch.address, r.room.room_no))
> TypeError: __init__() got an unexpected keyword argument 'represent'
>
>
>
> when using :
> db.booking.room.requires=IS_IN_DB(db(db.room.status=='Available'), 
> db.room.id, 
>   lambda id, r: '%s %s' % 
> (r.room.branch.address, r.room.room_no))
>
> Traceback
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
> 11.
> 12.
> 13.
> 14.
> 15.
> 16.
> 17.
> 18.
> 19.
> 20.
>
> Traceback (most recent call last):
>   File "/home/stifank/Desktop/web2py/gluon/restricted.py", line 212, in 
> restricted
> exec ccode in environment
>   File 
> "/home/stifank/Desktop/web2py/applications/hotel/controllers/default.py" 
> , 
> line 181, in 
>   File "/home/stifank/Desktop/web2py/gluon/globals.py", line 194, in 
> self._caller = lambda f: f()
>   File "/home/stifank/Desktop/web2py/gluon/tools.py", line 2971, in f
> return action(*a, **b)
>   File 
> "/home/stifank/Desktop/web2py/applications/hotel/controllers/default.py" 
> , 
> line 99, in booking
> editable=has_membership, deletable=has_membership)
>   File "/home/stifank/Desktop/web2py/gluon/sqlhtml.py", line 2084, in grid
> search_menu = SQLFORM.search_menu(sfields, prefix=prefix)
>   File "/home/stifank/Desktop/web2py/gluon/sqlhtml.py", line 1663, in 
> search_menu
> for k,v in field.requires.options()],
>   File "/home/stifank/Desktop/web2py/gluon/validators.py", line 545, in 
> options
> self.build_set()
>   File "/home/stifank/Desktop/web2py/gluon/validators.py", line 542, in 
> build_set
> self.labels = [self.label(r) for r in records]
> TypeError: () takes exactly 2 arguments (1 given)
>
>

-- 

--- 
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/groups/opt_out.




[web2py] Re: record representation format that refer to another table and that table is refer to another table

2013-03-21 Thread 黄祥
it's work well, thank you very much anthony.
it seems the 'represent' can't work in validators : requires. actually i'm 
also want the represent format in the form too. when i try to use the 
represent in requires an error is occured. did you know how to do it in 
requires field?

when using :
db.booking.room.requires=IS_IN_DB(db(db.room.status=='Available'), 
db.room.id, 
  represent=lambda id, r: '%s %s' % 
(r.room.branch.address, r.room.room_no))
Traceback

1.
2.
3.
4.
5.
6.
7.

Traceback (most recent call last):
  File "/home/stifank/Desktop/web2py/gluon/restricted.py", line 212, in 
restricted
exec ccode in environment
  File 
"/home/stifank/Desktop/web2py/applications/hotel/models/db_wizard_requires.py", 
line 57, in 
represent=lambda id, r: '%s %s' % (r.room.branch.address, r.room.room_no))
TypeError: __init__() got an unexpected keyword argument 'represent'



when using :
db.booking.room.requires=IS_IN_DB(db(db.room.status=='Available'), 
db.room.id, 
  lambda id, r: '%s %s' % 
(r.room.branch.address, r.room.room_no))

Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.

Traceback (most recent call last):
  File "/home/stifank/Desktop/web2py/gluon/restricted.py", line 212, in 
restricted
exec ccode in environment
  File "/home/stifank/Desktop/web2py/applications/hotel/controllers/default.py" 
, line 
181, in 
  File "/home/stifank/Desktop/web2py/gluon/globals.py", line 194, in 
self._caller = lambda f: f()
  File "/home/stifank/Desktop/web2py/gluon/tools.py", line 2971, in f
return action(*a, **b)
  File "/home/stifank/Desktop/web2py/applications/hotel/controllers/default.py" 
, line 
99, in booking
editable=has_membership, deletable=has_membership)
  File "/home/stifank/Desktop/web2py/gluon/sqlhtml.py", line 2084, in grid
search_menu = SQLFORM.search_menu(sfields, prefix=prefix)
  File "/home/stifank/Desktop/web2py/gluon/sqlhtml.py", line 1663, in 
search_menu
for k,v in field.requires.options()],
  File "/home/stifank/Desktop/web2py/gluon/validators.py", line 545, in options
self.build_set()
  File "/home/stifank/Desktop/web2py/gluon/validators.py", line 542, in 
build_set
self.labels = [self.label(r) for r in records]
TypeError: () takes exactly 2 arguments (1 given)

-- 

--- 
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/groups/opt_out.




[web2py] Re: record representation format that refer to another table and that table is refer to another table

2013-03-21 Thread Anthony
The "format" attribute does propagate, so you'll have to write your own 
"represent" function for the "room" field (not tested):

Field('room', 'reference room', represent=lambda id, r: '%s %s' % (r.room.
branch.address, r.room.room_no))

The above represent function uses recursive selects, which I think should 
work.

Anthony

On Thursday, March 21, 2013 11:30:34 PM UTC-4, 黄祥 wrote:
>
> hi,
>
> did anyone know how to show record representation format that refer to 
> another table and that table is refer to another table?
>
> e.g.
> *db.py*
> db.define_table('branch',
> Field('address', 'text'),
> Field('zip'),
> Field('city'),
> Field('country'),
> Field('phone'),
> Field('fax'),
> Field('email'),
> Field('company', 'reference company'),
> format='%(address)s')
>
> db.define_table('room',
> Field('room_no'),
> Field('status', 'list:string'),
> Field('branch', 'reference branch'),
> format='%(branch)s %(room_no)s')
>
> db.define_table('booking',
> Field('scheduled_start', 'datetime'),
> Field('due_date', 'datetime'),
> Field('room', 'reference room'),
> Field('customer', 'reference customer'),
> Field('description', 'text'),
> format='%(scheduled_start)s %(customer)s %(room)s')
>
> *my question is:*
> when i select table booking, i want to see : branch address room no (e.g. 
> jakarta 101), notf branch id room no (e.g. 1 101).
>
> many thanks before
>

-- 

--- 
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/groups/opt_out.