[web2py] Re: DRY conception

2011-01-18 Thread Massimo Di Pierro
from a coding point of view

tablename=request.controller
rows = db(db[tablename]).select()
return dict(rows=rows)

but the problem is that you have two controllers. Perhaps you should
have only one.

On Jan 18, 2:59 pm, walter wdv...@gmail.com wrote:
 I have two controllers which differ only a database table title. For
 example:

 default/persons/index
     persons = db(db.person).select()
     return dict(persons=persons)

 default/trips/index
     trips = db(db.trip).select()
     return dict(trips=trips)

 How implement DRY conception in this case? I think I need create an
 additional class and pass a table name to this class. All work must to
 be done in this class and a result should return to the corresponding
 method. But it only my opinion. How to do it right?


[web2py] Re: DRY conception

2011-01-18 Thread walter
 but the problem is that you have two controllers. Perhaps you should have 
 only one.

I have thought about it. Unfortunately, I need sometimes show all our
customers but at the next time I need view all them trips. I would be
glad to do merge two controllers into the one. But I cannot figure out
how to determine which of the tables need use in that, or otherwise
case?


Re: [web2py] Re: DRY conception

2011-01-18 Thread Bruno Rocha
def sections():
allowedtables = ['table1','table2']
tablename = request.args(0)
if tablename in allowedtables:
rows = db(db[tablename]).select()
else:
rows = 'You can't access this table'

return dict(rows=rows)


http://myapp/default/sections/tablename

Is that?


Bruno Rocha
http://about.me/rochacbruno/bio


2011/1/18 walter wdv...@gmail.com

  but the problem is that you have two controllers. Perhaps you should have
 only one.

 I have thought about it. Unfortunately, I need sometimes show all our
 customers but at the next time I need view all them trips. I would be
 glad to do merge two controllers into the one. But I cannot figure out
 how to determine which of the tables need use in that, or otherwise
 case?


Re: [web2py] Re: DRY conception

2011-01-18 Thread Jonathan Lundell
On Jan 18, 2011, at 1:59 PM, walter wrote:
 
 but the problem is that you have two controllers. Perhaps you should have 
 only one.
 
 I have thought about it. Unfortunately, I need sometimes show all our
 customers but at the next time I need view all them trips. I would be
 glad to do merge two controllers into the one. But I cannot figure out
 how to determine which of the tables need use in that, or otherwise
 case?

One way:

http://app/default/show/tablename

...where show is the function, and tablename is args[0]. That is, make the 
function the action you're requesting, and the argument(s) the object you're 
going to do it to.


Or go ahead and repeat yourself; it's only a venial sin.

Re: [web2py] Re: DRY conception

2011-01-18 Thread pbreit
For starters, I wouldn't get so hung up on DRY. Are the pages you are 
creating very nearly identical but with different data sets?

Jonathan's suggestion sounds good:
http://app/default/show/t http://app/default/show/tablenamerips
http://app/default/show/p http://app/default/show/tablenameersons


Re: [web2py] Re: DRY conception

2011-01-18 Thread Bruno Rocha
2011/1/19 pbreit pbreitenb...@gmail.com

 For starters, I wouldn't get so hung up on DRY. Are the pages you are
 creating very nearly identical but with different data sets?

 Jonathan's suggestion sounds good:
 http://app/default/show/t http://app/default/show/tablenamerips
 http://app/default/show/p http://app/default/show/tablenameersons


*So a little change on the code I proposed.*

def show():
allowedtables = ['table1','table2']
tablename = request.args(0)
if tablename in allowedtables:
rows = db(db[tablename]).select()
else:
rows = 'You can't access this table'

return dict(rows=rows)


http://myapp/default/show/ http://myapp/default/sections/tablename