Can I convert an Odoo browse object to JSON - python

I'm trying to integrate reactjs with Odoo, and successfully created components. Now my problem is that I cant get the JSON via odoo. The odoo programmer has to write special api request to make this happen. This is taking more time and code repetitions are plenty.
I tried may suggestions and none worked.
Is there a better way to convert the browse objects, that odoo generate, to JSON ?
Note: Entirely new to python and odoo, please forgive my mistakes, if any mentioned above.

maybe this will help you:
Step 1: Create js that runs reqiest to /example_link
Step 2: Create controller who listens that link #http.route('/example_link', type="json")
Step 3: return from that function json return json.dumps(res) where res is python dictionary and also dont forget to import json.
Thats all, it's not very hard, hope I helped you, good luck.

Related

How To Search For Specific Definition in Dictionary API

I am a super beginner and decided to try to create a project where I have to use an API so that I can advance my skills. I feel like I am in way over my head though I am sure this task would be simple for an advanced programmer.
I am using the Merriam Webster's Dictionary API to try to define some Spanish song lyrics. Through using the lyricsgenius module I was able to print the lyrics to a song, and now my issue is figuring out how to use the dictionary API to pull the definition for a specific word that I give it, and print it out. All I have done so far is this:
import requests
response = requests.get('https://dictionaryapi.com/api/v3/references/spanish/json/test?key=mykey').json()
print(response)
When I run this I get what seems to be to be a huge array of dictionaries filled with data that I do not understand, and I am very confused what I am supposed to do in order to get the result that I want. Am I supposed to alter the URL to let it know what specific information I want? How do I even go about figuring out what to do? The API Documentation site is also very difficult to understand as a beginner. Thank you for your help.

Is it possible to load a Google Ads custom report via API into production DB

Looking through the API documentation it seems that there's currently no way to access a custom report via the API. If this is, in fact, the case, is there a workaround to make this possible?
The goal is to get a modified version of this report shown on the web interface:
No, you need to build the report yourself and call it with the API unfortunately.
Depending on how complex the report is, it can be done pretty quickly. You can quickly generate the GAQL needed for your APU query using this tool: https://developers.google.com/google-ads/api/fields/v7/overview_query_builder
This will save you typing out all the resources manually, and will even validate it for you.
If you're stuck, let us know what report you're trying to generate and we can help with the GAQL.

In python what is a response object returned from a website?

I'm trying to use the etsy API and I was finally able to get it running from the source. I gave it my key, and it returned the following when printed out.
<etsy._v2.EtsyV2 object at 0xb7284ccc>
However I have no idea what to do with it. The github-repo doesn't have much documentation, and the command that is suppose to follow doesn't work. I read the Etsy API and didn't find the mentioned command getFrontFeaturedListings like the github listed.
I've had this issue before with an HTTP response object and I was told to use response.content to check out more info on the object. It didn't work for this object so I'm wondering if there was a simple way to test any generic object, or at least see what this object contains?
When in doubt you can always use the dir built-in method on an arbitrary python object. This will show you methods and fields attached to the object. https://docs.python.org/3/library/functions.html#dir
Anyway, sorry to hear about the poor documentation of the library. Last time I used Etsy's API I just created a little class that used requests. It wasn't much work since Etsy lays out all of the URIs + documentation nicely on their developer site. https://www.etsy.com/developers/documentation/reference/favoritelisting

Setting up a Python ViewServer for CouchDB

I am trying to get up to speed with CouchDB. As a relatively new user on Python, I am trying to set up a view-server so that I can pass on python functions to couchdb.design.ViewDefinitions function. As I understand, ViewDefinitions take javascript code to execute map/reduce function.
Here is what I struggle to understand - I am well aware that this might be a basic question. According to wiki (http://wiki.apache.org/couchdb/View_server):
To register query servers with CouchDB, add a line for each server to local.ini. The basic syntax is:
'[query_servers] python=/usr/bin/couchpy'
How do I access local.ini file? I am an 10.6.8 Mac user. Thanks!
Update: Thank you Kxepal. It seems I was able to create the design/view on Futon in Python. Alternatively, I figured that python viewserver can be created as follows:
curl -X PUT http://[localhost]/_config/query_servers/python '"/path/to/couchpy"'
However, I still cannot execute the python script. Running the view on Couch results in following:
'Error: An error occurred accessing the view no response'
I would appreciate if somebody can point in the right direction. Thanks!
I encountered the same "Error: An error occurred accessing the view no response" problem, and it turned out to be a bug in my python code. Specifically, in the javascript implementation I had something like:
function (doc) {
emit(doc.somefield, doc);
}
I had converted this to:
def map(doc):
yield doc.somefield, doc
However, this gave me the "no response" error you describe.
Changing it to the following fixed the problem.
def map(doc):
yield doc['somefield'], doc
I don't know there OSX keeps CouchDB config files, but you always may setup Python query server through Futon. On sidebar click Configuration, than "Add section" at the bottom of the page and fill the fields with same data as you planned to write into local.ini. As bonus, you don't need restart CouchDB - configuration changes through HTTP API are applied instantly, but be sure that you'd specified correct values.

How to implement Google Suggest in your own web application (e.g. using Python)

In my website, users have the possibility to store links.
During typing the internet address into the designated field I would like to display a suggest/autocomplete box similar to Google Suggest or the Chrome Omnibar.
Example:
User is typing as URL:
http://www.sta
Suggestions which would be displayed:
http://www.staples.com
http://www.starbucks.com
http://www.stackoverflow.com
How can I achieve this while not reinventing the wheel? :)
You could try with
http://google.com/complete/search?output=toolbar&q=keyword
and then parse the xml result.
I did this once before in a Django server. There's two parts - client-side and server-side.
Client side you will have to send out XmlHttpRequests to the server as the user is typing, and then when the information comes back, display it. This part will require a decent amount of javascript, including some tricky parts like callbacks and keypress handlers.
Server side you will have to handle the XmlHttpRequests which will be something that contains what the user has typed so far. Like a url of
www.yoursite.com/suggest?typed=www.sta
and then respond with the suggestions encoded in some way. (I'd recommend JSON-encoding the suggestions.) You also have to actually get the suggestions from your database, this could be just a simple SQL call or something else depending on your framework.
But the server-side part is pretty simple. The client-side part is trickier, I think. I found this article helpful
He's writing things in php, but the client side work is pretty much the same. In particular you might find his CSS helpful.
Yahoo has a good autocomplete control.
They have a sample here..
Obviously this does nothing to help you out in getting the data - but it looks like you have your own source and arent actually looking to get data from Google.
If you want the auto-complete to use date from your own database, you'll need to do the search yourself and update the suggestions using AJAX as users type. For the search part, you might want to look at Lucene.
That control is often called a word wheel. MSDN has a recent walkthrough on writing one with LINQ. There are two critical aspects: deferred execution and lazy evaluation. The article has source code too.

Categories