[web2py] record representation and lambda

2015-11-14 Thread Anthony Smith
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] Record representation : multiple levels of references

2014-05-23 Thread Louis Amon
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] Record representation and virtual fields

2014-04-09 Thread Louis Amon
I defined 2 tables as follows:

db.define_table('offer', Field.Virtual('title', title_func)
> db.define_table('discussion', Field('offer_id', reference offer)


With title_func() a function that builds a string based on other fields in 
the 'offer' table.

db.offer.format = '%(title)s



Now when I use appadmin and look at the 'discussion' table, all the 
referenced records are properly represented with my function.

But if I click on a 'discussion' id record to display the update form, the 
'select' input doesn't display the proper record representation for 
referenced fields.

I tried to put a print at the beginning of my offer_func() in 'offer' model 
and ended up with this upon loading the previous update form :
[...]  [...]


Which means that my virtual field somehow has full access to the fields it 
requires in the regular appadmin menu but doesn't have access to those in 
the update form. Just the id field.

Is this a bug ? Am I doing something wrong ??

-- 
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] Record Representation

2013-07-02 Thread greenpoise
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] Record representation and SQLFORM.grid searchable

2013-03-31 Thread Vladimir Kaznacheev

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] record representation format that refer to another table and that table is refer to another table

2013-03-21 Thread 黄祥
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.




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

2011-07-20 Thread Johann Spies
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


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

2011-07-20 Thread Johann Spies
 On 9 July 2011 03:47, niknok  wrote:

> **
> I have another unique column in my table that I would like to use as index
> for record representation.  How do I tell web2py to use another index?
>
> Ttrying to use like:
> db.mytable.thisfield.represent = lambda id: db.other(myidx).thatfield
>

I use this:


db.define_table('akb_doccenter_location',

Field('location'))

db.akb_doccenter.location.represent = lambda uuid: db(
db.akb_doccenter_location.uuid==uuid).select(
db.akb_doccenter_location.location).first()['location']


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


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

2011-07-08 Thread niknok
I have another unique column in my table that I would like to use as
index for record representation.  How do I tell web2py to use another
index?

Ttrying to use like:
db.mytable.thisfield.represent = lambda id:
db.other(myidx).thatfield