On Sat, 5 May 2007 at 01:35, AJ wrote:
> Doesn't this work:
>
> referer = cherrypy.request.headers['REFERER']
> HiddenField(name='referer', default=referer)
>
> (Me thinks I'm missing the point here ... :-S )
AttributeError: 'thread._local' object has no attribute 'request'
So no, it doesn't work :) Keep in mind that the form is being
built at compile time, not request time.
I found a google hit about allowing default to be a callable in
ToscaWidgets. Guess there's been no similar fix to TG widgets, at least
not in 1.0.1. I subclassed HiddenField and overrode adjust_values to
allow it:
class FixedHiddenField(HiddenField):
def adjust_value(self, value, **kw):
value = super(FixedHiddenField,self).adjust_value(value, **kw)
if callable(value): value = value()
return value
form = TableForm(
fields=fields+[FixedHiddenField(name='referer',
default=lambda: request.headers['Referer'])])
Now my forms are happy :)
--David
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---