Re: [web2py] Re: how to define functions in modules and then import it

2011-04-09 Thread pbreit
Are you getting an error? What is working fine? What are these: "__view(parameters), __feed(parameters), __result(parameters)"? A suggestion would be to skip the ajax and paging for now. That can complicate things and is not really necessary. Keep things as simple as possible.

Re: [web2py] Re: how to define functions in modules and then import it

2011-04-09 Thread Stifan Kristi
pardon me, i just follow the example that was written on the book: http://web2py.com/book/default/chapter/03 and it works fine, but i want to make it simple, i mean create __view(parameters), __feed(parameters), __result(parameters), and then the other function call it and pass the arguments.

Re: [web2py] Re: how to define functions in modules and then import it

2011-04-09 Thread pbreit
That code has *lots* of problems. First, there's no db() call so you're not going to have any rows. You don't do the "onkeyup" like that. You need to do it in the view as shown in the book: http://web2py.com/book/default/chapter/10#The-ajax-Function You're going to have a problem if "len(reques

Re: [web2py] Re: how to define functions in modules and then import it

2011-04-09 Thread Stifan Kristi
thank you so much for your explaination. pardon, because i'm a newbie in python n web2py, i just learn, try to implement what have been written in the http://web2py.com/book/default/ the other controller that can't be passed is *blog_result* like on below : def bl

Re: [web2py] Re: how to define functions in modules and then import it

2011-04-09 Thread pbreit
T() is for text translations and I'm not sure you can use it (or would want to) with non-static text. That dict() looks a little messy. For one thing, you can simply include blogs=blogs. Some of those things I would put in the view instead (MARKMIN(().xml(), URL('blog_show')). Also, since views

Re: [web2py] Re: how to define functions in modules and then import it

2011-04-09 Thread Stifan Kristi
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

Re: [web2py] Re: how to define functions in modules and then import it

2011-04-09 Thread Anthony
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 cr

Re: [web2py] Re: how to define functions in modules and then import it

2011-04-09 Thread Jonathan Lundell
On Apr 9, 2011, at 3:40 PM, Stifan Kristi 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 th

Re: [web2py] Re: how to define functions in modules and then import it

2011-04-09 Thread Stifan Kristi
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

Re: [web2py] Re: how to define functions in modules and then import it

2011-04-09 Thread pbreit
The one project I've seen that is sort of designed how you are suggesting is InstantPress: http://code.google.com/p/instant-press/ But I agree with Anthony, I always encourage keeping it simple. There's a saying about premature optimization and it's not good.

Re: [web2py] Re: how to define functions in modules and then import it

2011-04-09 Thread Anthony
You wouldn't generally want to define your DAL connection or crud in your module -- instead, you would likely want to define them in your models and then pass them to your module function as arguments. I think you would do something like: def manage(request, db, crud, title, table) and then

Re: [web2py] Re: how to define functions in modules and then import it

2011-04-09 Thread pbreit
If you're new (or not) to Python or Web2py, I would suggest: First: put the functions in the controllers that call them Second: put the function in "models" if multiple controllers need to call it Third: local_import() from "modules" if it doesn't need access to the web2py environment (pass in "r

Re: [web2py] Re: how to define functions in modules and then import it

2011-04-09 Thread Stifan Kristi
i've tried to run what you suggested, but still have a problem: On Modules: #!/usr/bin/env python # coding: utf8 from gluon.html import * from gluon.http import * from gluon.validators import * from gluon.sqlhtml import * # request, response, session, cache, T, db(s) # must be passed and cannot be

Re: [web2py] Re: how to define functions in modules and then import it

2011-04-09 Thread Stifan Kristi
thank you so much for your explaination, i've already read that url, honestly i'm the newbie in python and web2py, could you please give an example how to pass the global objects to the function as arguments? i've already test for the simple thing, it work, but for global objects i'm still confused

[web2py] Re: how to define functions in modules and then import it

2011-04-09 Thread Anthony
See http://web2py.com/book/default/chapter/04#Third-Party-Modules. Note, if your function needs to refer to some of the web2py global objects (as yours does), then you will need to explicitly pass them to the function as arguments (external modules cannot "see" web2py globals). On Saturday, Ap