Raj schrieb:
> My aim is to build a TG1.0.4.4 application which can be extended by
> independently developed small TG applications.
> For that, i have to split my controllers,models,templates,static files
> etc into multiple directories.
> Everything works fine except the model part.
> 
> I have done it as described below
> *)Created a 'models' directory
> *)Within that created two model files eg: a.py and b.py
> *)Created an __init__.py file within the models directory with
> contents
>  from turbogears.database import PackageHub
> __connection__ = hub = PackageHub('projectname')
> from projectname.models.a import *
> from projectname.models.b import *
> I could run the application without any problems.
> But, when I added values into a SingleSelectField widget, the
> problems
> began to arise
> *)I created a form widget with a SingleSelectField as shown below:
> class FormFields(widgets.WidgetsList):
>     txnType=categories =
> widgets.SingleSelectField(options=getValuesFromA())
> Here getValuesFromA() is a callable which returns a list of tuples
> required for the SingleSelectField as shown below:
> def getValuesFromA():
>     vals = [(A.field1, A.field2)
>                    for item in A.select()]
>     return vals
> Here 'A' is a model class in a.py
> When trying to run the application, the following error occurs.
>         KeyError: 'No database configuration found!'
> 
> After this i changed something to get it work.
> 
> *)I moved the form widget code to a controller definition (URLrequest
> handler) as shown below
> class ControllerClass(controllers.Controller)
> ....
> ...
> @...(...)
> def RequestHandlerA(self,*args,**kwargs)
>     class FormFields(widgets.WidgetsList):
>  
> txnType=widgets.SingleSelectField(options=[(entry.field1,entry.field2)
> for entry in A.select()])
>    ...rest of code....
> 
> Now it worked!!!
> That is the 'database configuration' can be 'found' at run time only.
> But this is not the actual result for me.
> I want to specify the widget form outside my controller functions.
> 
> Can anybody help me in this regard.

Again, the above code *calls* the getValuesFromA when *defining* the 
widget. *Don't* do that. Pass only the callable.

Diez

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to