Where does the manage code go?

已查看 36 次
跳至第一个未读帖子

Bryan Nahrwold

未读,
2018年2月16日 17:10:382018/2/16
收件人 web2py-users
I am assuming this is so obvious that you don't feel the need to state it explicitly, but where the heck does the manager code go in the book  code 3.3.2 Adding Grids?

I've tried several file locations which all don't work.

The book states on page 105-106 (version 2.16.1-stable+timestamp.2017.11.14.05.54.25):

We can improve this further using the SQLFORM.grid and SQLFORM.smartgrid gadgets to create a management interface for our application:

@auth.requires_membership('manager')
def manage():
    grid = SQLFORM.smartgrid(db.image, linked_tables=['post'])
    return dict(grid=grid)

with associated "views/default/manage.html".


You have a great book, However, I find it exasperating how many times you do not explicitly state where code should go.
EVERY SINGLE code entry should have an explicit listing of the file it is supposed to go into. That really shouldn't be difficult.

I have actually had to go to some third party web2py tutorials to try and figure some of this stuff out. Some of these third party tutorials DO give explicit file paths for EVERY code segment, can't you?

Please try to put yourself in the place of a beginner. The architecture is still not clear and your new readers may be digesting the book over periods of time with lapses in between readings. I shouldn't have to reread the last five pages every time I pick up the book again just to get a relative reference to tell me where the file resides that you are talking about modifying.

I like this product but find these repeated vague references to code locations an impediment to adoption of this product.

Dave S

未读,
2018年2月16日 17:48:012018/2/16
收件人 web...@googlegroups.com


On Friday, February 16, 2018 at 2:10:38 PM UTC-8, Bryan Nahrwold wrote:
I am assuming this is so obvious that you don't feel the need to state it explicitly, but where the heck does the manager code go in the book  code 3.3.2 Adding Grids?


This is just a controller function, so it can go in any file in the controllers directory.   Since it is meant to be directly accessible (by the authorized users) via a URL, it should not go in the models or modules directories.  To match the suggested view template file name, the example you quoted should go in controllers/default.py.



I've tried several file locations which all don't work.

The book states on page 105-106 (version 2.16.1-stable+timestamp.2017.11.14.05.54.25):

We can improve this further using the SQLFORM.grid and SQLFORM.smartgrid gadgets to create a management interface for our application:

@auth.requires_membership('manager')
def manage():
    grid = SQLFORM.smartgrid(db.image, linked_tables=['post'])
    return dict(grid=grid)

with associated "views/default/manage.html".
 

You have a great book, However, I find it exasperating how many times you do not explicitly state where code should go.
EVERY SINGLE code entry should have an explicit listing of the file it is supposed to go into. That really shouldn't be difficult.

I have actually had to go to some third party web2py tutorials to try and figure some of this stuff out. Some of these third party tutorials DO give explicit file paths for EVERY code segment, can't you?

Please try to put yourself in the place of a beginner. The architecture is still not clear and your new readers may be digesting the book over periods of time with lapses in between readings. I shouldn't have to reread the last five pages every time I pick up the book again just to get a relative reference to tell me where the file resides that you are talking about modifying.

I like this product but find these repeated vague references to code locations an impediment to adoption of this product.

In general, something that corresponds to a URL goes in a controller, something that is shared by controllers goes in a module, and something that defines a table goes in a model.  (There are some times when a table definition gets moved to a module, for overhead reasons.)  View templates go in the views directory, in a subdirectory corresponding to the controller file name.

Also note that many of the examples are done by running web2py -M -S myapp to open an interactive shell, and viewing the results on the console.

/dps

Anthony

未读,
2018年2月16日 18:20:402018/2/16
收件人 web2py-users
You have a great book, However, I find it exasperating how many times you do not explicitly state where code should go.
EVERY SINGLE code entry should have an explicit listing of the file it is supposed to go into. That really shouldn't be difficult.

I have actually had to go to some third party web2py tutorials to try and figure some of this stuff out. Some of these third party tutorials DO give explicit file paths for EVERY code segment, can't you?

Note, you are always welcome to make a pull request to the book repo (https://github.com/web2py/web2py-book).

Anthony
回复全部
回复作者
转发
0 个新帖子