Thank you,
I was missing the point completely.
I was using links like */default/modelA_read*.
...then I had in controller */default.py* :
def modelA_read():
return generic_read()
... and in */models/generic.py*
def generic_read():
table = request.function.replace('_read','')
# get data, generate forms, pagination, etc. based on value of table.
return dict(...)
I didn't know the request.arg() trick, so I needed a modelA_read controller
just so I could know which model I had to deal with in my generic
controller.
Now you taught me that, I don't need the modelX_read controller anymore.
By the way, response.view worked fine also, I don't need all the explicit
views anymore.
Thank you.
On Monday, October 15, 2012 3:33:14 PM UTC+1, apinho wrote:
>
> Hi,
>
> I started with web2py a few weeks ago, writing some very simple apps. I
> noticed that I was constantly repeating myself in the following steps :
> Write a controller to fetch the data
> Write a view to present data.
>
> So, I made generic controllers and views, which I later call using this
> schema :
>
> User request : http://myserver/myapp/mymodel_list
>
> In CONTROLLERS/DEFAULT.PY :
> def mymodel_list():
> return generic_list()
>
> In MODELS/GENERIC.PY :
> def generic_list():
> # Do all work here, get mydata, pagination, etc...
> return dict(mydata)
>
> In VIEWS/DEFAULT/MYMODEL_LIST.HTML :
> {{extend 'generic_list.html'}}
>
> In VIEWS/GENERIC_LIST.HTML
> {{extend 'layout.html'}}
> {{include}}
> <!-- Do all representation of mydata -->
>
> This works well for me, cause I only have to deal with 4/5 controller and
> views (generic_list, generic_read, generic_add, generic_edit).
>
> One question though :
> For every model I have to create all the functions :
> def mymodel_read():
> return generic_read()
> def mymodel_list():
> return generic_list()
> etc...
> .. and I also have to create all the views :
> mymodel_list.html :
> {{extend 'generic_list'}}
> mymodel_list.read :
> {{extend 'generic_read'}}
> ...etc
>
> I believe there must be a way to avoid creating these views and these
> controllers, through the use of routes, or something.
>
> Someone care to guide me to do this ?
>
>
>
>
>
>
--