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))
def test_image(self): field = self.get_field('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, field)) 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'), field)) 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'), field))
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))
def test_selection(self): converter = self.get_converter('selection') value = converter(4) self.assertEqual(value, e(u"réponse <D>")) converter = self.get_converter('selection_str') value = converter('C') self.assertEqual(value, u"Qu'est-ce qu'il fout ce maudit pancake, tabernacle ?")
def test_selection(self): converter = self.get_converter('selection') value = converter(4) self.assertEqual(value, e(u"réponse <D>")) converter = self.get_converter('selection_str') value = converter('C') self.assertEqual( value, u"Qu'est-ce qu'il fout ce maudit pancake, tabernacle ?")
def test_selection(self): [record] = self.Model.browse( self.cr, self.uid, [self.Model.create(self.cr, self.uid, {"selection": 4, "selection_str": "C"})] ) converter = self.registry("ir.qweb.field.selection") field_name = "selection" value = converter.record_to_html(self.cr, self.uid, record, field_name, {}) self.assertEqual(value, e(u"réponse <D>")) field_name = "selection_str" value = converter.record_to_html(self.cr, self.uid, record, field_name, {}) self.assertEqual(value, u"Qu'est-ce qu'il fout ce maudit pancake, tabernacle ?")
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))
def get_converter(self, name, type=None): field = self.get_field(name) for postfix in type, field.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, field, options=options, context=context))
def test_selection(self): [record] = self.Model.browse(self.cr, self.uid, [ self.Model.create(self.cr, self.uid, { 'selection': 4, 'selection_str': 'C', }) ]) converter = self.registry('ir.qweb.field.selection') field_name = 'selection' value = converter.record_to_html(self.cr, self.uid, record, field_name, {}) self.assertEqual(value, e(u"réponse <D>")) field_name = 'selection_str' value = converter.record_to_html(self.cr, self.uid, record, field_name, {}) self.assertEqual( value, u"Qu'est-ce qu'il fout ce maudit pancake, tabernacle ?")
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))
def converter(record): model = self.registry('ir.qweb.field.many2one') return e( model.record_to_html(self.cr, self.uid, 'many2one', record))
def converter(record): model = self.registry('ir.qweb.field.many2one') return e(model.record_to_html(self.cr, self.uid, 'many2one', record))