Fast work! Thanks
On Tuesday, November 27, 2012 8:16:22 AM UTC-8, Massimo Di Pierro wrote:
>
> Good catch! Fixed in trunk.
>
> On Tuesday, 27 November 2012 03:37:43 UTC-6, roger wrote:
>>
>> Hi there,
>>
>> I just tracked down a thorny problem I was having with Storage.getlist(),
>> and think it may be useful to folks.
>>
>> The particular situation was a strange edge-case, where I'm wanting a
>> request.vars value as a list, so am calling:
>> my_ids = request.vars.getlist('my_id')
>>
>> The problem was that in this case request.vars.my_id = "" (empty string)
>> And, unfortunately request.vars.getlist('my_id') was returning "" (and
>> not [""] as was hoped)
>>
>> Looking at the source-code for getlist:
>> def getlist(self, key):
>> value =
>> self.get<http://www.web2py.com/examples/static/epydoc/web2py.gluon.storage-pysrc.html#>(key,
>>
>> [])
>> return value if not value else \
>> value if isinstance(value, (list, tuple)) else [value]
>>
>> It seems that the "return value if not value..." is confusing things,
>> since "" (empty string) will evaluate as False.
>>
>> I've redefined Storage.getlist() in my code as:
>> def getlist(self, key):
>> value = self.get(key, [])
>> if value is None or isinstance(value, (list, tuple)):
>> return value
>> else:
>> return [value]
>>
>> and it seems to work for me now.
>>
>> Thoughts?
>>
>>
--