|
@ -1,5 +1,6 @@ |
|
|
# -*- coding: utf-8 -*- |
|
|
# -*- coding: utf-8 -*- |
|
|
from odoo import models, fields, _ |
|
|
|
|
|
|
|
|
from odoo import models, fields, api, _ |
|
|
|
|
|
from werkzeug.datastructures import FileStorage |
|
|
|
|
|
|
|
|
TYPES = [ |
|
|
TYPES = [ |
|
|
('free_text', _('Multiple Lines Text Box')), |
|
|
('free_text', _('Multiple Lines Text Box')), |
|
@ -18,3 +19,15 @@ class SurveyQuestion(models.Model): |
|
|
|
|
|
|
|
|
# question_attachment = fields.Binary(string="Joined attachment") |
|
|
# question_attachment = fields.Binary(string="Joined attachment") |
|
|
type = fields.Selection(selection=TYPES) |
|
|
type = fields.Selection(selection=TYPES) |
|
|
|
|
|
|
|
|
|
|
|
@api.multi |
|
|
|
|
|
def validate_upload_file(self, post, answer_tag): |
|
|
|
|
|
self.ensure_one() |
|
|
|
|
|
errors = {} |
|
|
|
|
|
# Empty answer to mandatory question |
|
|
|
|
|
if self.constr_mandatory and not isinstance(post[answer_tag], FileStorage): |
|
|
|
|
|
errors.update({answer_tag: self.constr_error_msg}) |
|
|
|
|
|
# Bad file type |
|
|
|
|
|
if isinstance(post[answer_tag], FileStorage) and post[answer_tag].content_type != 'application/pdf' and 'image/' not in post[answer_tag].content_type: |
|
|
|
|
|
errors.update({answer_tag: _("The file you joined is not an image nor a PDF file.")}) |
|
|
|
|
|
return errors |