I've been testing the way you described above and it works, to a point. The 
models are not imported in alphabetical order. This seems to be controlled 
by this line (521):
models = listdir(path, '^\w+\.py$', 0, sort=False) in compileapp.py
listdir is essentially os.walk with a regexp for filtering and os.walk 
doesn't give any guarantees for ordering at all from what I understand.
Later in compileapp, the models found with listdir are looped through, once 
(not dependant on the regexp) which gives changing the regexp between 
models limited use.
To explain my issue, I'll try to use an example. Please bear with me!
Let's say I have the following models:

dbInterface/someDbFile.py

anotherInterface/someAnotherInterface.py

__init__.py
logic.py


Now let's assume that listdir lists the models root dir first, then 
anotherInterface dir and then dbInterface dir.
I want the dbInterface to load before anotherInterface since 
anotherInterface is dependant on dbInterface.

So in __init__.py I do:
response.models_to_run =['dbInterface/']

And in the someDbFile.py model, I change the regexp to:
response.models_to_run = ['anotherInterface/']

This will however cause stuff in anotherInterface to never be loaded since 
the loop in compileapp has already passed (and filtered out) all 
anotherInterface files once I get to the dbInterface files.

Is there any way I can control the order things are imported from 
subfolders without changing web2py? I am aware that just setting sort to 
true in the listdir-call will fix my issue but I would like to be able to 
update web2py without having to make that change each time, if possible.

Best regards,
Joel
Den fredagen den 23:e november 2012 kl. 05:28:22 UTC+1 skrev Anthony:
>
> You can now do:
>
> response.models_to_run = ['list', 'of', 'regexes']
>
> You can set that (and change it) in any model file. The regexes are 
> relative to the /models folder, so any model file with a relative file path 
> that matches one of the regexes will be executed. By default, the 
> response.models_to_run regexes are defined to enable the standard 
> conditional models (i.e., execute models in subfolders whose names match 
> the current controller and function). However, you can change it to 
> whatever you like. To run all models in all subfolders, somewhere in the 
> first model file, just do:
>
> response.models_to_run = ['.*']
>
> It is checked after each model is executed, so it can be changed 
> dynamically from one model file to another. Also, note that when specifying 
> file paths, always use '/' as the path separator, even on Windows.
>
> Anthony
>
> On Thursday, November 22, 2012 9:04:24 AM UTC-5, Joel Samuelsson wrote:
>>
>> Hi,
>>
>> I would like to have a subfolder structure in my models folder. I am 
>> aware that subfolders are only executed upon request from the user. I saw 
>> this thread however:
>>
>> https://groups.google.com/forum/?fromgroups=#!searchin/web2py/models$20subfolders/web2py/o8Ya4ZqNhLk/eoeLK7_45Z4J
>> But after that, I haven't been able to find any mention if the fix 
>> (mentioned in last message in above thread) was ever implemented.
>> Can I somehow get subfolders in my models catalogue to be executed 
>> without moding compileapp myself?
>>
>> Best regards,
>> Joel
>>
>

-- 



Reply via email to