当前位置: 首页>>代码示例>>Python>>正文


Python SpreadsheetResponseMixin.get_fields方法代码示例

本文整理汇总了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', )
开发者ID:tommorris,项目名称:django-spreadsheetresponsemixin,代码行数:34,代码来源:test_views.py

示例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']
开发者ID:ashwoods,项目名称:django-spreadsheetresponsemixin,代码行数:22,代码来源:test_views.py

示例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']
开发者ID:jangeador,项目名称:django-spreadsheetresponsemixin,代码行数:26,代码来源:test_views.py

示例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!')
开发者ID:aptivate,项目名称:django-spreadsheetresponsemixin,代码行数:40,代码来源:test_views.py


注:本文中的spreadsheetresponsemixin.SpreadsheetResponseMixin.get_fields方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。