Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
4928 Lượt xem

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?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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
Ảnh đại diện
Huỷ bỏ
Tác giả

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

Tác giả

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.

Tác giả

It works. thanks again.

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 21
21306
1
thg 2 16
5394
0
thg 5 16
3405
2
thg 12 15
3482
1
thg 5 23
2456