本文整理汇总了Python中avocado.models.DataConcept.formatter_name方法的典型用法代码示例。如果您正苦于以下问题:Python DataConcept.formatter_name方法的具体用法?Python DataConcept.formatter_name怎么用?Python DataConcept.formatter_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类avocado.models.DataConcept
的用法示例。
在下文中一共展示了DataConcept.formatter_name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_format
# 需要导入模块: from avocado.models import DataConcept [as 别名]
# 或者: from avocado.models.DataConcept import formatter_name [as 别名]
def test_format(self):
name_field = DataField.objects.get_by_natural_key('models', 'title', 'name')
salary_field = DataField.objects.get_by_natural_key('models', 'title', 'salary')
boss_field = DataField.objects.get_by_natural_key('models', 'title', 'boss')
concept = DataConcept(name='Title')
concept.save()
DataConceptField(concept=concept, field=name_field, order=1).save()
DataConceptField(concept=concept, field=salary_field, order=2).save()
DataConceptField(concept=concept, field=boss_field, order=3).save()
values = ['CEO', 100000, True]
self.assertEqual(concept.format(values),
OrderedDict([
(u'name', u'CEO'),
(u'salary', 100000),
(u'boss', True)
]))
self.assertEqual(concept._formatter_cache[0], None)
from avocado.formatters import Formatter, registry as formatters
class HtmlFormatter(Formatter):
def to_html(self, values, **context):
fvalues = self(values, preferred_formats=['string'])
return OrderedDict({
'profile': '<span>' + '</span><span>'.join(fvalues.values()) + '</span>'
})
to_html.process_multiple = True
formatters.register(HtmlFormatter, 'HTML')
concept.formatter_name = 'HTML'
self.assertEqual(concept.format(values, preferred_formats=['html']),
OrderedDict([
('profile', u'<span>CEO</span><span>100000</span><span>True</span>')
]))