Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to redefine a method of controller Odoo

By
tansadio
on 12/3/14, 11:01 AM 919 views

Can someone help me. I would just change the definition of a method of controllers website module. here is my code

import datetime
from itertools import islice
import json
import xml.etree.ElementTree as ET

import logging
import re

import werkzeug.utils
import urllib2
import werkzeug.wrappers
from PIL import Image

import openerp
from openerp.addons.web import http
from openerp.http import request, STATIC_CACHE
from openerp.tools import image_save_for_web
import openerp.addons.website.controllers.main as main

logger = logging.getLogger(__name__)
# Completely arbitrary limits
MAX_IMAGE_WIDTH, MAX_IMAGE_HEIGHT = IMAGE_LIMITS = (1024, 768)
LOC_PER_SITEMAP = 45000
SITEMAP_CACHE_TIME = datetime.timedelta(hours=12)



class Website_extend(main.Website):
     @http.route(['/website/seo_suggest/<keywords>'], type='http', auth="public", website=True)
     def seo_suggest(self, keywords):
         url = "http://google.com/complete/search?hl=fr"
         try:
             req = urllib2.Request("%s&%s" % (url, werkzeug.url_encode({
                 'ie': 'utf8', 'oe': 'utf8', 'output': 'toolbar', 'q': keywords})))
             request = urllib2.urlopen(req)
         except (urllib2.HTTPError, urllib2.URLError):
             return []
         xmlroot = ET.fromstring(request.read())
         return json.dumps([sugg[0].attrib['data'] for sugg in xmlroot if len(sugg) and sugg[0].attrib['data']])   

@tansadio, I'm also interested in achieving this. I'll write back if I find a solution. Please post back here if you find a solution as well.

Luke Branch
on 12/4/14, 5:46 AM

it works well on localhost but on the server it takes me an error like: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 224: ordinal not in range

tansadio
on 12/4/14, 7:21 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 12/3/14, 11:01 AM
Seen: 919 times
Last updated: 3/16/15, 8:10 AM