[IMP] Website viewing of questions
bzr revid: rim@openerp.com-20131105152821-qfotzlvxutwfw932
This commit is contained in:
@@ -22,11 +22,11 @@
|
||||
from openerp.addons.web import http
|
||||
from openerp.addons.web.http import request
|
||||
from openerp.addons.website.models import website
|
||||
from openerp.tools.translate import _
|
||||
from openerp.tools.safe_eval import safe_eval
|
||||
# from openerp.tools.translate import _
|
||||
# from openerp.tools.safe_eval import safe_eval
|
||||
|
||||
import simplejson
|
||||
import werkzeug
|
||||
# import simplejson
|
||||
# import werkzeug
|
||||
|
||||
|
||||
class WebsiteSurvey(http.Controller):
|
||||
@@ -41,12 +41,16 @@ class WebsiteSurvey(http.Controller):
|
||||
survey_ids = survey_obj.search(cr, uid, [('state', '=', 'open')],
|
||||
context=context)
|
||||
surveys = survey_obj.browse(cr, uid, survey_ids, context=context)
|
||||
values = {'surveys': surveys}
|
||||
return request.website.render('survey.list', values)
|
||||
return request.website.render('survey.list', {'surveys': surveys})
|
||||
|
||||
@website.route(["/survey/fill/id/<int:survey_id>/"],
|
||||
@website.route(["/survey/fill/id/<int:survey_id>/",
|
||||
"/survey/fill/id/<int:survey_id>/page/<int:page_id>"],
|
||||
type='http', auth='public', multilang=True)
|
||||
def fill_survey(self, survey_id=None, page_id=None, **post):
|
||||
'''All the public surveys'''
|
||||
# do nothing
|
||||
return request.website.render('survey.survey')
|
||||
'''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)
|
||||
return request.website.render('survey.survey',
|
||||
{'survey': survey})
|
||||
|
||||
@@ -283,9 +283,6 @@ class survey_page(osv.osv):
|
||||
help="An introductory text to your page", translate=True,
|
||||
oldname="note"),
|
||||
}
|
||||
_defaults = {
|
||||
'sequence': 1
|
||||
}
|
||||
|
||||
# Public methods #
|
||||
|
||||
@@ -341,7 +338,7 @@ class survey_question(osv.osv):
|
||||
'parent_id': fields.many2one('survey.question', 'Parent question'),
|
||||
'children_ids': fields.one2many('survey.question', 'parent_id',
|
||||
'Children questions'),
|
||||
'sequence': fields.integer('Sequence'),
|
||||
'sequence': fields.integer(string='Sequence'),
|
||||
|
||||
# Question
|
||||
'question': fields.char('Question', required=1, translate=True),
|
||||
@@ -410,7 +407,6 @@ class survey_question(osv.osv):
|
||||
oldname='req_error_msg'),
|
||||
}
|
||||
_defaults = {
|
||||
'sequence': 1,
|
||||
'page_id': lambda s, cr, uid, c: c.get('page_id'),
|
||||
'type': 'free_text',
|
||||
|
||||
|
||||
@@ -30,13 +30,142 @@
|
||||
<t t-call="website.layout">
|
||||
<div class="wrap">
|
||||
<div class="container">
|
||||
<div class='jumbotron'>
|
||||
<h1><t t-esc='title'/></h1>
|
||||
<p><t t-esc='description'/></p>
|
||||
<div class="row">
|
||||
<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-foreach="survey.page_ids" t-as="page">
|
||||
<t t-call='survey.page' />
|
||||
</t>
|
||||
</div>
|
||||
<div class="col-md-1"> </div>
|
||||
<div class="col-md-1"> </div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</template>
|
||||
</data>
|
||||
|
||||
<!-- A page -->
|
||||
<template id="page" name="Page">
|
||||
<div>
|
||||
<h2><t t-esc='page.title' /></h2>
|
||||
<p><t t-esc='page.description'/></p>
|
||||
</div>
|
||||
<form role="form">
|
||||
<t t-foreach='page.question_ids' t-as='question'>
|
||||
<t t-call='survey.question'/>
|
||||
</t>
|
||||
<button type="button" class="btn btn-primary">Next page</button>
|
||||
</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">
|
||||
<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/>
|
||||
|
||||
<small><t t-esc='question.description'/> -- [ <t t-esc='question.type'/> ]</small></h3>
|
||||
|
||||
<!-- 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" placeholder="Your answer" />
|
||||
</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" />
|
||||
/!\ Datetime ne fonctionne pas sur tous les navigateurs... patch en JS ?
|
||||
</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-foreach='question.children_ids' t-as='question'>
|
||||
<t t-call='survey.question' />
|
||||
</t>
|
||||
</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>
|
||||
|
||||
|
||||
<!-- 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>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
Reference in New Issue
Block a user