My problem.

Use a session value as part of a select statement to determine what  
is shown in a SingleSelectField  on a form.

The current problem is getting the session data to be recognized when  
setting up the widget named "Task Name". I assume that I have to  
request the data for the widget in the Kid template instead of during  
initialization, But I am not sure how to do this or even if this is  
the correct approach.

from Controllers.py (non-relevant removed)
==============
name_list = people.build_list('name', orderBy=people.q.name)
project_list = project.build_list('name')

class ProjectFields(widgets.WidgetsList):
     w_project = widgets.SingleSelectField(label="Project Name",  
options=project_list, default=1)

class TimeFields(widgets.WidgetsList):
     w_name = widgets.SingleSelectField(label="Person Name",  
options=name_list, default=1 )
     w_days = widgets.TextField(label="Days Charged", default="1.0")
     w_task = widgets.SingleSelectField(label="Task Name",  
options=lambda:[(p.id, p.taskName) for p in task.select 
(task.q.projectID==cherrypy.session['cur_project'],  
orderBy=task.q.taskName)])

time_form = widgets.TableForm(fields=TimeFields(), action="save")
project_form = widgets.TableForm(fields=ProjectFields(),  
action="changeProject")

class Root(controllers.RootController):

     @expose(template="timesheetweb.templates.timeEntry")
     def timeEntry(self, tg_errors=None):
         cherrypy.session['cur_project'] = cherrypy.session.get 
('cur_project', 1)
         cherrypy.session['we_date'] = cherrypy.session.get 
('we_date', datetime.date.today())
         cherrypy.session['cur_person'] = cherrypy.session.get 
('cur_person', 1)
         if tg_errors:
             flash("Data Entry Error!")
         return dict(form1=project_form, form=time_form,  
def_proj=cherrypy.session['cur_project'], def_date=cherrypy.session 
['we_date'], cur_person=cherrypy.session['cur_person'])

     @expose()
     @validate(form=time_form)
     @error_handler(time)
     def save(self, w_name, w_days, w_task, w_date):
         cherrypy.session['we_date'] = w_date
         cherrypy.session['cur_person'] = w_name
         time(personID=w_name, taskID=w_task, weekEnding=w_date,  
daysCharged=w_days)
         flash("Added Record")
         raise redirect("timeEntry")

     @expose()
     def changeProject(self, w_project):
         global current_project
         cherrypy.session['cur_project'] = string.atoi(w_project)
         raise redirect("timeEntry")

Kid Template (timeEntry):
===========
<body>
        <p py:content="form1(submit_text='Change Project')">Project Form</p>
        <p py:content="form(submit_text='Save Entry')">Time Form</p>
</body>

Current Error:
===========
Traceback (most recent call last):
   File "./start-timesheetweb.py", line 26, in ?
     from timesheetweb.controllers import Root
   File "/Volumes/ConsultingProjectsCurrent/PCI/TimeApplication/ 
TimeSheetWeb/timesheetweb/controllers.py", line 19, in ?
     class TimeFields(widgets.WidgetsList):
   File "/Volumes/ConsultingProjectsCurrent/PCI/TimeApplication/ 
TimeSheetWeb/timesheetweb/controllers.py", line 22, in TimeFields
     w_task = widgets.SingleSelectField(label="Task Name",  
options=lambda:[(p.id, p.taskName) for p in task.select 
(task.q.projectID==cherrypy.session['cur_project'],  
orderBy=task.q.taskName)])
   File "/Maui-Dev/TurboGears/turbogears/turbogears/widgets/meta.py",  
line 142, in widget_init
     func(self, *args, **kw)
   File "/Maui-Dev/TurboGears/turbogears/turbogears/widgets/ 
forms.py", line 789, in __init__
     validator = self._guess_validator()
   File "/Maui-Dev/TurboGears/turbogears/turbogears/widgets/ 
forms.py", line 809, in _guess_validator
     sample_option = self._get_sample_option()
   File "/Maui-Dev/TurboGears/turbogears/turbogears/widgets/ 
forms.py", line 822, in _get_sample_option
     options = self._extend_options(self.options)
   File "/Maui-Dev/TurboGears/turbogears/turbogears/widgets/meta.py",  
line 95, in __get__
     return param()
   File "/Volumes/ConsultingProjectsCurrent/PCI/TimeApplication/ 
TimeSheetWeb/timesheetweb/controllers.py", line 22, in <lambda>
     w_task = widgets.SingleSelectField(label="Task Name",  
options=lambda:[(p.id, p.taskName) for p in task.select 
(task.q.projectID==cherrypy.session['cur_project'],  
orderBy=task.q.taskName)])
   File "/Maui-Dev/TurboGears/turbogears/thirdparty/cherrypy/cherrypy/ 
filters/sessionfilter.py", line 431, in __getattr__
     sess = cherrypy.request._session
   File "/Maui-Dev/TurboGears/turbogears/thirdparty/cherrypy/cherrypy/ 
__init__.py", line 42, in __getattr__
     childobject = getattr(serving, self.__attrname__)
AttributeError: 'thread._local' object has no attribute 'request'

Environment:
==========
TurboGears Complete Version Information

TurboGears requires:

* TurboGears 1.1a0
* nose 0.9.0
* configobj 4.3.2
* RuleDispatch 0.5a0.dev-r2100
* setuptools 0.6c3
* FormEncode 0.5.1
* cElementTree 1.0.5-20051216
* PasteScript 0.9.7
* elementtree 1.2.6
* simplejson 1.3
* SQLObject 0.7.1dev-r1860
* CherryPy 2.2.1
* Genshi 0.3.2
* TurboKid 0.9.9
* TurboCheetah 0.9.5
* TurboJson 0.9.9
* PyProtocols 1.0a0
* Cheetah 1.0
* PasteDeploy 0.4
* Paste 0.5dev-r4745
* FormEncode 0.5.1
* kid 0.9.3
* Cheetah 1.0
* elementtree 1.2.6

Identity Providers

* sqlobject (TurboGears 1.1a0)
* sqlalchemy (TurboGears 1.1a0)

tg-admin Commands

* info (TurboGears 1.1a0)
* shell (TurboGears 1.1a0)
* quickstart (TurboGears 1.1a0)
* update (TurboGears 1.1a0)
* sql (TurboGears 1.1a0)
* i18n (TurboGears 1.1a0)
* toolbox (TurboGears 1.1a0)

Visit Managers

* sqlobject (TurboGears 1.1a0)
* sqlalchemy (TurboGears 1.1a0)

Template Engines

* cheetah (TurboCheetah 0.9.5)
* json (TurboJson 0.9.9)
* kid (TurboKid 0.9.9)
* genshi-markup (Genshi 0.3.2)
* genshi-text (Genshi 0.3.2)
* genshi (Genshi 0.3.2)

Widget Packages


TurboGears Extensions

* visit (TurboGears 1.1a0)
* identity (TurboGears 1.1a0)
* fastdata (TGFastData 0.9a6)

--~--~---------~--~----~------------~-------~--~----~
 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