I understand the "if", only the .count() I don't understand.

On Thursday, January 30, 2014 5:33:19 PM UTC+2, Avi A wrote:
>
> Sorry for the "not working", I thought my mistake would be obvious. On the 
> console where i sent the post i got "Process finished with exit code 0" but 
> i could not see that anything was updated on the table.
> Regarding your answer,
> First line: does it mean that this "if" statement knows to search the 
> auth.user records till it finds a match? and what is the .count() for?
> Second line: 
> t._filter_fields(**post_params)
> Should work assuming the key on the url params matches exactly the field 
> name on the table?
>
> (I tried earlier with the insert something like that as well :
> return t.validate_and_insert( t.f_test= post_params.f_test, etc")
> as well but I thought it was wrong in that context. The example on the 
> book wasn't clear to me. (return db.person.validate_and_insert(**fields) )
> )
> Thanks. 
>
>
> On Thursday, January 30, 2014 4:49:42 PM UTC+2, Anthony wrote:
>>
>> Generally it's helpful if you can give more detail than just "not 
>> working". Anyway, note that an insert requires keywords and values, not 
>> just positional arguments. You can actually use post_params itself to do 
>> the insert. Also, no need to select and iterate over all auth_user records 
>> to check the API key -- just check for the existence of that single key via 
>> a query.
>>
>> if db(db.auth_user.api_key == post_params.api_key).count():
>>     return t.validate_and_insert(t._filter_fields(**post_params))
>>
>> Anthony
>>
>> On Thursday, January 30, 2014 5:30:52 AM UTC-5, Avi A wrote:
>>>
>>> Hi,
>>> I am trying something like that:
>>> #on one local script instance:
>>> import requests
>>>
>>> test_params = {'api_key': 'api_key', 'test': 'test', 'f_platform': 
>>> 'platform', 'f_device': 'device', 'f_steps': '10',
>>>                'f_matches':'7', 'f_missmatches': '3', 'f_missing': '0'}
>>> r = requests.post('http://127.0.0.1:8000/qatests/api', 
>>> params=test_params)
>>>
>>> #and the api function:
>>>
>>> @request.restful()
>>> def api():
>>>     response.view = 'generic.'+request.extension
>>>     def GET(search):
>>>         pass
>>>     clients = db(db.auth_user).select(db.auth_user.api_key)
>>>     t = db.t_tests_results
>>>     def POST(**post_params):
>>>         for client in clients:
>>>             if client.api_key == post_params.api_key:
>>>                 return t.validate_and_insert(post_params.test,
>>>                                         post_params.f_platform, 
>>> post_params.f_device,
>>>                                         post_params.f_steps, 
>>> post_params.f_matches,
>>>                                         post_params.f_missmatches, 
>>> post_params.f_missing)
>>>             else:
>>>                 raise HTTP(400)
>>>
>>> It's not working... Any help?
>>> 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 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/groups/opt_out.

Reply via email to