Thank you , Massimo!
No. code in models is executed at every request. Code in modules is
importent only once and cached. It is executed when functions in the
module are called (as in normal python).
On Dec 11, 2:51 pm, Constantine Vasil wrote:
> Just to confirm:
>
> If I put a code in /modules folder is it imported e
Just to confirm:
If I put a code in /modules folder is it imported every time
on each function request?
I want it imported on demand only when I need it.
Thank you, I tested it and it works both ways.
On Saturday, December 10, 2011 11:29:49 PM UTC-5, Constantine Vasil wrote:
>
> I just put my classes in site-packages/models.py
>
> and the 'from models import *' made the classes available globally.
>
> So if I put them in /modules/models.py it would be the same?
>
It should work the same -- le
As Anthony pointed out rightly, if you need that module for a specific
app, then put it in modules folder.
If that module is required to be imported in other apps as well, then
put it in site-packages folder.
HTH
-- Vineet
On Dec 11, 9:29 am, Constantine Vasil wrote:
> I just put my classes in
I just put my classes in site-packages/models.py
and the 'from models import *' made the classes available globally.
So if I put them in /modules/models.py it would be the same?
You should be able to do the same from the application's /modules folder.
Use site-packages if it's a module that needs to be accessed by multiple
applications (or possibly by other Python programs).
Anthony
On Saturday, December 10, 2011 7:09:32 PM UTC-5, Constantine Vasil wrote:
>
> Hi Vineet
Hi Vineet,
Thank you! Absolutely - you understood my question properly.
It seems that solution is very simple, I am so overwhelmed
with this porting that sometimes I oversee the simplest
solutions ;)
So if I put it under site-packages like this:
site-packages/models
site-packages/definitions
I
@Constantine Vasil
I had a similat task earlier.
I am using a third party library named 'DABO'.
Placed that in 'site-packages' folder within 'web2py' (source) &
imported that in models & controllers as required.
(Before that, I had tried placing it in 'modules' folder, but could
not import in contr
On Thursday, December 8, 2011 9:29:42 PM UTC-5, Constantine Vasil wrote:
>
>
> OK let put it in reverse - how you would do this (GAE)/
>
> in default.py
> myaccount = MyAccount.get_profile(user_id)
>
What happens when you do:
from module_that_defines_MyAccount import MyAccount
myaccount =
OK let put it in reverse - how you would do this (GAE)/
in default.py
myaccount = MyAccount.get_profile(user_id)
Please note that 'in module'
root = MyAccountRoot.get_profile()
does not works - it says 'not available' or something.
in default.py to import custom import yo
On Thursday, December 8, 2011 6:22:31 PM UTC-5, Constantine Vasil wrote:
>
> I tried to move to modules but got the following issues:
>
> This is not possible - e.g. to acces the class directly without a prefix -
> when I have a lot of code if I cannot do that it is a lot of work adding
> a prefix
They are a lot of model definitions - it is a big project which I am porting
to web2py. Django templates were easy to translate. GAE working with
web2py - took me a lot of time be I did it. Making the PyDev+Ecilpse+GAE
SDK environment to work with debugging - very hard but it is done.
Now the fin
I tried to move to modules but got the following issues:
This is not possible - e.g. to acces the class directly without a prefix -
when I have a lot of code if I cannot do that it is a lot of work adding
a prefix.
myclass = MyClass.profile(id)
name = myclass.name
Also if I have several related
BTW, do you have a large number of model definitions? Have you measured the
performance hit? It might not be that big.
Another option is conditional
models: http://web2py.com/book/default/chapter/04#Workflow. You can define
models that execute only for a particular controller and even a particu
You can move code to modules if you don't want it all executed on every
request. In that case, you'll either have to use the 'current' object or
pass global objects (such as 'db') to your module functions and methods.
See
http://web2py.com/book/default/chapter/04#Accessing-the-API-from-Python-m
17 matches
Mail list logo