Example #1
0
    def test_image(self):
        column = self.get_column('binary')
        converter = self.registry('ir.qweb.field.image')

        with open(os.path.join(directory, 'test_vectors', 'image'), 'rb') as f:
            content = f.read()

        encoded_content = content.encode('base64')
        value = e(
            converter.value_to_html(self.cr, self.uid, encoded_content,
                                    column))
        self.assertEqual(
            value, '<img src="data:image/jpeg;base64,%s">' % (encoded_content))

        with open(os.path.join(directory, 'test_vectors', 'pdf'), 'rb') as f:
            content = f.read()

        with self.assertRaises(ValueError):
            e(
                converter.value_to_html(self.cr, self.uid, 'binary',
                                        content.encode('base64'), column))

        with open(os.path.join(directory, 'test_vectors', 'pptx'), 'rb') as f:
            content = f.read()

        with self.assertRaises(ValueError):
            e(
                converter.value_to_html(self.cr, self.uid, 'binary',
                                        content.encode('base64'), column))
Example #2
0
    def test_image(self):
        column = self.get_column('binary')
        converter = self.registry('ir.qweb.field.image')

        with open(os.path.join(directory, 'test_vectors', 'image'), 'rb') as f:
            content = f.read()

        encoded_content = content.encode('base64')
        value = e(converter.value_to_html(
            self.cr, self.uid, encoded_content, column))
        self.assertEqual(
            value, '<img src="data:image/jpeg;base64,%s">' % (
                encoded_content
            ))

        with open(os.path.join(directory, 'test_vectors', 'pdf'), 'rb') as f:
            content = f.read()

        with self.assertRaises(ValueError):
            e(converter.value_to_html(
                self.cr, self.uid, 'binary', content.encode('base64'), column))

        with open(os.path.join(directory, 'test_vectors', 'pptx'), 'rb') as f:
            content = f.read()

        with self.assertRaises(ValueError):
            e(converter.value_to_html(
                self.cr, self.uid, 'binary', content.encode('base64'), column))
Example #3
0
        def converter(record):
            column = self.get_column('many2one')
            model = self.registry('ir.qweb.field.many2one')

            return e(
                model.record_to_html(self.cr, self.uid, 'many2one', record,
                                     column))
Example #4
0
    def get_converter(self, name, type=None):
        column = self.get_column(name)

        for postfix in type, column._type, '':
            fs = ['ir', 'qweb', 'field']
            if postfix is None: continue
            if postfix: fs.append(postfix)

            try:
                model = self.registry('.'.join(fs))
                break
            except KeyError: pass

        return lambda value, options=None, context=None: e(model.value_to_html(
            self.cr, self.uid, value, column, options=options, context=context))
Example #5
0
    def get_converter(self, name, type=None):
        column = self.get_column(name)

        for postfix in type, column._type, '':
            fs = ['ir', 'qweb', 'field']
            if postfix is None: continue
            if postfix: fs.append(postfix)

            try:
                model = self.registry('.'.join(fs))
                break
            except KeyError: pass

        return lambda value, options=None, context=None: e(model.value_to_html(
            self.cr, self.uid, value, column, options=options, context=context))
Example #6
0
        def converter(record):
            column = self.get_column('many2one')
            model = self.registry('ir.qweb.field.many2one')

            return e(model.record_to_html(
                self.cr, self.uid, 'many2one', record, column))