2013-11-05 10:36:54 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>).
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
from openerp.addons.web import http
|
|
|
|
from openerp.addons.web.http import request
|
|
|
|
from openerp.addons.website.models import website
|
2013-11-05 15:28:21 +00:00
|
|
|
# from openerp.tools.translate import _
|
|
|
|
# from openerp.tools.safe_eval import safe_eval
|
2013-11-05 10:36:54 +00:00
|
|
|
|
2013-11-05 15:28:21 +00:00
|
|
|
# import simplejson
|
2013-11-08 07:53:47 +00:00
|
|
|
import werkzeug
|
|
|
|
import logging
|
|
|
|
|
|
|
|
_logger = logging.getLogger(__name__)
|
2013-11-05 10:36:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
class WebsiteSurvey(http.Controller):
|
|
|
|
|
|
|
|
@website.route(['/survey/',
|
|
|
|
'/survey/list/'],
|
|
|
|
type='http', auth='public', multilang=True)
|
2013-11-06 15:24:06 +00:00
|
|
|
def list_surveys(self, **post):
|
2013-11-08 07:53:47 +00:00
|
|
|
'''Lists all the public surveys'''
|
2013-11-05 10:36:54 +00:00
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
|
|
|
survey_obj = request.registry['survey.survey']
|
2013-11-08 07:53:47 +00:00
|
|
|
survey_ids = survey_obj.search(cr, uid, [('state', '=', 'open'),
|
|
|
|
('page_ids', '!=', 'None')],
|
2013-11-05 10:36:54 +00:00
|
|
|
context=context)
|
|
|
|
surveys = survey_obj.browse(cr, uid, survey_ids, context=context)
|
2013-11-05 15:28:21 +00:00
|
|
|
return request.website.render('survey.list', {'surveys': surveys})
|
2013-11-05 10:36:54 +00:00
|
|
|
|
2013-11-08 07:53:47 +00:00
|
|
|
@website.route(['/survey/fill/<model("survey.survey"):survey>/'],
|
2013-11-05 10:36:54 +00:00
|
|
|
type='http', auth='public', multilang=True)
|
2013-11-08 07:53:47 +00:00
|
|
|
def fill_survey(self, survey=None, **post):
|
|
|
|
'''Display and validates a survey'''
|
2013-11-05 15:28:21 +00:00
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
|
|
|
survey_obj = request.registry['survey.survey']
|
2013-11-06 07:33:53 +00:00
|
|
|
|
2013-11-08 07:53:47 +00:00
|
|
|
# In case of bad survey, redirect to surveys list
|
|
|
|
if survey_obj.exists(cr, uid, survey.id, context=context) == []:
|
|
|
|
return werkzeug.utils.redirect("/survey/")
|
|
|
|
|
2013-11-08 14:24:06 +00:00
|
|
|
_logger.debug('Post request data: %s', post)
|
2013-11-08 07:53:47 +00:00
|
|
|
|
2013-11-13 13:55:32 +00:00
|
|
|
# Store answer data
|
|
|
|
# (/!\ assumes JavaScript validation of answers has succeeded!)
|
|
|
|
# TODO
|
2013-11-08 07:53:47 +00:00
|
|
|
|
2013-11-08 14:24:06 +00:00
|
|
|
# Display success message if totally succeeded
|
|
|
|
if post and post['next'] == "finished":
|
|
|
|
return request.website.render('survey.finished')
|
|
|
|
|
|
|
|
# Page selection
|
2013-11-13 13:55:32 +00:00
|
|
|
pagination = {'current': -1, 'next': 0}
|
|
|
|
# Default pagination if first opening
|
|
|
|
|
2013-11-08 07:53:47 +00:00
|
|
|
if 'current' in post and 'next' in post and post['next'] != "finished":
|
|
|
|
oldnext = int(post['next'])
|
|
|
|
if oldnext not in range(0, len(survey.page_ids)):
|
2013-11-06 15:24:06 +00:00
|
|
|
raise Exception("This page does not exist")
|
|
|
|
else:
|
2013-11-08 07:53:47 +00:00
|
|
|
pagination['current'] = oldnext
|
|
|
|
if oldnext == len(survey.page_ids) - 1:
|
|
|
|
pagination['next'] = 'finished'
|
|
|
|
else:
|
|
|
|
pagination['next'] = oldnext + 1
|
|
|
|
|
2013-11-06 15:24:06 +00:00
|
|
|
return request.website.render('survey.survey',
|
|
|
|
{'survey': survey,
|
2013-11-13 13:55:32 +00:00
|
|
|
'pagination': pagination})
|
2013-11-06 16:11:17 +00:00
|
|
|
|
2013-11-08 14:24:06 +00:00
|
|
|
@website.route(['/survey/print/<model("survey.survey"):survey>/'],
|
2013-11-06 16:11:17 +00:00
|
|
|
type='http', auth='public', multilang=True)
|
2013-11-08 14:24:06 +00:00
|
|
|
def print_empty_survey(self, survey=None, **post):
|
2013-11-08 07:53:47 +00:00
|
|
|
'''Display an empty survey in printable view'''
|
2013-11-08 14:24:06 +00:00
|
|
|
pagination = {'current': -1, 'next': 0}
|
2013-11-06 16:11:17 +00:00
|
|
|
return request.website.render('survey.survey_print',
|
2013-11-08 14:24:06 +00:00
|
|
|
{'survey': survey,
|
|
|
|
'pagination': pagination})
|