[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 and lambda

2015-11-16 Thread Anthony Smith
Thanks Anthony, yes there were some typo's my mistakes

On Sunday, 15 November 2015 18:25:01 UTC+11, Anthony Smith wrote:
>
> Hi All,
>
> I have looking though the group for and answer on this, I am try to get 
> the product_name and batch_no from the product table to be the product in 
> the stock task table.
>
> But  getting the following traceback:
>
> Traceback (most recent call last):
>   File "/home/tony/web2py/gluon/restricted.py", line 227, in restricted
> exec ccode in environment
>   File "/home/tony/web2py/applications/cps2d/models/db1.py" 
> , line 112, in 
> 
> db.stock_task.product.requires=IS_IN_DB(db,db.product,lambda record: 
> format_product(record))
>   File "/home/tony/web2py/gluon/packages/dal/pydal/base.py", line 906, in 
> __getattr__
> return super(DAL, self).__getattr__(key)
>   File "/home/tony/web2py/gluon/packages/dal/pydal/helpers/classes.py", line 
> 30, in __getattr__
> raise AttributeError
> AttributeError
>
> Error Snapshot:
>
> ()
>
>
> db.define_table('product',
> Field('product_name'),
> Field(batch_no),
> format=lambda record: format_product(record))
>
> def format_product(record):
> return '%s %s' % (record.product_name, record.batch_no)
>
>
> db.define_table('stock_task',
> Field()
> Field()
> Field('product','list:reference products'),
>
> auth.signature)
>
> db.stock_task.product.requires=IS_IN_DB(db,db.product,lambda record: 
> format_product(record))
>
> any help would be great 
>
> cheers 
> Anthony
>
>
>

-- 
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 and lambda

2015-11-15 Thread Anthony

>
> Traceback (most recent call last):
>   File "/home/tony/web2py/gluon/restricted.py", line 227, in restricted
> exec ccode in environment
>   File "/home/tony/web2py/applications/cps2d/models/db1.py" 
> , line 112, in 
> 
> db.stock_task.product.requires=IS_IN_DB(db,db.product,lambda record: 
> format_product(record))
>   File "/home/tony/web2py/gluon/packages/dal/pydal/base.py", line 906, in 
> __getattr__
> return super(DAL, self).__getattr__(key)
>
>
The attribute error occurs when trying to access an attribute of the DAL 
object (i.e., db), which implies the problem is in the db.product part of 
the code, not anything to do the the lambda. I notice in the code you show, 
you have defined a table called "product", but in the stock_task table, the 
"product" field is defined as "list:reference products". In your real code, 
is the product table defined as "products" rather than "product"? If so, 
that will result in an attribute error when you try db.product.
 

> db.define_table('product',
> Field('product_name'),
> Field(batch_no),
> format=lambda record: format_product(record))
>
>
Also, note that "batch_no" above is not surrounded by quotes -- if that 
were your actual code, that would throw an error before the line you are 
reporting.

In general, if you are showing some variation of your original code, be 
sure to try that exact variation and ensure it is resulting in the same 
error -- otherwise, it is difficult to diagnose the real problem.
 

>
> def format_product(record):
> return '%s %s' % (record.product_name, record.batch_no)
>
>
Note, there is no need for this format function -- if all you are doing is 
string formatting, you can simply define:

format='%(product_name)s %(batch_no)s'

If you need to re-use that somewhere, you can later retrieve it via 
db.product._format. 

db.define_table('stock_task',
> Field()
> Field()
> Field('product','list:reference products'),
>
> auth.signature)
>
> db.stock_task.product.requires=IS_IN_DB(db,db.product,lambda record: 
> format_product(record))
>
>
Note, when creating an IS_IN_DB validator for a list:reference field, you 
should set multiple=True to allow multiple values. Anyway, you shouldn't 
need to do this at all, as you will get exactly this default validator 
automatically as long as the referenced table has a "format" attribute 
defined.

Anthony

-- 
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 : multiple levels of references

2014-05-23 Thread Louis Amon
wicked cool

thanks a bunch !

On Friday, May 23, 2014 3:28:43 PM UTC+2, Anthony wrote:
>
> You can use a lambda:
>
> db.define_table('other_table',
> Field('key_id', 'reference key',
>   requires=IS_IN_DB(db, 'key.id', lambda r: '%s %s (%s)' % (r.
> person_id.first_name,
> r.
> person_id.last_name, r.id
>
> Anthony
>
> On Friday, May 23, 2014 5:38:21 AM UTC-4, Louis Amon wrote:
>>
>> Say I have a table like this:
>>
>> db.define_table('person', Field('first_name'), Field('last_name'), 
>> format='%(first_name)s %(last_name)s'
>>
>> Now if I build a new table:
>>
>> db.define_table('key', Field('person_id', 'reference person', 
>> requires=IS_IN_DB(db, db.person, label=db.person._format)))
>>
>> My new table 'key' will represent its references using 'person' table's 
>> format.
>>
>>
>> But what if I have another table like this:
>>
>> db.define_table('other_table', Field('key_id', 'reference key', 
>> requires=IS_IN_DB(db, db.key, label='%(first_name)s %(last_name)s 
>> (%(key_id)s)'???)))
>>
>>
>> How do I define the label in 'other_table' so that it shows the 'person' 
>> that this key is actually referring to ?
>>
>>
>>

-- 
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 : multiple levels of references

2014-05-23 Thread Anthony
You can use a lambda:

db.define_table('other_table',
Field('key_id', 'reference key',
  requires=IS_IN_DB(db, 'key.id', lambda r: '%s %s (%s)' % (r.
person_id.first_name,
r.
person_id.last_name, r.id

Anthony

On Friday, May 23, 2014 5:38:21 AM UTC-4, Louis Amon wrote:
>
> Say I have a table like this:
>
> db.define_table('person', Field('first_name'), Field('last_name'), 
> format='%(first_name)s %(last_name)s'
>
> Now if I build a new table:
>
> db.define_table('key', Field('person_id', 'reference person', 
> requires=IS_IN_DB(db, db.person, label=db.person._format)))
>
> My new table 'key' will represent its references using 'person' table's 
> format.
>
>
> But what if I have another table like this:
>
> db.define_table('other_table', Field('key_id', 'reference key', 
> requires=IS_IN_DB(db, db.key, label='%(first_name)s %(last_name)s 
> (%(key_id)s)'???)))
>
>
> How do I define the label in 'other_table' so that it shows the 'person' 
> that this key is actually referring to ?
>
>
>

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

2013-07-02 Thread Anthony
The represent attribute does not affect the value stored in the database -- 
it just affects the display of the value in the grid, SQLTABLE, and 
read-only forms. If you want to set the value in the database, use a 
compute field.

Anthony

On Tuesday, July 2, 2013 3:06:06 PM UTC-4, greenpoise wrote:
>
> I just implemented record representation such as the table below. My 
> question is, is record representation supposed to save the value in the 
> database? I am trying to create a price override field in my product table 
> because the price can be changed within the series of a product (on the 
> series table) or within the product itself on discriminatory occasions. Is 
> Record Representation what I need???  Thanks
>
> db.define_table('series',
>Field('seriesname'),
>Field('seriesdescription'),
>Field('colorgroup','reference colorgroup'),
>Field('material', 'reference material'),
>Field('price')
> db.series.seriesname.requires = IS_NOT_IN_DB(db,db.series.seriesname)
> db.series.colorgroup.requires = IS_IN_DB(db,db.colorgroup.id,
> '%(groupname)s')
> db.series._singular = "Series"
> db.series._plural = "+Series"
>
> db.define_table('product',
>Field('series', 'reference series'),
>Field('finish', 'reference finish'),
>Field('cut', 'reference cut'),
>Field('price')
> db.product.series.requires = IS_EMPTY_OR(IS_IN_DB(db,db.series.id,
> '%(seriesname)s'))
> db.product.finish.requires = IS_EMPTY_OR(IS_IN_DB(db,db.finish.id,
> '%(name)s'))
> db.product.cut.requires = IS_EMPTY_OR(IS_IN_DB(db,db.cut.id,'%(name)s'))
> db.product.price.represent = lambda id,row: db.series(row.series).price
>
>
>
>
>
>

-- 

--- 
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 and SQLFORM.grid searchable

2013-03-31 Thread Anthony
Field('dungeon', 'reference dungeons', required=True, notnull=True,
  represent=lambda v, r: '(%s %s) %s' % (r.dungeon.mountain.x,
  r.dungeon.mountain.y, r.dungeon.pos))

This may also work:

db.define_table('dungeons',
...
format=lambda r: '(%s %s) %s' % (r.mountain.x, r.mountain.y, r.pos))

Careful, though -- these involve separate recursive selects for every 
record, so not efficient if displaying a large number of records (in that 
case, better to do an explicit join to get the values you want to display).

Anthony

On Sunday, March 31, 2013 10:50:46 AM UTC-4, Vladimir Kaznacheev wrote:
>
> ok. may i get representation for *mountain *to be used 
> in representation for *dungeons*?
>
> воскресенье, 31 марта 2013 г., 18:39:29 UTC+4 пользователь Anthony написал:
>>
>> format='(%(mountain.x)s %(mountain.y)s) %(pos)s'
>>
>> If "format" is a string, it can only include the names of fields within 
>> the current table (e.g., "mountain").
>>
>> Anthony
>>
>> On Sunday, March 31, 2013 9:48:47 AM UTC-4, Vladimir Kaznacheev wrote:
>>>
>>>
>>> in *db.py*
>>> db.define_table('mountains',
>>> Field('m_id','integer', required=True),
>>> Field('pos','integer'),
>>> Field('x','integer'),
>>> Field('y','integer'),
>>> format='(%(x)s %(y)s)',
>>> )
>>>
>>> db.define_table('dungeons',
>>> Field('d_id','integer', required=True),
>>> Field('mountain', 'reference mountains', notnull=True), 
>>> Field('pos','integer'),
>>> format='(%(mountain.x)s %(mountain.y)s) %(pos)s',
>>> )
>>>
>>> db.define_table('dungeon_resources',
>>> Field('dungeon', 'reference dungeons', required=True, notnull=True),
>>> Field('mine', 'string'),
>>> Field('quantity', 'integer'),
>>> )
>>>
>>>
>>> in *controllers/default.py*
>>> def ResourceMap():
>>> form = SQLFORM.grid(db.dungeon_resources, searchable=True, 
>>> create=False, editable=False, deletable=False, details=False)
>>> return dict(form=form)
>>>
>>> when i try open *http:///default/ResourceMap* i get error ticket
>>>  'Table' object has no attribute 
>>> 'mountain.x'
>>>
>>> without *format* in *db.define_table* table displays, but it is not 
>>> informative
>>>
>>

-- 

--- 
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 and SQLFORM.grid searchable

2013-03-31 Thread Vladimir Kaznacheev
ok. may i get representation for *mountain *to be used 
in representation for *dungeons*?

воскресенье, 31 марта 2013 г., 18:39:29 UTC+4 пользователь Anthony написал:
>
> format='(%(mountain.x)s %(mountain.y)s) %(pos)s'
>
> If "format" is a string, it can only include the names of fields within 
> the current table (e.g., "mountain").
>
> Anthony
>
> On Sunday, March 31, 2013 9:48:47 AM UTC-4, Vladimir Kaznacheev wrote:
>>
>>
>> in *db.py*
>> db.define_table('mountains',
>> Field('m_id','integer', required=True),
>> Field('pos','integer'),
>> Field('x','integer'),
>> Field('y','integer'),
>> format='(%(x)s %(y)s)',
>> )
>>
>> db.define_table('dungeons',
>> Field('d_id','integer', required=True),
>> Field('mountain', 'reference mountains', notnull=True), 
>> Field('pos','integer'),
>> format='(%(mountain.x)s %(mountain.y)s) %(pos)s',
>> )
>>
>> db.define_table('dungeon_resources',
>> Field('dungeon', 'reference dungeons', required=True, notnull=True),
>> Field('mine', 'string'),
>> Field('quantity', 'integer'),
>> )
>>
>>
>> in *controllers/default.py*
>> def ResourceMap():
>> form = SQLFORM.grid(db.dungeon_resources, searchable=True, 
>> create=False, editable=False, deletable=False, details=False)
>> return dict(form=form)
>>
>> when i try open *http:///default/ResourceMap* i get error ticket
>>  'Table' object has no attribute 
>> 'mountain.x'
>>
>> without *format* in *db.define_table* table displays, but it is not 
>> informative
>>
>

-- 

--- 
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 and SQLFORM.grid searchable

2013-03-31 Thread Anthony
format='(%(mountain.x)s %(mountain.y)s) %(pos)s'

If "format" is a string, it can only include the names of fields within the 
current table (e.g., "mountain").

Anthony

On Sunday, March 31, 2013 9:48:47 AM UTC-4, Vladimir Kaznacheev wrote:
>
>
> in *db.py*
> db.define_table('mountains',
> Field('m_id','integer', required=True),
> Field('pos','integer'),
> Field('x','integer'),
> Field('y','integer'),
> format='(%(x)s %(y)s)',
> )
>
> db.define_table('dungeons',
> Field('d_id','integer', required=True),
> Field('mountain', 'reference mountains', notnull=True), 
> Field('pos','integer'),
> format='(%(mountain.x)s %(mountain.y)s) %(pos)s',
> )
>
> db.define_table('dungeon_resources',
> Field('dungeon', 'reference dungeons', required=True, notnull=True),
> Field('mine', 'string'),
> Field('quantity', 'integer'),
> )
>
>
> in *controllers/default.py*
> def ResourceMap():
> form = SQLFORM.grid(db.dungeon_resources, searchable=True, 
> create=False, editable=False, deletable=False, details=False)
> return dict(form=form)
>
> when i try open *http:///default/ResourceMap* i get error ticket
>  'Table' object has no attribute 
> 'mountain.x'
>
> without *format* in *db.define_table* table displays, but it is not 
> informative
>

-- 

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




[web2py] Re: record representation using a non-id column?

2011-07-20 Thread niknok
Thanks Johann!

On Jul 20, 8:11 pm, Johann Spies  wrote:
> On 20 July 2011 14:09, Johann Spies  wrote:
>
>
>
> > I use this:
>
> > db.define_table('akb_doccenter_location',
>
> >                 Field('location'))
>
> Apologies, I did not complete the message before sending: the model includes
> a Field(uuid),  obviously.
>
> Regards
> Johann
>
> --
>  May grace and peace be yours in abundance through the full knowledge of God
> and of Jesus our Lord!  His divine power has given us everything we need for
> life and godliness through the full knowledge of the one who called us by
> his own glory and excellence.
>                                                     2 Pet. 1:2b,3a