[FIX] Prefill fix + [REF] Moving some code

bzr revid: rim@openerp.com-20131220095845-494qswdk5f8mu88e
This commit is contained in:
Richard Mathot (OpenERP) 2013-12-20 10:58:45 +01:00
parent 3415da8b65
commit 83efed9f39
3 changed files with 20 additions and 14 deletions

View File

@ -205,9 +205,12 @@ class WebsiteSurvey(http.Controller):
answer_value = answer.value_number.__str__()
elif answer.answer_type == 'date':
answer_value = answer.value_date
elif answer.answer_type == 'suggestion':
elif answer.answer_type == 'suggestion' and not answer.value_suggested_row:
answer_value = answer.value_suggested.id
# TODO mettre les QCM ici
elif answer.answer_type == 'suggestion' and answer.value_suggested_row:
answer_tag = "%s_%s_%s" % (answer_tag, answer.value_suggested_row.id, answer.value_suggested.id)
answer_value = answer.value_suggested.id
# TODO vérifier QCM et matrices
if answer_value:
ret.update({answer_tag: answer_value})
else:
@ -274,11 +277,21 @@ class WebsiteSurvey(http.Controller):
return json.dumps(ret)
# Printing routes
@website.route(['/survey/print/<model("survey.survey"):survey>/'],
@website.route(['/survey/print/<model("survey.survey"):survey>/',
'/survey/print/<model("survey.survey"):survey>/<string:token>/'],
type='http', auth='user', multilang=True)
def print_empty_survey(self, survey=None, **post):
'''Display an empty survey in printable view'''
def print_survey(self, survey, token=None, **post):
'''Display an survey in printable view; if <token> is set, it will
grab the answers of the user_input_id that has <token>.'''
return request.website.render('survey.survey_print',
{'survey': survey, 'page_nr': 0})
def dict_soft_update(dictionary, key, value):
''' Insert the pair <key>: <value> into the <dictionary> '''
if key in dictionary:
dictionary[key].append(value)
else:
dictionary.update({key: [value]})
# vim: exp and tab: smartindent: tabstop=4: softtabstop=4: shiftwidth=4:

View File

@ -67,7 +67,7 @@ $(document).ready(function () {
console.log(json_data);
_.each(json_data, function(value, key){
the_form.find(".form-control[name=" + key + "]").val(value);
the_form.find("input[type='radio'][name=" + key + "]").val([value]);
the_form.find("input[name=" + key + "]").val([value]);
});
})
.fail(function(){

View File

@ -1109,6 +1109,7 @@ class survey_user_input_line(osv.osv):
ca = dict_keys_startswith(post, answer_tag)
no_answers = True
# TODO gérer le cas des matrices monochoix
for col in question.labels_ids:
for row in question.labels_ids_2:
a_tag = "%s_%s_%s" % (answer_tag, row.id, col.id)
@ -1130,12 +1131,4 @@ def dict_keys_startswith(dictionary, string):
This function uses dictionary comprehensions (Python >= 2.7)'''
return {k: dictionary[k] for k in filter(lambda key: key.startswith(string), dictionary.keys())}
def dict_soft_update(dictionary, key, value):
''' Insert the pair <key>: <value> into the <dictionary> '''
if key in dictionary:
dictionary[key].append(value)
else:
dictionary.update({key: [value]})
# vim: exp and tab: smartindent: tabstop=4: softtabstop=4: shiftwidth=4: