py4web grid syntax - needs testers

212 views
Skip to first unread message

Massimo Di Pierro

unread,
Sep 15, 2019, 7:18:17 PM9/15/19
to web2py-users
I just pushed some changes to the new py4web grid (aka mtable aka publisher). It requires the latest pydal.

There is an example in http://127.0.0.1:8000/examples

But as of today it works like this:

0) make sure you have

apps/{yourapp}/static/components/mtable.js and mtable.html (copy them from _dashboard)

1) in controller define a publisher:

from py4web.utils.publisher import Publisher
publisher = Publisher(db, policy=ALLOW_ALL_POLICY)

# you can set more complex policies using the pydal restapi policy format. If the policy requires a logger in user do:

publisher = Publisher(db, auth=auth.user, policy=ALLOW_ALL_POLICY)

2) in the action:

# exposed as /examples/grid                                                                
@action('mygrid')
@action.uses('mygrid.html')
def example_grid():
    return dict(grid=publisher.grid(db.mytablename)) ### <<< your table name

3) In mygrid.html all you need is

[[extends "layout.html"]]
[[=grid]]

Notice you can have multiple grids per page. You can also have multiple publishers if you need different policies for different grids but you probably can do everything with one publisher. Each publisher exposes its own RESTAPI.

Does it work? Suggestions for improvements?



isi_jca

unread,
Sep 16, 2019, 8:02:04 PM9/16/19
to web2py-users
Hi!!!

1°)
When I try to use 

"A page with an update form example", the console show:

ERROR:root:Traceback (most recent call last):
  File "/home/jalbornoz/py4web-env/lib64/python3.7/site-packages/py4web/core.py", line 461, in wrapper
    ret = func(*func_args, **func_kwargs)
  File "/home/jalbornoz/py4web-env/lib64/python3.7/site-packages/py4web/core.py", line 427, in wrapper
    ret = func(*args, **kwargs)
  File "/home/jalbornoz/apps/examples/__init__.py", line 33, in example_form
    form = Form(db.person, id, deletable=False, formstyle=FormStyleBulma)
  File "/home/jalbornoz/py4web-env/lib64/python3.7/site-packages/py4web/utils/form.py", line 184, in __init__
    (value, error) = field.validate(value)
TypeError: validate() missing 1 required positional argument: 'record_id'

id= 42

2°) The dashboard don't let to edit row on table or create a new row.





Massimo Di Pierro

unread,
Sep 17, 2019, 2:03:11 AM9/17/19
to web2py-users
You have an olv version of pydal

python3 -m pip install -U pydal

IVINH

unread,
Sep 20, 2019, 5:12:15 AM9/20/19
to web2py-users
For a new update in model, controller or view, do I need to restart the server?

Massimo Di Pierro

unread,
Sep 21, 2019, 11:45:12 AM9/21/19
to web2py-users
You need to press the reload button in the dashboard or restart the server.

isi_jca

unread,
Sep 22, 2019, 9:02:16 PM9/22/19
to web2py-users
Hi!!!

In models.py, I have this table

db.define_table('tempresa',
Field('descripcion','string',length=50,label = T('Enterprise')),
Field('email','string',length=50, label = T('Email')),
Field('phone','string',length=50, label = T('Phone')),
Field('estado','reference trestado',label = T('State')),migrate=False)

When I use grid get this string:

{ "__class__": "lazyT", "kwargs": {}, "text": "Enterprise", "translator": { "__class__": "method" } }
{ "__class__": "lazyT", "kwargs": {}, "text": "Email", "translator": { "__class__": "method" } }
{ "__class__": "lazyT", "kwargs": {}, "text": "Phone", "translator": { "__class__": "method" } }
{ "__class__": "lazyT", "kwargs": {}, "text": "State", "translator": { "__class__": "method" } }


In init.py my script is this.

# exposed as /examples/grid
@action('empresa_grid', method=['GET','POST'])
@action.uses('empresa_grid.html',db, session,T)
def empresa_grid():
    Titulo = T('Enterprise')
    grid=publisher.grid(db.tempresa)
    return locals()

isi_jca

unread,
Sep 30, 2019, 3:34:57 PM9/30/19
to web2py-users
Hi! 

Anybody have idea why py4web doesn't translate  the labels?

Best regards

Massimo Di Pierro

unread,
Sep 30, 2019, 11:44:53 PM9/30/19
to web2py-users
Thanks for catching that. Please open a ticket and I will fix it asap.
Reply all
Reply to author
Forward
0 new messages