Odoo Help


Qweb templating (Python side) : Access survey_user_input model on survey template using t-field ?

Yassine TEIMI
on 11/25/15, 6:07 PM 1,934 views


As you know t-field gives fields access via browsable record.

For the survey module, it's used on survey qweb template. For example, for the survey_init template (the first page of every started survey, describing survey title, and description) here is the code using t-field :

 <template id="survey_init" name="Survey"> 

<t t-call="website.layout">
<div class="wrap">
<div class="oe_structure" />
<div class="container">
<div groups="base.group_website_publisher" t-ignore="true" class="text-right">
<a href="/web#action=survey.action_survey_form" class="btn btn-default">Go back to su rveys</a>
<div class='jumbotron mt32'>
<h1 t-field='survey.title' />
<div t-field='survey.description' class="oe_no_empty"/>
<a class="btn btn-primary btn-lg" t-att-href="'/survey/fill/%s/%s' % (slug(survey ), token)">
Start Survey
<div class="oe_structure" />

So how this is can be done ?

Humble answer : After inspecting the controllers code, it's the start_survey() method that is responsible of launching the survey, it takes the variable survey as a parameter, and send it via data dictionnary trough : website.request.render, wich allows access survey fields value using t-field.

Here is the code part (For one page rendering case "test survey" among others) explainig that :


type='http', auth='public', website=True)
def start_survey(self, survey, token=None, **post):
cr, uid, context = request.cr, request.uid, request.context
    survey_obj = request.registry['survey.survey']
    user_input_obj = request.registry['survey.user_input']
    # Test mode
    if token and token == "phantom":
        _logger.info("[survey] Phantom mode")
        user_input_id = user_input_obj.create(cr, uid, {'survey_id': survey.id, 'test_entry': True}, context=context)
        user_input = user_input_obj.browse(cr, uid, [user_input_id], context=context)[0]
        data = {'survey': survey, 'page': None, 'token': user_input.token}
    return request.website.render('survey.survey_init', data)

My question here is how survey is passed as a parameter ? is it by using @route ?

If I know how to pass more parameters to start_survey(), then maybe I can pass a parameter named like "survey_user_input" trough data dictionnary, allowing me to use it on t-field.


I'm calling my survey from hr_evaluation_interview model from the hr_evaluation module.

Here is the method calling survey from hr_evaluation module (maybe I can use it to pass a parameter to start survey via context) :

 def action_start_survey(self, cr, uid, ids, context=None): 
''' Open the website page with the survey form '''
    trail = ""
    context = dict(context or {}, relative_url=True)
    if 'survey_token' in context:
        trail = "/" + context['survey_token']
    return {
        'type': 'ir.actions.act_url',
        'name': "Start Survey",
        'target': 'self',
        'url': self.read(cr, uid, ids, ['public_url'], context=context)[0]['public_url'] + trail

I hope my question is clear, if not, I'm here for further explainations.

Many thanks for your help.

Axel Mendoza
On 11/25/15, 7:16 PM

The argument survey is converted and passed by the @route decorator, converting the positional param of the url to a model object using a model argument pattern converter declared in the url param of the @route decorator and passed to the handle method of the url. 

See more here about that:



Odoo provides an additional converter called model which provides records directly when given their id. Let's use this to create a generic page for teacher biographies:

So you need to redefine the method and the @route url pattern and the method arguments to match the url pattern.

The url returned on the method action_start_survey need to match the @route url pattern so add the id value of the survey_user_input param to the url obtained from the field public_url or to the trail var, the thing is that the result url need to match the url for the @route overrided

Thanks a lot Axel for your explainations, I'm now trying to override : action_start_survey method called from hr_interview (I did'nt included it on my post), it's the first called method, that calls action_start_survey of the survey model. (So functionnaly speaking, it's like using action_start_survey for a human ressources evaluation purpose). Then I'll override action_start_survey of the survey module, and then override @route decorator and start_survey() method. I'll post my code, and further details soon. Thanks for your valuable help.

Yassine TEIMI
on 11/26/15, 6:50 AM

Hi Axel, it worked : On the first action_start_survey (on hr_interview object) I had to pass a browsable record of it, using context, and then on action_start_survey(survey object), modify trail, and add slug(context['interview']) to the url, and finally on the start_survey() method override @route decorator and pass the parameter, then send it via data dictionnary to the qweb view, and it's ready to use. I have to do the same for print_survey() and fill_survey(). Thanks a lot Axel for your help.

Yassine TEIMI
on 11/26/15, 11:45 AM

Happy to help

Axel Mendoza
on 11/26/15, 1:43 PM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 11/25/15, 6:07 PM
Seen: 1934 times
Last updated: 11/26/15, 9:48 AM