跳至內容
選單
此問題已被標幟
1 回覆
4919 瀏覽次數

Hello all,

    In the file :

    odoo-8.0-20150920/openerp/addons/web/controllers/main.py

    There is the method :

        def login_redirect()

            url = '/web/loginPTPTPTPT555?'

            # built the redirect url, keeping all the query parameters of the url

            redirect_url = '%s?%s' % (request.httprequest.base_url, werkzeug.urls.url_encode(request.params))

            return """<html><head><script>

            window.location = '%sredirect=' + encodeURIComponent("%s" + location.hash);

            </script></head></html>

            """ % (url, redirect_url)


How to override such a method who is not in a class?

頭像
捨棄
最佳答案

This is what it's called monkey patch. (https://en.wikipedia.org/wiki/Monkey_patch)

Like this:

from openerp.addons.web.controllers import main
def new_login_redirect():
    ...
main.login_redirect = new_login_redirect
頭像
捨棄
作者

very interesting. Will try it soon. Thanks again Axel!

作者

Is this a good way to work or not?

Obviously is not the first choice and is not good if you have another way to do it, if you don't have an alternative? You can go with this method, I used, Gevent used and I'm sure more people is using it.

作者

It works. thanks again.

相關帖文 回覆 瀏覽次數 活動
1
3月 21
21301
1
2月 16
5393
0
5月 16
3402
2
12月 15
3482
1
5月 23
2451