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


Python DataView.apply方法代码示例

本文整理汇总了Python中avocado.models.DataView.apply方法的典型用法代码示例。如果您正苦于以下问题:Python DataView.apply方法的具体用法?Python DataView.apply怎么用?Python DataView.apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在avocado.models.DataView的用法示例。


在下文中一共展示了DataView.apply方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_sort_related

# 需要导入模块: from avocado.models import DataView [as 别名]
# 或者: from avocado.models.DataView import apply [as 别名]
    def test_sort_related(self):
        "Sorts on a reverse foreign key property."
        view = DataView(
            json=[
                {"concept": self.first_name.pk},
                {"concept": self.last_name.pk},
                {"concept": self.project_name.pk, "sort": "asc", "visible": False},
            ]
        )

        queryset = view.apply()

        exporter = export.BaseExporter(view)
        exporter.params.insert(0, (RawFormatter(keys=["pk"]), 1))
        exporter.row_length += 1

        self.assertEqual(
            list(exporter.write(queryset.raw())),
            [
                (3, u"Erick", u"Smith"),
                (4, u"Aaron", u"Harris"),
                (5, u"Zac", u"Cook"),
                (6, u"Mel", u"Brooks"),
                (1, u"Eric", u"Smith"),
                (2, u"Erin", u"Jones"),
            ],
        )
开发者ID:hassanNS,项目名称:avocado,代码行数:29,代码来源:tests.py

示例2: setUp

# 需要导入模块: from avocado.models import DataView [as 别名]
# 或者: from avocado.models.DataView import apply [as 别名]
    def setUp(self):
        management.call_command("avocado", "init", "tests", quiet=True)
        salary_concept = DataField.objects.get(field_name="salary").concepts.all()[0]

        view = DataView(json={"ordering": [[salary_concept.pk, "desc"]]})
        self.query = view.apply(tree=models.Employee).raw()
        # Ick..
        self.exporter = export.BaseExporter(view)
        self.exporter.params.insert(0, (RawFormatter(keys=["pk"]), 1))
        self.exporter.row_length += 1
开发者ID:hassanNS,项目名称:avocado,代码行数:12,代码来源:tests.py

示例3: test_dataview_order_by

# 需要导入模块: from avocado.models import DataView [as 别名]
# 或者: from avocado.models.DataView import apply [as 别名]
    def test_dataview_order_by(self):
        f = DataField(app_name='lexicon', model_name='month', field_name='id')
        f.save()

        c = DataConcept()
        c.save()

        cf = DataConceptField(field=f, concept=c)
        cf.save()

        v = DataView({'ordering': [c.pk]})

        qs = Month.objects.filter(label__startswith='J').values('id')
        self.assertEqual(str(v.apply(qs).query), 'SELECT "lexicon_month"."id" FROM "lexicon_month" WHERE "lexicon_month"."label" LIKE J% ESCAPE \'\\\'  ORDER BY "lexicon_month"."order" ASC')
开发者ID:leipzig,项目名称:avocado,代码行数:16,代码来源:tests.py

示例4: test_view

# 需要导入模块: from avocado.models import DataView [as 别名]
# 或者: from avocado.models.DataView import apply [as 别名]
    def test_view(self):
        salary_field = DataField.objects.get_by_natural_key('exporting', 'title', 'salary')
        salary_concept = DataConcept()
        salary_concept.save()
        DataConceptField(concept=salary_concept, field=salary_field, order=1).save()

        view = DataView(json={'ordering': [[salary_concept.pk, 'desc']]})
        query = view.apply(tree=models.Employee).raw()

        # Ick..
        exporter = export.CSVExporter(view)
        exporter.params.insert(0, (RawFormatter(keys=['pk']), 1))
        exporter.row_length += 1

        buff = exporter.write(query)
        buff.seek(0)

        lines = buff.read().splitlines()
        # Skip the header
        self.assertEqual([int(x) for x in lines[1:]], [2, 4, 6, 1, 3, 5])
开发者ID:aaron0browne,项目名称:avocado,代码行数:22,代码来源:tests.py


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