Hmmm...I would have expected a LOAD(...ajax=True) to trigger conditional
models properly.
Not the answer you're looking for but I very strongly advise against
premature optimization (ie, conditional models).
On Monday, June 4, 2012 12:01:17 PM UTC-7, anonymouse wrote:
>
> Hi all,
>
> I'm having an issue trying to load a component that relies on
> conditionally loaded models.
>
> It appears that either the conditional model file is not
> executed/evaluated using the LOAD function.
>
> The following files are relevant to this issue:
>
> models/people/personnel.py
> controllers/people.py
> controllers/contact.py
> views/contact/index.html
> views/people/index.html
>
>
> The quick solution would clearly be to take the conditional model out of
> "people" so that it is available to the "contact" controller, but I was
> wondering if there were any another solutions which allow the "people"
> model file to still be executed conditionally.
>
> Perhaps I would be better off putting the model in modules and having the
> model/personnel.py file import the table definition from modules, and add
> another import statement to the "contact" controller and any other
> controllers outside of people that use personnel data (though at present,
> contact is the ONLY one)?
>
> I would think that LOAD would execute the conditional model but perhaps
> there is a good reason it does not? I could just be using components/LOAD
> completely wrong, but if not then maybe this is a good candidate for a
> feature request?
>
> If anyone can shed some light on this issue, please, shed away!
>
> Below are the parts my app that are relevant:
>
> ### Models: models/people/personnel.py
> db.define_table('people',
> Field(...) # Defines name, position, user-id -- this is NOT meant for any
> sort of access control, just a list of people in our institution
> ...
> )
>
>
> ### I have two controllers:
> # controller - people.py
> def index():
> if request.args(0):
> people = db(db.people.positition == request.args(0)).select()
> else:
> people = db(db.people).select()
> return dict(people=people)
>
> # contact.py
> def index():
> ... build contact form, do form validation, etc ...
> return dict(form=form)
>
> # and my contact view
> # views/contact/index.html contains this LOAD statement:
> {{ = LOAD('people','index',args=['faculty']) }}
>
> When I attempt to view the page /app/contact/index
>
> I get the error:
> KeyError: people
>
> The error is of course generated in the 2nd line of the people.py index
> function.
>
> When I attempt to view /app/people/index everything works perfectly.
>
> Can I use LOAD with conditional models?
>