Offending code from a fresh web2py welcome app:

in db.py

before auth.define_tables()

from gluon.contrib.populate import populate

auth.settings.extra_fields['auth_user'] = [Field('test_field_1','boolean')]

in controller default.py

def test():
    if db(db.auth_user.id>0).isempty():
         populate(db.auth_user,10)

    table = db.auth_user
    fields = ['id','first_name']
    fields.append('test_field_1')

    query = table.id > 0

    row = db(query).select(*fields).first().as_dict()

    profile = {'auth_fields':row,
               "other_stuff":{"hello":False},
              "second_bool":False}

    return response.json(profile)

This returns the following JSON response:

{"second_bool": false, "auth_fields": {"_extra": {"test_field_1": "T",
"first_name": "Corinne", "id": 1}}, "other_stuff": {"hello": false}}



On Wed, Apr 6, 2016 at 10:42 AM, Mark Graves <mgrave...@gmail.com> wrote:

> Hey Anthony and Richard,
>
> Yes you are both correct.
>
> I am attempting to create a usable JSON object.
>
> The confounding details from what I can tell are:
>
> 1.) the offending method is defined in a model file, which returns a
> dictionary, which is then json serialized via
>
> response.json(RETURNED_FROM_MODEL)
>
> This shouldn't be a problem.
>
> 2.) I am nesting the results of the row.as_dict() into another dictionary,
> which contains additional information ala.
>
> RETURNED_FROM_MODEL = {'row':row,'other_key':[]}
>
> The reason I moved the "extra" key into the dictionary manually is because
> when I did not, the row in the above line was returning it to me as a key
> in the json response.
>
> Its a nested serialization issue from what I can tell, because if I add
> another key into RETURNED_FROM_MODEL and set it explicitly as a boolean, it
> returns properly.  When I add a dictionary with a key that has a boolean
> value, it returns "T" or "F"
>
> I'm coming up with some example code now.
>
> On Wed, Apr 6, 2016 at 9:14 AM, Richard Vézina <
> ml.richard.vez...@gmail.com> wrote:
>
>> Yeah you right...
>>
>> On Wed, Apr 6, 2016 at 12:06 PM, Anthony <abasta...@gmail.com> wrote:
>>
>>> On Wednesday, April 6, 2016 at 11:30:34 AM UTC-4, Richard wrote:
>>>>
>>>> You maybe right Anthony abour update_record() it really depend though
>>>> of what he is trying todo...
>>>>
>>>
>>> Well at the point where row.update() is called, row is already a
>>> dictionary, so there is no .update_record() at that point. Also, the code
>>> is simply moving keys/values from the "extra" sub-dictionary into the
>>> top-level of the dictionary, so presumably the intention isn't to change
>>> anything in the database record.
>>>
>>> Anthony
>>>
>>> --
>>> 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 web2py+unsubscr...@googlegroups.com.
>>> 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/JlAzUE46s_M/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> web2py+unsubscr...@googlegroups.com.
>> 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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to