Odoo modules related to surveys
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.3 KiB

  1. # -*- coding: utf-8 -*-
  2. from odoo import models, fields, api, _
  3. from werkzeug.datastructures import FileStorage
  4. TYPES = [
  5. ('free_text', _('Multiple Lines Text Box')),
  6. ('textbox', _('Single Line Text Box')),
  7. ('numerical_box', _('Numerical Value')),
  8. ('date', _('Date')),
  9. ('upload_file', _('Attachment')),
  10. ('simple_choice', _('Multiple choice: only one answer')),
  11. ('multiple_choice', _('Multiple choice: multiple answers allowed')),
  12. ('matrix', _('Matrix')),
  13. ]
  14. class SurveyQuestion(models.Model):
  15. _inherit = 'survey.question'
  16. # question_attachment = fields.Binary(string="Joined attachment")
  17. type = fields.Selection(selection=TYPES)
  18. @api.multi
  19. def validate_upload_file(self, post, answer_tag):
  20. self.ensure_one()
  21. errors = {}
  22. # Empty answer to mandatory question
  23. if self.constr_mandatory and not isinstance(post[answer_tag], FileStorage):
  24. errors.update({answer_tag: self.constr_error_msg})
  25. # Bad file type
  26. if isinstance(post[answer_tag], FileStorage) and post[answer_tag].content_type != 'application/pdf' and 'image/' not in post[answer_tag].content_type:
  27. errors.update({answer_tag: _("The file you joined is not an image nor a PDF file.")})
  28. return errors