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

change @http.route() type args dynamically

By
Sah Vinay Mahabir
on 11/3/16, 6:20 AM 305 views

I have a requirement which i have to call same controller but i need to change controller type["HTTP", "JSON"] based on condition
here is controller definition

@http.route('/controller', auth="public")
Now the problem is i have to call same controller based on the request type send to my controller, like this
if it send request to '/controller' of type "HTTP" then dynamicallythis controller should become
 @http.route('/controller', auth="public", type="http")
and if it send request to '/controller' of type "JSON" then dynamically this controller should become
@http.route('/controller', auth="public", type="json")
i have tried writing controller like this
class my_controller(http.Controller)
     __dynamicallyType= None
     @http.route('/controller', auth="public", type= __dynamicallyType)

i can change variable "__dynamicallyTypefrom" another function before this controller is about to call ans i can see "__dynamicallyTypefrom" value change during runtime but the controller is not able to change its type dynamically, it assume to be change whatever i assign for first time, once the value is passed to the type of the controller then type of the controller do not change for next run
Any hint or trick or hack if fine

1

Jérémy Kersten (jke)

--Jérémy Kersten (jke)--
2993
| 3 2 5
Jodoigne, Belgium
--Jérémy Kersten (jke)--

Jérémy is a member of the core R&D team since september 2013. He developed several projects for OpenERP version 8 including the eCommerce, the Google Calendar synchronization and the new product variants/configurator. Now, he manages Odoo website and themes for saas.

Jérémy Kersten (jke)
On 11/14/16, 9:02 AM

IMHO, not possible...


What you can try, use 2 controllers which call common method...


    @http.route('/http', type='http', auth="none")    
def xhttp(self):
        return self.xmagic()

    @http.route('/json', type='json', auth="none")
def xjson(self):
        return self.xmagic(reqtype='json')

    def xmagic(self, reqtype='http'):
        l = ['a','b','c']
 if reqtype == 'http':
            return str(l)
else:
            return l


That will return:

    

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: 11/3/16, 6:20 AM
Seen: 305 times
Last updated: 11/17/16, 9:21 AM