Actually I do get an error:
rest_action = _action().get(method, None)
AttributeError: 'NoneType' object has no attribute 'get'
On Thursday, January 30, 2014 7:28:23 PM UTC+2, Avi A wrote:
>
> Thanks for the explanation.
> It stiil doesn't add records to the table.
> Is there any where I can see the error? on the admin there are no errors,
> and not on the console where i post.
> Thanks.
>
> On Thursday, January 30, 2014 7:00:32 PM UTC+2, Anthony wrote:
>>
>> On Thursday, January 30, 2014 10:33:19 AM UTC-5, Avi A wrote:
>>>
>>> Sorry for the "not working", I thought my mistake would be obvious.
>>>
>>
>> Describing the specific failure often makes it easier to home in on the
>> source of the problem.
>>
>>
>>> First line: does it mean that this "if" statement knows to search the
>>> auth.user records till it finds a match?
>>>
>>
>> Yes, it's simply a query to see if any auth_user records contain an
>> api_key that matches the one submitted. You were doing this query in
>> Python, when it is far more efficient to have the database do it for you
>> (particularly if you create a database index on the api_key field).
>>
>>
>>> and what is the .count() for?
>>>
>>
>> When doing the query, there is no need to return the matching records --
>> you just need to know whether any such records exist. So, it is more
>> efficient just to get a count of the records (if the count is 0, there are
>> no matching records).
>>
>>
>>> Second line:
>>> t._filter_fields(**post_params)
>>> Should work assuming the key on the url params matches exactly the field
>>> name on the table?
>>>
>>
>> Yes, that assumes the URL parameters match the field names of the table.
>> Note, ._filter_fields() simply removes any keys from the dictionary that
>> don't match any of the field names in the table (in this case, it would
>> remove the api_key key, since that's not part of the db table). You could
>> also manually remove any extra fields from the dictionary. For example:
>>
>> if db(db.auth_user.api_key == post_params.pop('api_key')).count():
>> return t.validate_and_insert(**post_params)
>>
>> post_params.pop('api_key') extracts the api_key value from post_params
>> and then removes that key/value from post_params, leaving only the keys
>> associated with fields in the db table.
>>
>> 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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.