Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
4930 มุมมอง

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.

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
มี.ค. 21
21306
1
ก.พ. 16
5394
0
พ.ค. 16
3405
override a method inheritance แก้ไขแล้ว
2
ธ.ค. 15
3482
1
พ.ค. 23
2456