本文整理汇总了Python中spreadsheetresponsemixin.SpreadsheetResponseMixin.get_fields方法的典型用法代码示例。如果您正苦于以下问题:Python SpreadsheetResponseMixin.get_fields方法的具体用法?Python SpreadsheetResponseMixin.get_fields怎么用?Python SpreadsheetResponseMixin.get_fields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spreadsheetresponsemixin.SpreadsheetResponseMixin
的用法示例。
在下文中一共展示了SpreadsheetResponseMixin.get_fields方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GenerateHeadersTests
# 需要导入模块: from spreadsheetresponsemixin import SpreadsheetResponseMixin [as 别名]
# 或者: from spreadsheetresponsemixin.SpreadsheetResponseMixin import get_fields [as 别名]
class GenerateHeadersTests(TestCase):
def setUp(self):
MockModelFactory()
self.mixin = SpreadsheetResponseMixin()
self.data = self.mixin.generate_data(MockModel.objects.all())
def test_get_fields_defined_on_view(self):
fields = ('title', 'summary')
self.mixin.fields = fields
assert fields == self.mixin.get_fields()
def test_get_fields_from_kwargs(self):
fields = ('title', 'summary')
assert fields == self.mixin.get_fields(fields=fields)
def test_get_fields_from_model(self):
model = MockModelFactory()
self.mixin.model = model
assert ['id', 'title'] == self.mixin.get_fields()
def test_get_fields_from_queryset(self):
self.mixin.queryset = MockModel.objects.all()
assert ['id', 'title'] == self.mixin.get_fields()
def test_generate_headers_gets_headers_from_model_name(self):
assert self.mixin.generate_headers(self.data) == (u'Id', u'Title')
def test_generate_headers_only_returns_fields_if_fields_is_passed(self):
fields = ('title',)
assert self.mixin.generate_headers(self.data,
fields=fields) == (u'Title', )
示例2: GetFieldsTests
# 需要导入模块: from spreadsheetresponsemixin import SpreadsheetResponseMixin [as 别名]
# 或者: from spreadsheetresponsemixin.SpreadsheetResponseMixin import get_fields [as 别名]
class GetFieldsTests(TestCase):
def setUp(self):
self.mixin = SpreadsheetResponseMixin()
def test_if_fields_defined_on_view(self):
fields = ('title', 'summary')
self.mixin.fields = fields
assert self.mixin.get_fields() == fields
def test_get_fields_from_kwargs(self):
fields = ('title', 'summary')
assert self.mixin.get_fields(fields=fields) == fields
def test_get_fields_from_model(self):
self.mixin.model = MockModel
assert self.mixin.get_fields() == ['id', 'title']
def test_get_fields_from_queryset(self):
self.mixin.queryset = MockModel.objects.all()
assert self.mixin.get_fields() == ['id', 'title']
示例3: GetFieldsTests
# 需要导入模块: from spreadsheetresponsemixin import SpreadsheetResponseMixin [as 别名]
# 或者: from spreadsheetresponsemixin.SpreadsheetResponseMixin import get_fields [as 别名]
class GetFieldsTests(TestCase):
def setUp(self):
self.mixin = SpreadsheetResponseMixin()
def test_if_fields_defined_on_view(self):
fields = ('title', 'summary')
self.mixin.fields = fields
assert self.mixin.get_fields() == fields
def test_get_fields_from_kwargs(self):
fields = ('title', 'summary')
assert self.mixin.get_fields(fields=fields) == fields
def test_get_fields_from_queryset(self):
self.mixin.queryset = MockModel.objects.all()
assert self.mixin.get_fields() == ['id', 'title', 'author']
def test_get_fields_from_values_list_queryset(self):
self.mixin.queryset = MockModel.objects.all().values_list()
assert self.mixin.get_fields() == ['id', 'title', 'author_id']
def test_get_fields_from_values_list_queryset_with_specific_fields(self):
self.mixin.queryset = MockModel.objects.all().values_list('author', 'title')
assert self.mixin.get_fields() == ['author', 'title']
示例4: GenerateHeadersTests
# 需要导入模块: from spreadsheetresponsemixin import SpreadsheetResponseMixin [as 别名]
# 或者: from spreadsheetresponsemixin.SpreadsheetResponseMixin import get_fields [as 别名]
class GenerateHeadersTests(TestCase):
def setUp(self):
MockModelFactory()
self.mixin = SpreadsheetResponseMixin()
self.mixin.queryset = MockModel.objects.all()
self.data = self.mixin.generate_data()
def test_generate_headers_gets_headers_from_model_name(self):
fields = self.mixin.get_fields(model=MockModel)
assert self.mixin.generate_headers(MockModel, fields) == (u'Id', u'Title', u'Author')
def test_generate_headers_keeps_fields_order(self):
fields = ('title', 'id')
headers = self.mixin.generate_headers(MockModel, fields=fields)
assert headers == (u'Title', u'Id')
def test_generate_headers_only_returns_fields_if_fields_is_passed(self):
fields = ('title',)
assert self.mixin.generate_headers(MockModel,
fields=fields) == (u'Title', )
def test_generate_headers_follows_foreign_keys(self):
fields = ('title', 'author__name')
headers = self.mixin.generate_headers(MockModel, fields)
assert headers == (u'Title', u'Author Name')
def test_generate_headers_with_calculated_fields(self):
fields = ('title', 'author__name', 'calculate_this')
self.mixin.calculate_this = lambda values: 'whee %d' % values[0]
headers = self.mixin.generate_headers(MockModel, fields)
assert headers == (u'Title', u'Author Name', u'Calculate This')
def test_generate_headers_with_calculated_fields_with_verbose_names(self):
fields = ('title', 'author__name', 'calculate_this')
self.mixin.calculate_this = lambda values: 'whee %d' % values[0]
self.mixin.calculate_this.verbose_name = 'Whee!'
headers = self.mixin.generate_headers(MockModel, fields)
assert headers == (u'Title', u'Author Name', u'Whee!')