I'm populating the options of a SingleSelectField with a database query; however, I need to filter the query based on which user is logged in. In my controllers I simply call request.identity['repoze.who.userid'] to find the user with which I filter the data. When I try to make a call to request.identity from my a form, I get the following error: AttributeError: identity
How can I find out which user is logged in from a form? If that's not possible in that context, how do I pass a variable from my controller to the form holding the user id?
I can just give you a vague answer, but there are methods on the widget, which get called within the .display() call in your template. If you supply values to the call to .display(), you can access those in that functions and use it to display dynamic dropdown options.
> I'm populating the options of a SingleSelectField with a database query; > however, I need to filter the query based on which user is logged in. In > my controllers I simply call request.identity['repoze.who.userid'] to find > the user with which I filter the data. When I try to make a call > to request.identity from my a form, I get the following > error: AttributeError: identity
> How can I find out which user is logged in from a form? If that's not > possible in that context, how do I pass a variable from my controller to > the form holding the user id?
On Friday, November 2, 2012 5:01:10 PM UTC-4, Moritz Schlarb wrote:
> I can just give you a vague answer, but there are methods on the widget, > which get called within the .display() call in your template. > If you supply values to the call to .display(), you can access those in > that functions and use it to display dynamic dropdown options.
> self.value holds exactly what you pass in to the call to .display().
> Am Freitag, 2. November 2012 15:39:13 UTC+1 schrieb RyanWilson:
>> Hi,
>> I'm populating the options of a SingleSelectField with a database query; >> however, I need to filter the query based on which user is logged in. In >> my controllers I simply call request.identity['repoze.who.userid'] to find >> the user with which I filter the data. When I try to make a call >> to request.identity from my a form, I get the following >> error: AttributeError: identity
>> How can I find out which user is logged in from a form? If that's not >> possible in that context, how do I pass a variable from my controller to >> the form holding the user id?
On Saturday, November 3, 2012 1:01:32 AM UTC-4, RyanWilson wrote:
> Thank you!
> I didn't know how to access what I pass into .display()
> self.value should give me what I'm looking for.
> Best,
> Ryan
> On Friday, November 2, 2012 5:01:10 PM UTC-4, Moritz Schlarb wrote:
>> I can just give you a vague answer, but there are methods on the widget, >> which get called within the .display() call in your template. >> If you supply values to the call to .display(), you can access those in >> that functions and use it to display dynamic dropdown options.
>> self.value holds exactly what you pass in to the call to .display().
>> Am Freitag, 2. November 2012 15:39:13 UTC+1 schrieb RyanWilson:
>>> Hi,
>>> I'm populating the options of a SingleSelectField with a database query; >>> however, I need to filter the query based on which user is logged in. In >>> my controllers I simply call request.identity['repoze.who.userid'] to find >>> the user with which I filter the data. When I try to make a call >>> to request.identity from my a form, I get the following >>> error: AttributeError: identity
>>> How can I find out which user is logged in from a form? If that's not >>> possible in that context, how do I pass a variable from my controller to >>> the form holding the user id?