Browse Source

[ADD-IMP] survey_attachment_module (from Fogits) + [I18N]

12.0
Rémi FRANÇOIS 5 years ago
parent
commit
dd247707db
  1. 2
      survey_attachment/__init__.py
  2. 35
      survey_attachment/__manifest__.py
  3. 2
      survey_attachment/controllers/__init__.py
  4. 40
      survey_attachment/controllers/main.py
  5. 139
      survey_attachment/i18n/fr.po
  6. 139
      survey_attachment/i18n/survey_attachment.pot
  7. 2
      survey_attachment/models/__init__.py
  8. 20
      survey_attachment/models/survey_question.py
  9. 58
      survey_attachment/models/survey_user_input_line.py
  10. BIN
      survey_attachment/static/description/icon.png
  11. BIN
      survey_attachment/static/description/image_2.png
  12. BIN
      survey_attachment/static/description/imge_1.png
  13. 21
      survey_attachment/static/description/index.html
  14. BIN
      survey_attachment/static/description/survey.jpg
  15. 57
      survey_attachment/templates/page.xml
  16. 49
      survey_attachment/templates/survey_print.xml
  17. 44
      survey_attachment/templates/upload_file.xml
  18. 17
      survey_attachment/views/survey_user_input_line.xml

2
survey_attachment/__init__.py

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

35
survey_attachment/__manifest__.py

@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': 'Survey Attachment',
'version': '1.0.0',
'summary': """
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/',
'license': 'AGPL-3',
'category': 'Marketing',
'depends': [
'survey',
],
'data': [
'templates/upload_file.xml',
'templates/page.xml',
'templates/survey_print.xml',
'views/survey_user_input_line.xml',
],
'demo': [],
'auto_install': False,
'external_dependencies': [],
'application': False,
'css': [],
'images': ['static/description/survey.jpg'],
'js': [],
'installable': True,
'maintainer': 'Fogits Solutions, Sudokeys',
'pre_init_hook': '',
'post_init_hook': '',
'uninstall_hook': '',
}

2
survey_attachment/controllers/__init__.py

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

40
survey_attachment/controllers/main.py

@ -0,0 +1,40 @@
# -*- 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})

139
survey_attachment/i18n/fr.po

@ -0,0 +1,139 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * survey_attachment
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-03-31 13:31+0000\n"
"PO-Revision-Date: 2020-03-31 13:31+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: survey_attachment
#: model:ir.model.fields,field_description:survey_attachment.field_survey_user_input_line__answer_type
msgid "Answer Type"
msgstr "Type de réponse"
#. module: survey_attachment
#: code:addons/survey_attachment/models/survey_question.py:9
#: selection:survey.question,type:0
#: selection:survey.user_input_line,answer_type:0
#, python-format
msgid "Attachment"
msgstr " jointe"
#. module: survey_attachment
#: code:addons/survey_attachment/models/survey_question.py:8
#: selection:survey.question,type:0
#: selection:survey.user_input_line,answer_type:0
#, python-format
msgid "Date"
msgstr "Date"
#. module: survey_attachment
#: model_terms:ir.ui.view,arch_db:survey_attachment.upload_file
msgid "Download"
msgstr "Télécharger"
#. module: survey_attachment
#: model:ir.model.fields,field_description:survey_attachment.field_survey_user_input_line__file_type
msgid "File type"
msgstr "Type de fichier"
#. module: survey_attachment
#: code:addons/survey_attachment/models/survey_user_input_line.py:7
#: selection:survey.user_input_line,file_type:0
#, python-format
msgid "Image"
msgstr "Image"
#. module: survey_attachment
#: model:ir.model.fields,field_description:survey_attachment.field_survey_question__question_attachment
msgid "Joined attachment"
msgstr "Pièce jointe"
#. module: survey_attachment
#: code:addons/survey_attachment/models/survey_question.py:12
#: selection:survey.question,type:0
#: selection:survey.user_input_line,answer_type:0
#, python-format
msgid "Matrix"
msgstr "Matrice"
#. module: survey_attachment
#: code:addons/survey_attachment/models/survey_question.py:5
#: selection:survey.question,type:0
#: selection:survey.user_input_line,answer_type:0
#, python-format
msgid "Multiple Lines Text Box"
msgstr "Plusieurs lignes de champ de texte"
#. module: survey_attachment
#: code:addons/survey_attachment/models/survey_question.py:11
#: selection:survey.question,type:0
#: selection:survey.user_input_line,answer_type:0
#, python-format
msgid "Multiple choice: multiple answers allowed"
msgstr "Choix multiples : réponses multiples"
#. module: survey_attachment
#: code:addons/survey_attachment/models/survey_question.py:10
#: selection:survey.question,type:0
#: selection:survey.user_input_line,answer_type:0
#, python-format
msgid "Multiple choice: only one answer"
msgstr "Choix multiples : une seule réponse possible"
#. module: survey_attachment
#: code:addons/survey_attachment/models/survey_question.py:7
#: selection:survey.question,type:0
#: selection:survey.user_input_line,answer_type:0
#, python-format
msgid "Numerical Value"
msgstr "Valeur numérique"
#. module: survey_attachment
#: code:addons/survey_attachment/models/survey_user_input_line.py:8
#: selection:survey.user_input_line,file_type:0
#, python-format
msgid "PDF file"
msgstr "Fichier PDF"
#. module: survey_attachment
#: code:addons/survey_attachment/models/survey_question.py:6
#: selection:survey.question,type:0
#: selection:survey.user_input_line,answer_type:0
#, python-format
msgid "Single Line Text Box"
msgstr "Ligne de texte unique"
#. module: survey_attachment
#: model:ir.model,name:survey_attachment.model_survey_question
msgid "Survey Question"
msgstr "Question du sondage"
#. module: survey_attachment
#: model:ir.model,name:survey_attachment.model_survey_user_input_line
msgid "Survey User Input Line"
msgstr "Ligne de saisie pour l'utilisateur du sondage"
#. module: survey_attachment
#: model:ir.model.fields,field_description:survey_attachment.field_survey_question__type
msgid "Type of Question"
msgstr "Type de question"
#. module: survey_attachment
#: model:ir.model.fields,field_description:survey_attachment.field_survey_user_input_line__file
msgid "Uploaded file"
msgstr "Fichier joint"
#. module: survey_attachment
#: model:ir.model.fields,field_description:survey_attachment.field_survey_user_input_line__filename
msgid "Uploaded file name"
msgstr "Nom du fichier joint"

139
survey_attachment/i18n/survey_attachment.pot

@ -0,0 +1,139 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * survey_attachment
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-03-31 13:32+0000\n"
"PO-Revision-Date: 2020-03-31 13:32+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: survey_attachment
#: model:ir.model.fields,field_description:survey_attachment.field_survey_user_input_line__answer_type
msgid "Answer Type"
msgstr ""
#. module: survey_attachment
#: code:addons/survey_attachment/models/survey_question.py:9
#: selection:survey.question,type:0
#: selection:survey.user_input_line,answer_type:0
#, python-format
msgid "Attachment"
msgstr ""
#. module: survey_attachment
#: code:addons/survey_attachment/models/survey_question.py:8
#: selection:survey.question,type:0
#: selection:survey.user_input_line,answer_type:0
#, python-format
msgid "Date"
msgstr ""
#. module: survey_attachment
#: model_terms:ir.ui.view,arch_db:survey_attachment.upload_file
msgid "Download"
msgstr ""
#. module: survey_attachment
#: model:ir.model.fields,field_description:survey_attachment.field_survey_user_input_line__file_type
msgid "File type"
msgstr ""
#. module: survey_attachment
#: code:addons/survey_attachment/models/survey_user_input_line.py:7
#: selection:survey.user_input_line,file_type:0
#, python-format
msgid "Image"
msgstr ""
#. module: survey_attachment
#: model:ir.model.fields,field_description:survey_attachment.field_survey_question__question_attachment
msgid "Joined attachment"
msgstr ""
#. module: survey_attachment
#: code:addons/survey_attachment/models/survey_question.py:12
#: selection:survey.question,type:0
#: selection:survey.user_input_line,answer_type:0
#, python-format
msgid "Matrix"
msgstr ""
#. module: survey_attachment
#: code:addons/survey_attachment/models/survey_question.py:5
#: selection:survey.question,type:0
#: selection:survey.user_input_line,answer_type:0
#, python-format
msgid "Multiple Lines Text Box"
msgstr ""
#. module: survey_attachment
#: code:addons/survey_attachment/models/survey_question.py:11
#: selection:survey.question,type:0
#: selection:survey.user_input_line,answer_type:0
#, python-format
msgid "Multiple choice: multiple answers allowed"
msgstr ""
#. module: survey_attachment
#: code:addons/survey_attachment/models/survey_question.py:10
#: selection:survey.question,type:0
#: selection:survey.user_input_line,answer_type:0
#, python-format
msgid "Multiple choice: only one answer"
msgstr ""
#. module: survey_attachment
#: code:addons/survey_attachment/models/survey_question.py:7
#: selection:survey.question,type:0
#: selection:survey.user_input_line,answer_type:0
#, python-format
msgid "Numerical Value"
msgstr ""
#. module: survey_attachment
#: code:addons/survey_attachment/models/survey_user_input_line.py:8
#: selection:survey.user_input_line,file_type:0
#, python-format
msgid "PDF file"
msgstr ""
#. module: survey_attachment
#: code:addons/survey_attachment/models/survey_question.py:6
#: selection:survey.question,type:0
#: selection:survey.user_input_line,answer_type:0
#, python-format
msgid "Single Line Text Box"
msgstr ""
#. module: survey_attachment
#: model:ir.model,name:survey_attachment.model_survey_question
msgid "Survey Question"
msgstr ""
#. module: survey_attachment
#: model:ir.model,name:survey_attachment.model_survey_user_input_line
msgid "Survey User Input Line"
msgstr ""
#. module: survey_attachment
#: model:ir.model.fields,field_description:survey_attachment.field_survey_question__type
msgid "Type of Question"
msgstr ""
#. module: survey_attachment
#: model:ir.model.fields,field_description:survey_attachment.field_survey_user_input_line__file
msgid "Uploaded file"
msgstr ""
#. module: survey_attachment
#: model:ir.model.fields,field_description:survey_attachment.field_survey_user_input_line__filename
msgid "Uploaded file name"
msgstr ""

2
survey_attachment/models/__init__.py

@ -0,0 +1,2 @@
from . import survey_question
from . import survey_user_input_line

20
survey_attachment/models/survey_question.py

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from odoo import models, fields, _
TYPES = [
('free_text', _('Multiple Lines Text Box')),
('textbox', _('Single Line Text Box')),
('numerical_box', _('Numerical Value')),
('date', _('Date')),
('upload_file', _('Attachment')),
('simple_choice', _('Multiple choice: only one answer')),
('multiple_choice', _('Multiple choice: multiple answers allowed')),
('matrix', _('Matrix')),
]
class SurveyQuestion(models.Model):
_inherit = 'survey.question'
question_attachment = fields.Binary(string="Joined attachment")
type = fields.Selection(selection=TYPES)

58
survey_attachment/models/survey_user_input_line.py

@ -0,0 +1,58 @@
# -*- coding: utf-8 -*-
import base64
from odoo import models, fields, api, _
from .survey_question import TYPES
FILE_TYPES = [
('image', _('Image')),
('pdf', _('PDF file')),
]
class SurveyUserInputLine(models.Model):
_inherit = 'survey.user_input_line'
answer_type = fields.Selection(selection=TYPES)
file = fields.Binary(string='Uploaded file')
filename = fields.Char(string='Uploaded file name')
file_type = fields.Selection(selection=FILE_TYPES, string="File type")
@api.model
def save_line_upload_file(self, user_input_id, question, post, answer_tag):
vals = {
'user_input_id': user_input_id,
'question_id': question.id,
'survey_id': question.survey_id.id,
'skipped': False
}
if question.constr_mandatory:
file = base64.encodebytes(post[answer_tag].read())
else:
file = base64.encodebytes(post[answer_tag].read()) if post[answer_tag] else None
if answer_tag in post:
vals.update({
'answer_type': 'upload_file',
'file': file,
'filename': post[answer_tag].filename,
})
if post[answer_tag].content_type == 'application/pdf':
vals.update({'file_type': 'pdf'})
if 'image/' in post[answer_tag].content_type:
vals.update({'file_type': 'image'})
else:
vals.update({
'answer_type': None,
'file': False,
'filename': False,
'skipped': True,
})
old_uil = self.search([
('user_input_id', '=', user_input_id),
('survey_id', '=', question.survey_id.id),
('question_id', '=', question.id)
])
if old_uil:
old_uil.write(vals)
else:
old_uil.create(vals)
return True

BIN
survey_attachment/static/description/icon.png

After

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

BIN
survey_attachment/static/description/image_2.png

After

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

BIN
survey_attachment/static/description/imge_1.png

After

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

21
survey_attachment/static/description/index.html

@ -0,0 +1,21 @@
<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

After

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

57
survey_attachment/templates/page.xml

@ -0,0 +1,57 @@
<?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>
<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>
</template>
</odoo>

49
survey_attachment/templates/survey_print.xml

@ -0,0 +1,49 @@
<?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>
<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>
</template>
</odoo>

44
survey_attachment/templates/upload_file.xml

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<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>
</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/>
</t>
</div>
<script>
$(document).ready(function(){
$(".img-thumbnail").click(function(){
if ( $(this).height() == 240) {
$(this).animate({
opacity: '0.8',
height: '100px',
width: '100px',
}, "slow");
} else {
$(this).animate({
opacity: '0.8',
height: '250px',
width: '250px',
}, "slow");
}
});
});
</script>
</template>
</odoo>

17
survey_attachment/views/survey_user_input_line.xml

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="survey_user_input_line_form" model="ir.ui.view">
<field name="name">survey_attachment survey.user_input_line form</field>
<field name="model">survey.user_input_line</field>
<field name="inherit_id" ref="survey.survey_user_input_line_form"/>
<field name="priority">20</field>
<field name="arch" type="xml">
<xpath expr="//field[@name='answer_type']" position="after">
<field name="file" filename="filename" attrs="{'invisible': [('answer_type','!=','upload_file')]}"/>
<field name="filename" invisible="1"/>
</xpath>
</field>
</record>
</odoo>
Loading…
Cancel
Save