Re: [web2py] Re: Question about SQLFORM.grid - process a column before show it

2012-12-21 Thread Christian Espinoza
Wow!! Thanks Niphlod, this tip worked like a charm!!

El jueves, 20 de diciembre de 2012 20:53:14 UTC-3, Niphlod escribió:

 my bad, sorry Christian.

 myset = { 0:'Quiet',1:'Running',2:'Fail'}
 
 Field('action', 'integer', 
  requires=IS_IN_SET(myset), 
  represent=lambda value, row: myset.get(value, None) 
  # or myset[value] if you are totally sure that myset contains 
 all the possible values
  )


 Tested !

 On Friday, December 21, 2012 12:13:11 AM UTC+1, villas wrote:

 I guess you need to use:  actions.represent  as well.  


 On Thursday, December 20, 2012 9:46:58 PM UTC, Niphlod wrote:

 Disclaimer: not tested
 why don't you just change the action Field to 

 Field('action', requires=IS_IN_SET({ 0:'Quiet',1:'Running',2:'Fail'}))

 On Thursday, December 20, 2012 10:23:07 PM UTC+1, Jim S wrote:

 Have you though about adding a table to define the relation between 
 'index' and the text:

 db_actions.define_table('actions',
 Field(name, length=20, label='Action'))

 Then modify db_events so field index looks like:

 Field('index', db.actions, label='Action),

 Table actions would then have three records, 

 Quiet
 Running
 Fail

 This should then automatically display the right value - the only 
 problem is that it wouldn't guarantee that the index would be 0, 1, and 2. 
  It would be whatever the primary key on the actions table worked out to 
 be.

 The other way to handle it would be to write a custom validator that 
 changed the numeric value as you mentioned.  I haven't done that before, 
 but heard it isn't that difficult.

 -Jim

 On Thu, Dec 20, 2012 at 2:45 PM, Christian Espinoza chesp...@gmail.com
  wrote:

 My Model for this App
 db_events.define_table('events',
 Field('devid', length=15, label='CODE'),
 Field('type', length=15, label='Type'),
 Field('index','integer', label='Action'),
 Field('datetime','datetime', label='Date'),
 Field('latitude','double', label='Lat'),
 Field('longitude','double', label='Lon'),
 Field('velocity','double', label='Vel'),
 Field('heading', 'integer', label='Dir'),
 Field('pfm','integer', label='PFM'),
 Field('age','integer', label='Age'),
 Field('odometer','double', label='Od')
 )
 -- 
  
  
  




-- 





[web2py] Re: Question about SQLFORM.grid - process a column before show it

2012-12-20 Thread Jim S
What does your model look like?

-Jim

On Thursday, December 20, 2012 2:15:20 PM UTC-6, Christian Espinoza wrote:

 Hi, I'm wondering about if is possible process the values of a column to 
 show the result on the grid instead of original value...
 My Code:
 (db_events.events.device_id == request.vars.id) \
 (db_events.events.event_datetime = from) \
 (db_events.events.event_datetime = to)

 grid = SQLFORM.grid(query, editable=False, searchable=False, 
 deletable=False,create=False,details=False )

 With this code I get :
 Idhttp://127.0.0.1:8000/avl/reports/events?keywords=order=events.id_signature=acefaa93bdd83c149087600ecbf3e87539935034
 Chttp://127.0.0.1:8000/avl/reports/events?keywords=order=events.device_id_signature=acefaa93bdd83c149087600ecbf3e87539935034
 odeThttp://127.0.0.1:8000/avl/reports/events?keywords=order=events.event_type_signature=acefaa93bdd83c149087600ecbf3e87539935034
 ypeAhttp://127.0.0.1:8000/avl/reports/events?keywords=order=events.event_index_signature=acefaa93bdd83c149087600ecbf3e87539935034
 ctionDhttp://127.0.0.1:8000/avl/reports/events?keywords=order=events.event_datetime_signature=acefaa93bdd83c149087600ecbf3e87539935034
 ateLahttp://127.0.0.1:8000/avl/reports/events?keywords=order=events.event_latitude_signature=acefaa93bdd83c149087600ecbf3e87539935034
 tLonhttp://127.0.0.1:8000/avl/reports/events?keywords=order=events.event_longitude_signature=acefaa93bdd83c149087600ecbf3e87539935034
 Velhttp://127.0.0.1:8000/avl/reports/events?keywords=order=events.event_velocity_signature=acefaa93bdd83c149087600ecbf3e87539935034
 Dirhttp://127.0.0.1:8000/avl/reports/events?keywords=order=events.event_heading_signature=acefaa93bdd83c149087600ecbf3e87539935034
 PFMhttp://127.0.0.1:8000/avl/reports/events?keywords=order=events.event_pfm_signature=acefaa93bdd83c149087600ecbf3e87539935034
 Agehttp://127.0.0.1:8000/avl/reports/events?keywords=order=events.event_age_signature=acefaa93bdd83c149087600ecbf3e87539935034
 Odhttp://127.0.0.1:8000/avl/reports/events?keywords=order=events.vodometer_signature=acefaa93bdd83c149087600ecbf3e87539935034
 5742356612022462768EVENT22012-12-20 15:24:52-20.23496-70.1384814.48371732
 18460843.005743356612022462768EVENT12012-12-20 15:25:58-20.23064-70.13754
 16.0933363218461344.005744356612022462768EVENT12012-12-20 15:26:26
 -20.23049-70.138616.0933293218461461.005745356612022462768EVENT12012-12-20 
 15:28:49-20.22115-70.137746.43723253218462508.005746356612022462768EVENT02012-12-20
  
 15:29:11-20.22088-70.1394724.13953593218462702.005747356612022462768EVENT02012-12-20
  
 15:31:17-20.21419-70.1389919.31163081218463458.005748356612022462768EVENT02012-12-20
  
 15:34:16-20.21372-70.1469522.53022713218464303.005749356612022462768EVENT22012-12-20
  
 15:36:17
 I need change the Action column with the values of a Dic that I have:

 Actions = { 0:'Quiet',1:'Running',2:'Fail'}

 How can I show on SQLFORM.grid a 'Quiet' instead of a 0, a 'Running' 
 instead a 1, an finally a 'Fail' instead a 2??

 Greetings
 Christian.



-- 





[web2py] Re: Question about SQLFORM.grid - process a column before show it

2012-12-20 Thread Christian Espinoza
My Model for this App
db_events.define_table('events',
Field('devid', length=15, label='CODE'),
Field('type', length=15, label='Type'),
Field('index','integer', label='Action'),
Field('datetime','datetime', label='Date'),
Field('latitude','double', label='Lat'),
Field('longitude','double', label='Lon'),
Field('velocity','double', label='Vel'),
Field('heading', 'integer', label='Dir'),
Field('pfm','integer', label='PFM'),
Field('age','integer', label='Age'),
Field('odometer','double', label='Od')
)

-- 





Re: [web2py] Re: Question about SQLFORM.grid - process a column before show it

2012-12-20 Thread Jim Steil
Have you though about adding a table to define the relation between 'index'
and the text:

db_actions.define_table('actions',
Field(name, length=20, label='Action'))

Then modify db_events so field index looks like:

Field('index', db.actions, label='Action),

Table actions would then have three records,

Quiet
Running
Fail

This should then automatically display the right value - the only problem
is that it wouldn't guarantee that the index would be 0, 1, and 2.  It
would be whatever the primary key on the actions table worked out to be.

The other way to handle it would be to write a custom validator that
changed the numeric value as you mentioned.  I haven't done that before,
but heard it isn't that difficult.

-Jim

On Thu, Dec 20, 2012 at 2:45 PM, Christian Espinoza chespin...@gmail.comwrote:

 My Model for this App
 db_events.define_table('events',
 Field('devid', length=15, label='CODE'),
 Field('type', length=15, label='Type'),
 Field('index','integer', label='Action'),
 Field('datetime','datetime', label='Date'),
 Field('latitude','double', label='Lat'),
 Field('longitude','double', label='Lon'),
 Field('velocity','double', label='Vel'),
 Field('heading', 'integer', label='Dir'),
 Field('pfm','integer', label='PFM'),
 Field('age','integer', label='Age'),
 Field('odometer','double', label='Od')
 )
 --





-- 





Re: [web2py] Re: Question about SQLFORM.grid - process a column before show it

2012-12-20 Thread Niphlod
Disclaimer: not tested
why don't you just change the action Field to 

Field('action', requires=IS_IN_SET({ 0:'Quiet',1:'Running',2:'Fail'}))

On Thursday, December 20, 2012 10:23:07 PM UTC+1, Jim S wrote:

 Have you though about adding a table to define the relation between 
 'index' and the text:

 db_actions.define_table('actions',
 Field(name, length=20, label='Action'))

 Then modify db_events so field index looks like:

 Field('index', db.actions, label='Action),

 Table actions would then have three records, 

 Quiet
 Running
 Fail

 This should then automatically display the right value - the only problem 
 is that it wouldn't guarantee that the index would be 0, 1, and 2.  It 
 would be whatever the primary key on the actions table worked out to be.

 The other way to handle it would be to write a custom validator that 
 changed the numeric value as you mentioned.  I haven't done that before, 
 but heard it isn't that difficult.

 -Jim

 On Thu, Dec 20, 2012 at 2:45 PM, Christian Espinoza 
 chesp...@gmail.comjavascript:
  wrote:

 My Model for this App
 db_events.define_table('events',
 Field('devid', length=15, label='CODE'),
 Field('type', length=15, label='Type'),
 Field('index','integer', label='Action'),
 Field('datetime','datetime', label='Date'),
 Field('latitude','double', label='Lat'),
 Field('longitude','double', label='Lon'),
 Field('velocity','double', label='Vel'),
 Field('heading', 'integer', label='Dir'),
 Field('pfm','integer', label='PFM'),
 Field('age','integer', label='Age'),
 Field('odometer','double', label='Od')
 )
 -- 
  
  
  




-- 





Re: [web2py] Re: Question about SQLFORM.grid - process a column before show it

2012-12-20 Thread villas
I guess you need to use:  actions.represent  as well.  


On Thursday, December 20, 2012 9:46:58 PM UTC, Niphlod wrote:

 Disclaimer: not tested
 why don't you just change the action Field to 

 Field('action', requires=IS_IN_SET({ 0:'Quiet',1:'Running',2:'Fail'}))

 On Thursday, December 20, 2012 10:23:07 PM UTC+1, Jim S wrote:

 Have you though about adding a table to define the relation between 
 'index' and the text:

 db_actions.define_table('actions',
 Field(name, length=20, label='Action'))

 Then modify db_events so field index looks like:

 Field('index', db.actions, label='Action),

 Table actions would then have three records, 

 Quiet
 Running
 Fail

 This should then automatically display the right value - the only problem 
 is that it wouldn't guarantee that the index would be 0, 1, and 2.  It 
 would be whatever the primary key on the actions table worked out to be.

 The other way to handle it would be to write a custom validator that 
 changed the numeric value as you mentioned.  I haven't done that before, 
 but heard it isn't that difficult.

 -Jim

 On Thu, Dec 20, 2012 at 2:45 PM, Christian Espinoza 
 chesp...@gmail.comwrote:

 My Model for this App
 db_events.define_table('events',
 Field('devid', length=15, label='CODE'),
 Field('type', length=15, label='Type'),
 Field('index','integer', label='Action'),
 Field('datetime','datetime', label='Date'),
 Field('latitude','double', label='Lat'),
 Field('longitude','double', label='Lon'),
 Field('velocity','double', label='Vel'),
 Field('heading', 'integer', label='Dir'),
 Field('pfm','integer', label='PFM'),
 Field('age','integer', label='Age'),
 Field('odometer','double', label='Od')
 )
 -- 
  
  
  




-- 





Re: [web2py] Re: Question about SQLFORM.grid - process a column before show it

2012-12-20 Thread Niphlod
my bad, sorry Christian.

myset = { 0:'Quiet',1:'Running',2:'Fail'}

Field('action', 'integer', 
 requires=IS_IN_SET(myset), 
 represent=lambda value, row: myset.get(value, None) 
 # or myset[value] if you are totally sure that myset contains all 
the possible values
 )


Tested !

On Friday, December 21, 2012 12:13:11 AM UTC+1, villas wrote:

 I guess you need to use:  actions.represent  as well.  


 On Thursday, December 20, 2012 9:46:58 PM UTC, Niphlod wrote:

 Disclaimer: not tested
 why don't you just change the action Field to 

 Field('action', requires=IS_IN_SET({ 0:'Quiet',1:'Running',2:'Fail'}))

 On Thursday, December 20, 2012 10:23:07 PM UTC+1, Jim S wrote:

 Have you though about adding a table to define the relation between 
 'index' and the text:

 db_actions.define_table('actions',
 Field(name, length=20, label='Action'))

 Then modify db_events so field index looks like:

 Field('index', db.actions, label='Action),

 Table actions would then have three records, 

 Quiet
 Running
 Fail

 This should then automatically display the right value - the only 
 problem is that it wouldn't guarantee that the index would be 0, 1, and 2. 
  It would be whatever the primary key on the actions table worked out to be.

 The other way to handle it would be to write a custom validator that 
 changed the numeric value as you mentioned.  I haven't done that before, 
 but heard it isn't that difficult.

 -Jim

 On Thu, Dec 20, 2012 at 2:45 PM, Christian Espinoza 
 chesp...@gmail.comwrote:

 My Model for this App
 db_events.define_table('events',
 Field('devid', length=15, label='CODE'),
 Field('type', length=15, label='Type'),
 Field('index','integer', label='Action'),
 Field('datetime','datetime', label='Date'),
 Field('latitude','double', label='Lat'),
 Field('longitude','double', label='Lon'),
 Field('velocity','double', label='Vel'),
 Field('heading', 'integer', label='Dir'),
 Field('pfm','integer', label='PFM'),
 Field('age','integer', label='Age'),
 Field('odometer','double', label='Od')
 )
 -- 
  
  
  




--