[web2py] Re: Where should I put my application logic code?

2013-12-31 Thread 黄祥
granma said : 'everything is wonderful if you know how to appreciate it' imho models : yet in the books said that is better to not put the logic function in models - Minimize the code in models: do not define functions there, define functions in the controllers that need them or - even b

[web2py] Re: Where should I put my application logic code?

2013-12-31 Thread Anthony
> > 2. the web2py modules is like python modules, it automatically compile it, > so you will got *pyc for every module you create in here, and i think it > will increaase the performance in byte compile rather in script. > Note, if you use admin to compile the application, you get the same bene

[web2py] Re: Where should I put my application logic code?

2013-12-31 Thread Anthony
> > Looks like to me *modules *is the best place. But the new problem is the > global objects and classes are not visible to files in modules unlike files > in models/controllers. I am not sure which packages need to be imported. It > will be convenient if *modules *folder can be treated same a

[web2py] Re: Where should I put my application logic code?

2013-12-31 Thread Phil Hughes
Add an argument to the function: foo(bar): Only functions with no arguments can be called from the outside world. On Tuesday, December 31, 2013 3:57:56 AM UTC-6, Wei Li wrote: > > Hi, > > This could be a silly question:) . I am going to build up some > application logic. So I will create a few

Re: [web2py] Re: Where should I put my application logic code?

2013-12-31 Thread Wei Li
Thank you all for the replies! On Tue, Dec 31, 2013 at 1:10 PM, Phil Hughes wrote: > Add an argument to the function: foo(bar): Only functions with no > arguments can be called from the outside world. > > > On Tuesday, December 31, 2013 3:57:56 AM UTC-6, Wei Li wrote: >> >> Hi, >> >> This coul

Re: [web2py] Re: Where should I put my application logic code?

2014-01-05 Thread Alex
I've quite a lot model files (~40), so far the performance is still very good. Since it is not very optimal and also not good in the long run I'm now thinking of rewriting the code into modules. I'm struggling a little bit to rewrite the functions. E.g. consider following function in a model: @

Re: [web2py] Re: Where should I put my application logic code?

2014-01-05 Thread Anthony
If you want to do it with a decorator, you can use @lazy_cache (see http://web2py.com/books/default/chapter/29/04/the-core#Accessing-the-API-from-Python-modules). Otherwise, you can just use current.cache to store the return value of the function. Anthony On Sunday, January 5, 2014 8:13:59 AM

Re: [web2py] Re: Where should I put my application logic code?

2014-01-05 Thread Alex
thanks Anthony! it's working with lazy_cache decorator. I guess the @ is missing in the documentation example: lazy_cache('key', time_expire=60, cache_model='ram') def f(a,b,c,): Alex Am Sonntag, 5. Januar 2014 16:20:37 UTC+1 schrieb Anthony: > > If you want to do it with a decorator, you

Re: [web2py] Re: Where should I put my application logic code?

2014-01-05 Thread Alex
It's working fine locally but when I try to run it on the server (compiled application) I get the following error: ImportError: No module named myapp.modules.room any idea what I could be missing? on the server the module .py files are under myapp/modules Alex Am Sonntag, 5. Januar 2014 17:25

Re: [web2py] Re: Where should I put my application logic code?

2014-01-05 Thread 黄祥
i think it related with module name, try to change your module file name into unique name. i usually use the app name with the controller file name. e.g. modules/myapp_mycontroller.py of course you can use whatever module file name as you want, but please make it unique. best regards, stifan -

Re: [web2py] Re: Where should I put my application logic code?

2014-01-06 Thread Alex
thanks! that's a good tip. Unfortunately the error still exists: ImportError: No module named myapp.modules.myapp_room the file modules/myapp_room.py exists on the server. what else could be missing? Alex Am Montag, 6. Januar 2014 01:32:09 UTC+1 schrieb 黄祥: > > i think it related with module

Re: [web2py] Re: Where should I put my application logic code?

2014-01-06 Thread 黄祥
it's hard to help you track the error. please try to create the module from simple like in the book. e.g. */test/modules/justforlearn.py* from gluon import * def ip(): return current.request.client */test/controllers/default.py* from gluon.custom_import import track_changes; track_changes(True) i