Got it. Unfortunately, I don't think there is a way to prevent the "_extra"
key from being added to each Row in this case, so .as_list() will end up
including it. You'll either have to remove the "_extra" keys after calling
.as_list(), or write your own function to convert the Rows to a list of
dictionaries.
Feel free to submit a Github issue (to the PyDAL repo, not the web2py repo)
suggesting that "with alias" fields not be added to the "_extra" dictionary
(it appears to be unnecessary, as the alias is already added as a top level
attribute of the Row object).
Anthony
On Friday, July 22, 2016 at 1:56:34 AM UTC-4, Eric wrote:
>
> Hi Anthony,
>
> My code is the following:
>
> # -*- coding: utf-8 -*-
> from gluon.serializers import json
>
>
> @auth.requires(lambda: AuthHelper.valid_token(), requires_login=False)
> @request.restful()
> def search():
> session.forget()
>
> def post(*args, **vars):
> response.headers["Content-Type"] = "application/json"
> retval, error = RequestHelper.parse(request)
>
> if error is not None:
> return json(error)
>
> encoded_zip = int(StringHelper.encode_postcode(retval["zip_code"]))
> house_number = int(retval["house_number"])
>
> return json(dict(result=db((db.addresses.encoded_zip_code ==
> encoded_zip) & (db.addresses.house_number == house_number)).select(
> db.addresses.street.with_alias('straat'),
> db.addresses.city.with_alias('plaats),
> distinct=True).as_list()))
>
> return dict(GET=post, POST=post)
>
>
>
> 2016-07-21 17:12 GMT+02:00 Anthony <[email protected]>:
>
>> Please show your code.
>>
>> On Wednesday, July 20, 2016 at 3:55:19 PM UTC-4, Eric wrote:
>>>
>>> Hi Anthony,
>>>
>>> I'm not including them. I'm only using with_alias() and the select in
>>> combination with as_list(). I would not expect to get the _extra as a
>>> little bonus when you use with_alias()...
>>>
>>> That's why I'm asking :)
>>>
>>> Greetings,
>>>
>>> Eric
>>>
>>>
>>> 2016-07-20 20:56 GMT+02:00 Anthony <[email protected]>:
>>>
>>>> The "_extra" dictionary stores values generated from expressions
>>>> (rather than raw values from individual fields). If you don't want them to
>>>> appear in the conversion of the Rows to a list of dictionaries, then don't
>>>> include them in the original .select() call that generated the Rows object.
>>>>
>>>> Anthony
>>>>
>>>> On Wednesday, July 20, 2016 at 10:00:57 AM UTC-4, Eric wrote:
>>>>>
>>>>> Hi There,
>>>>>
>>>>> Is there a way in Web2Py to suppress the _extra information when
>>>>> selecting data with as_list() or as_dict()?
>>>>>
>>>>> I can't find it and option for it, but maybe I'm just overlooking it
>>>>> in the documentation ;)
>>>>>
>>>>> Thanks!
>>>>>
>>>> --
>>>> Resources:
>>>> - http://web2py.com
>>>> - http://web2py.com/book (Documentation)
>>>> - http://github.com/web2py/web2py (Source code)
>>>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>>>> ---
>>>> You received this message because you are subscribed to a topic in the
>>>> Google Groups "web2py-users" group.
>>>> To unsubscribe from this topic, visit
>>>> https://groups.google.com/d/topic/web2py/d3YmI1e3iaQ/unsubscribe.
>>>> To unsubscribe from this group and all its topics, send an email to
>>>> [email protected].
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>> --
>> Resources:
>> - http://web2py.com
>> - http://web2py.com/book (Documentation)
>> - http://github.com/web2py/web2py (Source code)
>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>> ---
>> You received this message because you are subscribed to a topic in the
>> Google Groups "web2py-users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/web2py/d3YmI1e3iaQ/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.