[IMP] Display all questions in CMS

bzr revid: rim@openerp.com-20131106152406-j1puozfk65h2oayh
This commit is contained in:
Richard Mathot (OpenERP)
2013-11-06 16:24:06 +01:00
parent f937225b59
commit 5fb20ba152
3 changed files with 164 additions and 120 deletions
+20 -9
View File
@@ -34,7 +34,7 @@ class WebsiteSurvey(http.Controller):
@website.route(['/survey/',
'/survey/list/'],
type='http', auth='public', multilang=True)
def list_surveys(self, survey_id=None, page_id=None, **post):
def list_surveys(self, **post):
'''All the public surveys'''
cr, uid, context = request.cr, request.uid, request.context
survey_obj = request.registry['survey.survey']
@@ -43,18 +43,29 @@ class WebsiteSurvey(http.Controller):
surveys = survey_obj.browse(cr, uid, survey_ids, context=context)
return request.website.render('survey.list', {'surveys': surveys})
@website.route(["/survey/fill/id-<int:survey_id>/",
"/survey/fill/id-<int:survey_id>/page-<int:page_id>"],
@website.route(["/survey/fill/<int:survey_id>/",
"/survey/fill/<int:survey_id>/page/",
"/survey/fill/<int:survey_id>/page/<int:page_index>/"],
type='http', auth='public', multilang=True)
def fill_survey(self, survey_id=None, page_id=None, **post):
def fill_survey(self, survey_id=None, page_index=None, **post):
'''Display a survey'''
cr, uid, context = request.cr, request.uid, request.context
survey_obj = request.registry['survey.survey']
survey = survey_obj.browse(cr, uid, survey_id, context=context)
pagination = {'current': -1, 'next': -1}
# if not page_id:
# pagination['next'] =
pagination = {'current': -1,
'next': 0}
if page_index is not None:
if page_index not in range(0, len(survey.page_ids)):
raise Exception("This page does not exist")
pagination['current'] = page_index
if page_index == len(survey.page_ids) - 1:
pagination['next'] = -1
else:
pagination['next'] = page_index + 1
return request.website.render('survey.survey', {'survey': survey,
'pagination': pagination})
return request.website.render('survey.survey',
{'survey': survey,
'pagination': pagination,
'debug': False,
'validation_error': None})
+3 -12
View File
@@ -77,7 +77,7 @@ class survey_survey(osv.osv):
base_url = self.pool.get('ir.config_parameter').get_param(cr, uid,
'web.base.url')
for survey_browse in self.browse(cr, uid, ids, context=context):
res[survey_browse.id] = urljoin(base_url, "survey/fill/id-%s"
res[survey_browse.id] = urljoin(base_url, "survey/fill/%s/"
% survey_browse.id)
return res
@@ -314,14 +314,7 @@ class survey_question(osv.osv):
''' Questions that will be asked in a survey.
Each question can have one of more suggested answers (eg. in case of
dropdown choices, multi-answer checkboxes, radio buttons...)
Changes
-------
This version of the model has been simplified in relation to the previous
one: some fields were simply a n-time repetition of a simpler field. It is
now allowed to have children question that allows to group subquestions.'''
dropdown choices, multi-answer checkboxes, radio buttons...).'''
_name = 'survey.question'
_description = 'Question'
_rec_name = 'question'
@@ -351,12 +344,10 @@ class survey_question(osv.osv):
('textbox', 'Text box'),
('numerical_box', 'Numerical box'),
('datetime', 'Date and Time'),
('checkbox', 'Checkbox'),
('simple_choice_scale', 'One choice on a scale'),
('simple_choice_dropdown', 'One choice in a menu'),
('multiple_choice', 'Some choices in checkboxes'),
('vector',
'Multi-questions'),
('vector', 'Multi-questions'),
('matrix', 'Matrix')
], 'Question Type', required=1),
'suggested_answers_ids': fields.one2many('survey.suggestion',
+141 -99
View File
@@ -34,24 +34,28 @@
<div class="col-md-1"> </div>
<div class="col-md-1"> </div>
<div class="col-md-8">
<div class='jumbotron'>
<h1>
<t t-esc='survey.title'/>
<t t-if="survey.description is not False">
<br/>
<small><t t-esc='survey.description'/></small>
</t>
</h1>
</div>
<t t-if="pagination['current'] == -1">
<div class='jumbotron'>
<h1>
<t t-esc='survey.title'/>
<t t-if="survey.description is not False">
<br/>
<small><t t-esc='survey.description'/></small>
</t>
</h1>
</div>
</t>
<t t-if="pagination['current'] != -1">
<div class='page-header'>
<h1>
<t t-esc='survey.title'/>
</h1>
</div>
<t t-set='page' t-value="survey.page_ids[pagination['current']]" />
<t t-call="survey.page" />
</t>
<!-- <t t-if="pagination['current'] != -1">
<t t-call="pagination['current']" />
</t>
-->
<t t-foreach="survey.page_ids" t-as="page">
<t t-call="survey.page"/>
</t>
<t t-call='survey.navsub' />
<t t-call='survey.navsub' />
</div>
<div class="col-md-1"> </div>
@@ -64,123 +68,161 @@
<!-- Navigation & Submission -->
<template id="navsub" name="Footer for navigation and submission">
<div class="text-center">
<t t-if="pagination['current'] == -1"><button type="button" class="btn btn-primary">Take survey</button>
<t t-if="pagination['current'] != -1 and pagination['next'] != -1"><button type="button" class="btn btn-primary">Next page</button>
<t t-if="pagination['next'] == -1"><button type="button" class="btn btn-success">Submit survey</button></t></t></t>
<t t-if="pagination['current'] == -1"><a t-att-href="'/survey/fill/' + survey.id.__str__() + '/page/' + pagination['next'].__str__()" class="btn btn-primary active" role="button">Take survey</a></t>
<t t-if="pagination['current'] != -1 and pagination['next'] != -1"><a t-att-href="'/survey/fill/' + survey.id.__str__() + '/page/' + pagination['next'].__str__()" class="btn btn-primary active" role="button">Next page</a></t>
<t t-if="pagination['next'] == -1"><button t-att-href="'#'" class="btn btn-success active" role="submit">Submit survey</button></t>
</div>
</template>
<!-- A page -->
<template id="page" name="Page">
<div>
<h2><t t-esc='page.title' /></h2>
<p><t t-esc='page.description'/></p>
<p><t t-if="page.description"><t t-esc='page.description'/></t></p>
<p class="text-info text-right">Questions marked with <span class="glyphicon glyphicon-exclamation-sign"></span> are mandatory.</p>
</div>
<hr/>
<!-- Panel to display input errors -->
<t t-if="validation_error">
<div class="panel panel-danger">
<div class="panel-heading">
<h3 class="panel-title">Errors on this page</h3>
</div>
<div class="panel-body text-danger">
Some answers are missing or incorrect
</div>
</div>
</t>
<form role="form">
<t t-foreach='page.question_ids' t-as='question'>
<t t-call='survey.question'/>
</t>
</form>
<div>
<p class="text-info">Questions marked with <span class="glyphicon glyphicon-exclamation-sign"></span> are mandatory.</p>
</div>
</template>
<!-- A question -->
<template id='question' name='Question'>
<div class="form-group">
<!-- Detection of matrix/vector elements and creating flags for easy use -->
<t t-if="question.parent_id and question.children_ids"><t t-set="is_matrix_vector" t-value="True" /></t>
<t t-if="question.parent_id"><t t-set="is_vector_element" t-value="True" /></t>
<t t-if="not is_vector_element"> <!-- if -->
<h3>
<t t-if="question.constr_mandatory"><span class="glyphicon glyphicon-exclamation-sign"></span></t>
<t t-esc='question.sequence'/>. <t t-esc='question.question'/><br/>
<t t-esc='question.question'/><br/>
<small><t t-esc='question.description'/> -- [ <t t-esc='question.type'/> ]</small></h3>
<small><t t-if="question.description"><t t-esc='question.description'/></t></small>
</h3>
</t>
<t t-if="is_vector_element"> <!-- else -->
<t t-if="question.type == 'simple_choice_scale'">
<t t-esc='question.question'/><t t-raw="'&lt;/td&gt;&lt;td&gt;'" />
</t>
</t> <!-- endif -->
<!-- instanciating different types of questions -->
<t t-if="question.type in ['free_text']">
<textarea class="form-control" rows="3"></textarea>
<!-- instanciating different types of questions -->
<t t-if="question.type in ['free_text']">
<textarea class="form-control" rows="3"></textarea>
</t>
<t t-if="question.type in ['textbox']">
<input type="text" class="form-control" />
</t>
<t t-if="question.type in ['numerical_box']">
<input type="number" class="form-control"/>
</t>
<t t-if="question.type in ['datetime']">
<input type="datetime-local" class="form-control" />
TODO: replace html5 datetime widget by OpenERP-CMS datetime widget
</t>
<t t-if="question.type in ['simple_choice_scale']">
<t t-foreach='question.suggested_answers_ids' t-as='suggestion'>
<div class="radio-inline">
<label>
<input type="radio" t-att-name="suggestion.question_id.id" t-att-value='suggestion.value' />
<t t-esc='suggestion.value'/>
</label>
</div>
</t>
</t>
<t t-if="question.type in ['simple_choice_dropdown']">
<select class="form-control">
<t t-foreach='question.suggested_answers_ids' t-as='suggestion'>
<option><t t-esc='suggestion.value'/></option>
</t>
</select>
</t>
<t t-if="question.type in ['textbox']">
<input type="text" class="form-control" placeholder="Your answer" />
</t>
<t t-if="question.type in ['multiple_choice']">
<t t-foreach='question.suggested_answers_ids' t-as='suggestion'>
<div class="checkbox">
<label>
<input type="checkbox" t-att-name="suggestion.question_id.id" t-att-value='suggestion.value' />
<t t-esc='suggestion.value'/>
</label>
</div>
</t>
</t>
<t t-if="question.type in ['numerical_box']">
<input type="number" class="form-control"/>
</t>
<t t-if="question.type in ['vector']">
<t t-if="question.type in ['datetime']">
<input type="datetime-local" class="form-control" />
/!\ Datetime ne fonctionne pas sur tous les navigateurs... patch en JS ?
</t>
<t t-if="not is_matrix_vector">
<t t-raw="'&lt;table class=&quot;table table-responsive&quot;&gt;'" />
</t>
<t t-if="question.type in ['checkbox']">
Ici il faudrait afficher qqch ?
<input type="checkbox" class="form-control" />
</t>
<t t-if="question.type in ['simple_choice_scale']">
<t t-foreach='question.suggested_answers_ids' t-as='suggestion'>
<div class="radio-inline">
<label>
<input type="radio" t-att-name="suggestion.question_id" t-att-value='suggestion.value' />
<t t-esc='suggestion.value'/>
</label>
</div>
</t>
</t>
<t t-if="question.type in ['simple_choice_dropdown']">
<select class="form-control">
<t t-foreach='question.suggested_answers_ids' t-as='suggestion'>
<option><t t-esc='suggestion.value'/></option>
</t>
</select>
</t>
<t t-if="question.type in ['multiple_choice']">
<t t-foreach='question.suggested_answers_ids' t-as='suggestion'>
<div class="checkbox">
<label>
<input type="checkbox" t-att-name="suggestion.question_id" t-att-value='suggestion.value' />
<t t-esc='suggestion.value'/>
</label>
</div>
</t>
</t>
<t t-if="question.type in ['vector']">
TODO afficher les vector correctement
<t t-if="question.children_ids[0].type != 'simple_choice_scale'">
<tr>
<t t-foreach='question.children_ids' t-as='question'>
<t t-call='survey.question' />
<td><t t-call='survey.question' /></td>
</t>
</tr>
</t>
<t t-if="question.children_ids[0].type == 'simple_choice_scale'">
<t t-foreach='question.children_ids' t-as='question'>
<tr>
<td><t t-call='survey.question' /></td>
</tr>
</t>
</t>
<t t-if="not is_matrix_vector">
<t t-raw="'&lt;/table&gt;'" />
</t>
<t t-if="question.type in ['matrix']">
TODO afficher les matrix correctement
<t t-foreach='question.children_ids' t-as='question'>
<t t-call='survey.question' />
</t>
</t>
<t t-if="question.type in ['matrix']">
<table class="table table-responsive">
<t t-foreach='question.children_ids' t-as='question'>
<t t-call='survey.question' />
</t>
</table>
</t>
<!-- Comments -->
<t t-if="question.comments_allowed">
<div class="panel panel-default">
<div class="panel-heading">Any comments ?</div>
<div class="panel-body">
TODO afficher la boîte à commentaires
</div>
</div>
</t>
<!-- Comments -->
<t t-if="question.comments_allowed">
<div class="panel panel-default">
<div class="panel-heading">Any comments ?</div>
<div class="panel-body">
TODO: show comments box here
</div>
</div>
</template>
</data>
</openerp>
</t>
</template>
</data>
</openerp>