def content_image(self, id=None, max_width=0, max_height=0, **kw): if max_width: kw['width'] = max_width if max_height: kw['height'] = max_height if id: id, _, unique = id.partition('_') kw['id'] = int(id) if unique: kw['unique'] = unique return Binary().content_image(**kw)
def survey_get_background(self, survey_token, answer_token): access_data = self._get_access_data(survey_token, answer_token, ensure_token=True) if access_data['validity_code'] is not True: return werkzeug.exceptions.Forbidden() survey_sudo, answer_sudo = access_data['survey_sudo'], access_data[ 'answer_sudo'] status, headers, image_base64 = request.env['ir.http'].sudo( ).binary_content(model='survey.survey', id=survey_sudo.id, field='background_image', default_mimetype='image/png') return Binary._content_image_get_response(status, headers, image_base64)
def survey_get_question_image(self, survey_token, answer_token, question_id, suggested_answer_id): access_data = self._get_access_data(survey_token, answer_token, ensure_token=True) if access_data['validity_code'] is not True: return werkzeug.exceptions.Forbidden() survey_sudo, answer_sudo = access_data['survey_sudo'], access_data[ 'answer_sudo'] if not survey_sudo.question_ids.filtered(lambda q: q.id == question_id)\ .suggested_answer_ids.filtered(lambda a: a.id == suggested_answer_id): return werkzeug.exceptions.NotFound() status, headers, image_base64 = request.env['ir.http'].sudo( ).binary_content(model='survey.question.answer', id=suggested_answer_id, field='value_image', default_mimetype='image/png') return Binary._content_image_get_response(status, headers, image_base64)
def resize_to_48(b64source): if not b64source: b64source = base64.b64encode(Binary.placeholder()) return image_process(b64source, size=(48, 48))