hi, all,

thank you so much for your detail explaination, i'm understand right now.

i can simplified the other function (show and view) but for search result
and feed, i can't pass it to another function.

1. why i can't pass row.title into variable?
def blog_result():
pattern = '%' + request.vars.keyword.lower() + '%'
 pages = db(db.blog.title.lower().like(pattern)).select(orderby =
db.blog.title)
items = [A(T(*row.title*), _href = URL('blog_show', args = row.id)) for row
in pages]
 return UL(*items).xml()

2. rss feed error, when i tried to passed the variable into it (title, link,
description)?
def blog_feed():
    blogs = db().select(db.blog.ALL, orderby = db.blog.title)
    return dict(title = *'Blog Feed'*, link = *'
http://127.0.0.1:8000/stevevanchristie/main/blog'*, description = *'Blog RSS
Feed'*, created_on = request.now, items = [dict(title = row.title, link =
URL('blog_show', args = row.id), description =
MARKMIN(row.content).xml(), created_on = row.created_on) for row in blogs])

could anyone explain to me where is my fault?

thank you very much

steve van christie

On Sun, Apr 10, 2011 at 6:10 AM, Anthony <[email protected]> wrote:

> On Saturday, April 9, 2011 6:40:03 PM UTC-4, 黄祥 wrote:
>>
>> actually my real intention is :
>>
>> i have the same function that repeated many times in 1 controller
>> (repeated to different tables), so that i would to make it simple just put
>> it on modules, what do you think about it?
>>
>> if i created the new function in 1 controller and then the other function
>> access it, i don't like because it can be access by the browser url, is
>> there any way to prevent it? (i mean i created 1 function, and the other
>> function access it, and can't be accessed via browser url)
>>
>
> As explained here (http://web2py.com/book/default/chapter/04#Dispatching),
> any function in a controller that either (a) takes any arguments or (b)
> starts with an underscore cannot be accessed via a URL. In your case, the
> 'manage' function takes arguments, so it cannot be accessed directly via URL
> (try it). If it didn't take any arguments and you still wanted to make it
> inaccessible, you could rename it to '_manage' (or simply give it a dummy
> argument that isn't used).
>
>
>>
>> pardon, if i'm not wrong, i read that to put the function on the model is
>> not the best practice, what do you think about it?
>>
>
> I think it's OK to put a function in a model file if it is used across
> multiple controllers, particularly if the function needs access to the
> web2py global objects (that way, you don't have to worry about passing the
> globals to the function). If you have a few such helper functions, it would
> probably make sense to put them into a special helper model file (rather
> than sticking them all in your db.py file). At some point, it might make
> sense to start moving some functions out into modules and importing them
> when needed, but that's probably not necessary until your app starts to get
> a lot bigger and more complex. One thing to keep in mind -- model files are
> executed in alphabetical order, so don't put something in a model file if it
> needs to refer to something that's defined in another model file that comes
> later in alphabetical order.
>
> Anthony
>

Reply via email to