Browse Source

[REF] survey attachment

12.0
Rémi FRANÇOIS 5 years ago
parent
commit
f413d9c16e
  1. 1
      survey_attachment/__init__.py
  2. 6
      survey_attachment/__manifest__.py
  3. 2
      survey_attachment/controllers/__init__.py
  4. 40
      survey_attachment/controllers/main.py
  5. 2
      survey_attachment/i18n/fr.po
  6. 2
      survey_attachment/models/survey_question.py
  7. 12
      survey_attachment/models/survey_user_input_line.py
  8. BIN
      survey_attachment/static/description/icon.png
  9. BIN
      survey_attachment/static/description/image_2.png
  10. BIN
      survey_attachment/static/description/imge_1.png
  11. 21
      survey_attachment/static/description/index.html
  12. BIN
      survey_attachment/static/description/survey.jpg
  13. 53
      survey_attachment/templates/page.xml
  14. 45
      survey_attachment/templates/survey_print.xml
  15. 15
      survey_attachment/templates/upload_file.xml

1
survey_attachment/__init__.py

@ -1,2 +1 @@
from . import controllers
from . import models

6
survey_attachment/__manifest__.py

@ -7,8 +7,8 @@
This module provides a new type of question in surveys, that allows to join a file as answer.
""",
'description': """ """,
'author': 'Fogits Solutions',
'website': 'https://www.fogits.com/',
'author': 'Sudokeys',
'website': 'http://www.sudokeys.com/',
'license': 'AGPL-3',
'category': 'Marketing',
'depends': [
@ -28,7 +28,7 @@
'images': ['static/description/survey.jpg'],
'js': [],
'installable': True,
'maintainer': 'Fogits Solutions, Sudokeys',
'maintainer': 'Sudokeys',
'pre_init_hook': '',
'post_init_hook': '',
'uninstall_hook': '',

2
survey_attachment/controllers/__init__.py

@ -1,2 +0,0 @@
# -*- coding: utf-8 -*-
from . import main

40
survey_attachment/controllers/main.py

@ -1,40 +0,0 @@
# -*- coding: utf-8 -*-
from odoo import fields, http, SUPERUSER_ID
from odoo.http import request
from odoo.addons.survey.controllers.main import Survey
import logging
_logger = logging.getLogger(__name__)
class SurveyAttachment(Survey):
# Printing routes
@http.route(['/survey/print/<model("survey.survey"):survey>',
'/survey/print/<model("survey.survey"):survey>/<string:token>'],
type='http', auth='public', website=True)
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>.'''
survey_question = request.env['survey.question']
user_input = request.env['survey.user_input']
user_input_line = request.env['survey.user_input_line']
question_ids = survey_question.sudo().search([('type', '=', 'upload_file'), ('survey_id', '=', survey.id)])
user_input_id = user_input.sudo().search([('token', '=', token), ('survey_id', '=', survey.id)])
user_input_line_upload_file = []
for question in question_ids:
user_input_line = user_input_line.search([
('user_input_id', '=', user_input_id.id),
('survey_id', '=', survey.id),
('question_id', '=', question.id),
('answer_type', '=', 'upload_file')
])
user_input_line_upload_file.append(user_input_line)
return request.render('survey.survey_print',
{'survey': survey,
'token': token,
'page_nr': 0,
'quizz_correction': True if survey.quizz_mode and token else False,
'user_input_line_upload_file': user_input_line_upload_file})

2
survey_attachment/i18n/fr.po

@ -26,7 +26,7 @@ msgstr "Type de réponse"
#: selection:survey.user_input_line,answer_type:0
#, python-format
msgid "Attachment"
msgstr " jointe"
msgstr "Pièce jointe"
#. module: survey_attachment
#: code:addons/survey_attachment/models/survey_question.py:8

2
survey_attachment/models/survey_question.py

@ -16,5 +16,5 @@ TYPES = [
class SurveyQuestion(models.Model):
_inherit = 'survey.question'
question_attachment = fields.Binary(string="Joined attachment")
# question_attachment = fields.Binary(string="Joined attachment")
type = fields.Selection(selection=TYPES)

12
survey_attachment/models/survey_user_input_line.py

@ -1,7 +1,15 @@
# -*- coding: utf-8 -*-
import base64
from odoo import models, fields, api, _
from .survey_question import TYPES
ANSWER_TYPES = [
('text', _('Text')),
('number', _('Number')),
('date', _('Date')),
('free_text', _('Free Text')),
('upload_file', _('Attachment')),
('suggestion', _('Suggestion')),
]
FILE_TYPES = [
('image', _('Image')),
@ -12,7 +20,7 @@ FILE_TYPES = [
class SurveyUserInputLine(models.Model):
_inherit = 'survey.user_input_line'
answer_type = fields.Selection(selection=TYPES)
answer_type = fields.Selection(selection=ANSWER_TYPES)
file = fields.Binary(string='Uploaded file')
filename = fields.Char(string='Uploaded file name')
file_type = fields.Selection(selection=FILE_TYPES, string="File type")

BIN
survey_attachment/static/description/icon.png

Before

Width: 320  |  Height: 320  |  Size: 11 KiB

BIN
survey_attachment/static/description/image_2.png

Before

Width: 1767  |  Height: 868  |  Size: 57 KiB

BIN
survey_attachment/static/description/imge_1.png

Before

Width: 1881  |  Height: 903  |  Size: 74 KiB

21
survey_attachment/static/description/index.html

@ -1,21 +0,0 @@
<section class="oe_container app" style="border: 3px solid #c4d335;border-radius: 4px;box-shadow: 5px 10px 18px 6px#666666;">
<div class="oe_row oe_spaced" style="max-width: 95%;">
<div class="oe_span12">
<h2 class="oe_slogan" style="font-weight: bold;">Survey Attachment </h2>
<div class="oe_demo" style="font-weight: bold; margin: 30px auto 0; padding: 0 15px 0 0; border:none; width: 96%;">
<h3>This module allows you to upload file to survey ! </h3>
<br/>
<h3>Choose Type of question upload file</h3>
<img style="border: 2px solid #c4d335;" src="imge_1.png"/>
<br/>
<h3>Upload File here</h3>
<br/>
<img style="border: 2px solid #c4d335;" src="image_2.png"/>
<br/>
<br/>
</div>
</div>
</div>
</section>

BIN
survey_attachment/static/description/survey.jpg

Before

Width: 540  |  Height: 270  |  Size: 14 KiB

53
survey_attachment/templates/page.xml

@ -1,57 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="survey.page" name="Page">
<div class="page-header">
<p class="pull-right">Page <span t-raw='page_nr + 1'/> of <span t-raw="len(survey.page_ids)"/></p>
<h1 t-field='page.title' />
<div t-field='page.description' class="oe_no_empty"/>
</div>
<form role="form" method="post" class="js_surveyform" t-att-name="'%s_%s' % (survey.id, page.id)" t-att-action="'/survey/fill/%s/%s' % (slug(survey), token)" t-att-data-prefill="'/survey/prefill/%s/%s/%s' % (slug(survey), token, slug(page))" t-att-data-validate="'/survey/validate/%s' % (slug(survey))" t-att-data-submit="'/survey/submit/%s' % (slug(survey))">
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
<input type="hidden" name="page_id" t-att-value="page.id" />
<input type="hidden" name="token" t-att-value="token" />
<t t-foreach='page.question_ids' t-as='question'>
<t t-set="prefix" t-value="'%s_%s_%s' % (survey.id, page.id, question.id)" />
<div class="js_question-wrapper" t-att-id="prefix">
<h2>
<span t-field='question.question' />
<span t-if="question.constr_mandatory" class="text-danger">*</span>
</h2>
<div t-field='question.description' class="text-muted oe_no_empty"/>
<t t-if="question.type == 'free_text'"><t t-call="survey.free_text"/></t>
<t t-if="question.type == 'textbox'"><t t-call="survey.textbox"/></t>
<t t-if="question.type == 'numerical_box'"><t t-call="survey.numerical_box"/></t>
<t t-if="question.type == 'date'"><t t-call="survey.date"/></t>
<t t-if="question.type == 'simple_choice'"><t t-call="survey.simple_choice"/></t>
<t t-if="question.type == 'multiple_choice'"><t t-call="survey.multiple_choice"/></t>
<t t-if="question.type == 'matrix'"><t t-call="survey.matrix"/></t>
<template id="page" name="Survey Attachment Page" inherit_id="survey.page">
<xpath expr="//div[hasclass('js_question-wrapper')]/t[last()]" position='after'>
<t t-if="question.type == 'upload_file'"><t t-call="survey_attachment.upload_file"/></t>
<div class="js_errzone alert alert-danger" style="display:none;"></div>
</div>
</t>
<div class="text-center mt16 mb16">
<button t-if="survey.users_can_go_back and page_nr > 0" type="submit" class="btn btn-default" name="button_submit" value="previous">Previous page</button>
<button t-if="not last" type="submit" class="btn btn-primary" name="button_submit" value="next">Next page</button>
<button t-if="last" type="submit" class="btn btn-primary" name="button_submit" value="finish">Submit survey</button>
</div>
</form>
<!-- Modal used to display error message, i.c.o. ajax error -->
<div class="modal fade" id="AJAXErrorModal" role="dialog" aria-labelledby="AJAXErrorModal" aria-hidden="true" >
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&amp;times;</button>
<h4 class="modal-title">A problem has occured</h4>
</div>
<div class="modal-body"><p>Something went wrong while contacting survey server. <strong class="text-danger">Your answers have probably not been recorded.</strong> Try refreshing.</p></div>
<div class="modal-footer"><button type="button" class="btn btn-primary" data-dismiss="modal">Close</button></div>
</div>
</div>
</div>
</xpath>
</template>
</odoo>

45
survey_attachment/templates/survey_print.xml

@ -1,49 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="survey.survey_print" name="Survey">
<t t-call="survey.layout">
<div class="wrap">
<div class="container">
<t t-call="survey.back" />
<div class="row">
<div class='jumbotron mt32' style="width:100%;">
<h1><span t-field='survey.title'/></h1>
<t t-if="survey.description"><div t-field='survey.description' class="oe_no_empty"/></t>
</div>
<div role="form" class="js_surveyform" t-att-name="'%s' % (survey.id)" t-att-data-prefill="'/survey/prefill/%s/%s' % (slug(survey), token)" style="width: -moz-available;">
<t t-foreach="survey.page_ids" t-as="page">
<div class="page-header">
<h1 t-field='page.title' />
<t t-if="page.description"><div t-field='page.description' class="oe_no_empty"/></t>
</div>
<t t-foreach='page.question_ids' t-as='question'>
<t t-set="prefix" t-value="'%s_%s_%s' % (survey.id, page.id, question.id)" />
<div class="js_question-wrapper" t-att-id="prefix">
<h2>
<span t-field='question.question' />
<span t-if="question.constr_mandatory" class="text-danger">*</span>
<span t-if="quizz_correction" class="badge" t-att-data-score-question="question.id"></span>
</h2>
<t t-if="question.description"><div class="text-muted oe_no_empty" t-field='question.description'/></t>
<t t-if="question.type == 'free_text'"><t t-call="survey.free_text"/></t>
<t t-if="question.type == 'textbox'"><t t-call="survey.textbox"/></t>
<t t-if="question.type == 'numerical_box'"><t t-call="survey.numerical_box"/></t>
<t t-if="question.type == 'date'"><t t-call="survey.date"/></t>
<t t-if="question.type == 'simple_choice'"><t t-call="survey.simple_choice"/></t>
<t t-if="question.type == 'multiple_choice'"><t t-call="survey.multiple_choice"/></t>
<t t-if="question.type == 'matrix'"><t t-call="survey.matrix"/></t>
<template id="survey_print" name="Survey Attachment print" inherit_id="survey.survey_print">
<xpath expr="//div[hasclass('js_question-wrapper')]/t[last()]" position='after'>
<t t-if="question.type == 'upload_file'"><t t-call="survey_attachment.upload_file"/></t>
<div class="js_errzone alert alert-danger" style="display:none;"></div>
</div>
</t>
<hr/>
</t>
</div>
</div>
</div>
</div>
</t>
</xpath>
</template>
</odoo>

15
survey_attachment/templates/upload_file.xml

@ -3,21 +3,20 @@
<template id="upload_file" name="Upload a file">
<div class="input-file-container">
<t t-if="user_input_line_upload_file">
<t t-foreach="user_input_line_upload_file" t-as="upload_file" t-if="upload_file.question_id.id == question.id">
<t t-if="upload_file.file_type == 'pdf'">
<a width="100px" height="100px" t-att-href="'data:application/pdf;base64,%s' % to_text(upload_file.file)" target="_blank">Download</a>
</t>
<t t-if="upload_file.file_type == 'image'">
<img width="100px" style="height: 100px;" class="img-thumbnail" t-att-src="'data:image/*;base64,%s' % to_text(upload_file.file)"/>
<t t-set="user_input_line" t-value="survey.user_input_ids.filtered(lambda sui: sui.token == token).user_input_line_ids.filtered(lambda suil: suil.question_id == question)"/>
<t t-if="user_input_line">
<t t-if="user_input_line.file_type == 'pdf'">
<a width="100px" height="100px" t-att-href="'data:application/pdf;base64,%s' % to_text(user_input_line.file)" target="_blank">Download <t t-esc="user_input_line.filename"/></a>
</t>
<t t-elif="user_input_line.file_type == 'image'">
<img width="100px" style="height: 100px;" class="img-thumbnail" t-att-src="'data:image/*;base64,%s' % to_text(user_input_line.file)"/>
</t>
</t>
<t t-else="">
<div class="file-field">
<input class="input-file" id="my-file" type="file" accept="image/*,application/pdf" t-att-name="prefix"/>
</div>
<br/>
<!-- <br/> -->
</t>
</div>
<script>

Loading…
Cancel
Save