[web2py] Re: represent in sqlform.grid and javascript

2017-10-04 Thread 黄祥
for 1st problem, tried to print the value of the field


just curious what SQLFORM.grid() does with this kind of data with 
represent, so that it can appears smoothly, while using another it's throw 
an error, any idea or hints?

thanks and best regards,
stifan

-- 
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: represent in sqlform.grid and javascript

2017-10-04 Thread 黄祥
*modules/test_grid.py*
def list(table):
query = (table.is_active == True)
items = current.db(query).select(orderby = ~table.created_on).render()
actions = [
{'is_item_action': lambda item: True, 'url': lambda item: 
URL('view', args = [item.id] ), 'icon': 'zoom-in', 'title': 'View', 
'onclick': ''},
{'is_item_action': lambda item: True, 'url': lambda item: 
URL('edit', args = [item.id] ), 'icon': 'pencil', 'title': 'Edit', 
'onclick': ''},
]
fields = [f for f in table]
current.response.view = 'templates/grid/list.%s' % 
current.request.extension
return dict(item_name = table._singular, row_list = items, actions = 
actions, field_list = fields)

*views/templates/grid/list.html*
{{extend 'layout.html'}}


$(document).ready(function() {
var table = $('#example').DataTable( {
"responsive": false,
"dom": "ifrtlp",
"language": {
"decimal": ",",
"thousands": "."
}, 
} );
} );




{{for field in field_list:}}
{{=field.label}}
{{pass}}
Action



{{for row in row_list:}}

{{for field in field_list:}}
{{=row[field] }}
{{pass}}

{{for action in actions:}}
{{if action['is_item_action'](row):}}



{{pass}}
{{pass}}


{{pass}}



-- 
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: represent in sqlform.grid and javascript

2017-10-04 Thread Dave S
I think you should show how you're setting up the datatables.net context. 
 It looks like there is something about how pydal is called from that 
context, perhaps something  that SQLFORM.grid initializes that is being 
missed in the JS setup. 

/dps


On Wednesday, October 4, 2017 at 1:42:19 AM UTC-7, 黄祥 wrote:
>
> *modules/test_field_constructor.py*
> represent_reference_0 = lambda value, field: \
> A('%s, %s, %s' % (field.address.street, field.address.city, 
> field.address.country), 
>   _href="
> http://maps.google.com/maps?f=q=en=%s,+%s,+%s
> " 
>   % (field.address.street, field.address.city, field.address.country) )
>
> *using SQLFORM.grid() produce = *
> http://maps.google.com/maps?f=qhl=engeocode=time=date=ttype=q=street,+city,+country;>street,
>  
> city, country
>
> *using datatables.net  produce =*
> Traceback (most recent call last):
>   File "/Users/MacBookPro/site/web2py/gluon/restricted.py", line 227, in 
> restricted
> exec ccode in environment
>   File 
> "/Users/MacBookPro/site/web2py/applications/test/views/templates/grid/list.html",
>  
> line 90, in 
> 
>   File 
> "/Users/MacBookPro/site/web2py/gluon/packages/dal/pydal/objects.py", line 
> 2695, in 
> return (self.render(i, fields=fields) for i in range(len(self)))
>   File 
> "/Users/MacBookPro/site/web2py/gluon/packages/dal/pydal/objects.py", line 
> 2712, in render
> row[table])
>   File "/Users/MacBookPro/site/web2py/gluon/packages/dal/pydal/base.py", 
> line 1076, in represent
> return self.representers[name](*args, **kwargs)
>   File "/Users/MacBookPro/site/web2py/gluon/sqlhtml.py", line 70, in 
> represent
> return f(value, record)
>   File "applications/test/modules/test_field_constructor.py", line 33, in 
> 
> % (field.address.street, field.address.city, field.address.country) ) 
> if value else ''
> AttributeError: 'long' object has no attribute 'street'
>
> already tried = 
> *models/db.py*
> db = DAL(..., lazy_tables = True) # setting lazy_tables = True or False 
> still got the same result
>
> any hints to face this?
>
> another strange things is :
> *models/db.py*
> db.define_table('address', 
> Field('street', 'text'), # when change the field name into address the 
> result using datatables turn into None
> Field('city'), 
> Field('country'), 
> format = lambda r: '%s, %s, %s, %s' % (r.street, r.city, r.country) )
>
> e.g.
> db.address.street.represent = lambda value, field: SPAN(value)
> *result using datatables.net  =* whatever value 
> store in this field
>
> db.address.address.represent = lambda value, field: SPAN(value)
> *result using datatables.net  =* None (no errors 
> occured but the result is not expected)
>
> while tested using SQLFORM.grid() both field name (address or street) run 
> as expected
>
> tested from scratch (new web2py app)
>
> thanks and best regards,
> stifan
>

-- 
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: represent for SQLFORM.grid

2015-06-09 Thread Anthony
The represent attribute doesn't apply to form widgets. For that, you will 
need to create a custom widget and specify the widget attribute of the 
Field.

Anthony

On Tuesday, June 9, 2015 at 4:51:59 PM UTC-4, i...@softmanufacture.com 
wrote:

 Hello,

 The represent works fine for grid view but 
 I need to apply represent function for the add, edit forms.

 db.product.price.represent = lambda x, row: 
 current.currency.format_price(x)

 Inside html template I use {{=form}}
 as well as {{=form.custom.widget.price}}

 Thank you for the help.



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