當前位置: 首頁>>代碼示例>>Python>>正文


Python Datasource.as_datasource方法代碼示例

本文整理匯總了Python中ereports.engine.datasource.Datasource.as_datasource方法的典型用法代碼示例。如果您正苦於以下問題:Python Datasource.as_datasource方法的具體用法?Python Datasource.as_datasource怎麽用?Python Datasource.as_datasource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ereports.engine.datasource.Datasource的用法示例。


在下文中一共展示了Datasource.as_datasource方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_headers

# 需要導入模塊: from ereports.engine.datasource import Datasource [as 別名]
# 或者: from ereports.engine.datasource.Datasource import as_datasource [as 別名]
    def test_headers(self):
        G(SimpleDemoModel, n=2, char='abc', integer1=10, integer2=20)

        ds = Datasource.as_datasource(model=SimpleDemoModel)
        r = BaseReport.as_report(datasource=ds,
                                 list_display=['integer2', 'char', 'integer1'])

        self.assertSequenceEqual(['Integer #2', 'Character', 'Integer #1'], r.headers)

        ds = Datasource.as_datasource(model=SimpleDemoModel,
                                      columns=['integer2', 'char', 'integer1'])
        r = BaseReport.as_report(datasource=ds)

        self.assertSequenceEqual(['Integer #2', 'Character', 'Integer #1'], r.headers)
開發者ID:saxix,項目名稱:django-easy-reports,代碼行數:16,代碼來源:report.py

示例2: test_list_columns

# 需要導入模塊: from ereports.engine.datasource import Datasource [as 別名]
# 或者: from ereports.engine.datasource.Datasource import as_datasource [as 別名]
 def test_list_columns(self):
     G(SimpleDemoModel, n=2, char='abc', integer1=1, integer2=3)
     ds = Datasource.as_datasource(model=SimpleDemoModel,
                                   columns=[('char', Column), ('integer1', Column)])
     self.assertSequenceEqual([c.name for c in ds.columns], ['char', 'integer1'])
     self.assertSequenceEqual([c.title for c in ds.columns], ['Character', 'Integer #1'])
     self.assertSequenceEqual(ds, [(u'abc', 1), (u'abc', 1)])
開發者ID:bugman80,項目名稱:django-easy-reports,代碼行數:9,代碼來源:datasource.py

示例3: test_total

# 需要導入模塊: from ereports.engine.datasource import Datasource [as 別名]
# 或者: from ereports.engine.datasource.Datasource import as_datasource [as 別名]
def test_total():
    G(SimpleDemoModel, n=2, char='abc', integer1=10, integer2=20)
    ds = Datasource.as_datasource(model=SimpleDemoModel)
    r = BaseReport.as_report(datasource=ds)

    assert total(r, 'integer2') == 40
    assert total(r, 'char') == 0
開發者ID:saxix,項目名稱:django-easy-reports,代碼行數:9,代碼來源:ereports.py

示例4: test_get_column_values

# 需要導入模塊: from ereports.engine.datasource import Datasource [as 別名]
# 或者: from ereports.engine.datasource.Datasource import as_datasource [as 別名]
    def test_get_column_values(self):
        G(SimpleDemoModel, n=10, data_fixture=SequentialDataFixture(0))
        ds = Datasource.as_datasource(model=SimpleDemoModel)
        r = BaseReport.as_report(datasource=ds,
                                 list_display=['integer2', 'char', 'integer1'])

        self.assertSequenceEqual([1, 3, 5, 7, 9, 11, 13, 15, 17, 19], r.get_column_values('integer1'))
開發者ID:saxix,項目名稱:django-easy-reports,代碼行數:9,代碼來源:report.py

示例5: test_by_custom_column

# 需要導入模塊: from ereports.engine.datasource import Datasource [as 別名]
# 或者: from ereports.engine.datasource.Datasource import as_datasource [as 別名]
    def test_by_custom_column(self):
        itms = [User(username='username%s' % x,
                     first_name='fn%s' % int(x % 2),
                     last_name='ln%s' % int(x % 2),
                     is_staff=bool(x % 2)) for x in range(6)]

        ds = Datasource.as_datasource(model=User,
                                      columns=('is_staff',
                                               'username',
                                               StringFormatColumn('group',
                                                                  format='{0.last_name} {0.first_name}')),
                                      queryset=FakeQuerySet(model=User, items=itms))

        TestReport = type('Report', (BaseReport,), {'datasource': ds,
                                                    'group_by': ('group', 'username'),
                                                    'list_display': ('group', 'username')})
        report = TestReport.as_report()
        self.assertSequenceEqual(sorted(dict(report.get_groups()).keys()),
                                 ['ln0 fn0', 'ln1 fn1'])

        self.assertSequenceEqual(list(report),
                                 [('ln0 fn0', 'username0'),
                                  ('ln0 fn0', 'username2'),
                                  ('ln0 fn0', 'username4'),
                                  ('ln1 fn1', 'username1'),
                                  ('ln1 fn1', 'username3'),
                                  ('ln1 fn1', 'username5')])
開發者ID:saxix,項目名稱:django-easy-reports,代碼行數:29,代碼來源:group.py

示例6: test_custom_column_from_string

# 需要導入模塊: from ereports.engine.datasource import Datasource [as 別名]
# 或者: from ereports.engine.datasource.Datasource import as_datasource [as 別名]
 def test_custom_column_from_string(self):
     G(SimpleDemoModel, n=2, char='abc', integer1=1, integer2=3)
     ds = Datasource.as_datasource(model=SimpleDemoModel,
                                   extra_column=lambda obj: 'extra_value',
                                   columns=[Column('integer1'),
                                            'integer2',
                                            CalcColumn(['integer1', 'integer2'])])
     self.assertSequenceEqual(ds, [(1, 3, 4), (1, 3, 4)])
開發者ID:bugman80,項目名稱:django-easy-reports,代碼行數:10,代碼來源:datasource.py

示例7: test_columns

# 需要導入模塊: from ereports.engine.datasource import Datasource [as 別名]
# 或者: from ereports.engine.datasource.Datasource import as_datasource [as 別名]
    def test_columns(self):
        G(SimpleDemoModel, n=2, char='abc', integer1=1)
        ds = Datasource.as_datasource(model=SimpleDemoModel,
                                      columns=[Column('char', 'AAA'), Column('integer1')])

        self.assertSequenceEqual([c.name for c in ds.columns], ['char', 'integer1'])
        self.assertSequenceEqual([c.title for c in ds.columns], ['AAA', 'Integer #1'])
        self.assertSequenceEqual(ds, [(u'abc', 1), (u'abc', 1)])
開發者ID:bugman80,項目名稱:django-easy-reports,代碼行數:10,代碼來源:datasource.py

示例8: test_datasource_custom_list_display

# 需要導入模塊: from ereports.engine.datasource import Datasource [as 別名]
# 或者: from ereports.engine.datasource.Datasource import as_datasource [as 別名]
    def test_datasource_custom_list_display(self):
        G(SimpleDemoModel, n=2, char='abc', integer1=10, integer2=20)

        ds = Datasource.as_datasource(model=SimpleDemoModel)
        r = BaseReport.as_report(datasource=ds,
                                 list_display=['integer2', 'char', 'integer1'])

        self.assertSequenceEqual(r[1], (20, u'abc', 10))
        self.assertSequenceEqual(r[:1], [(20, u'abc', 10)])
開發者ID:saxix,項目名稱:django-easy-reports,代碼行數:11,代碼來源:report.py

示例9: test_datasource_std_list_display

# 需要導入模塊: from ereports.engine.datasource import Datasource [as 別名]
# 或者: from ereports.engine.datasource.Datasource import as_datasource [as 別名]
    def test_datasource_std_list_display(self):
        G(SimpleDemoModel, n=2, char='abc', integer1=10, integer2=20)

        ds = Datasource.as_datasource(model=SimpleDemoModel,
                                      columns=['integer2', 'char', 'integer1'])
        r = BaseReport.as_report(datasource=ds)

        self.assertSequenceEqual([c.name for c in ds.columns], r.display_order())
        self.assertSequenceEqual(r[1], (20, u'abc', 10))
開發者ID:saxix,項目名稱:django-easy-reports,代碼行數:11,代碼來源:report.py

示例10: test_filter_queryset

# 需要導入模塊: from ereports.engine.datasource import Datasource [as 別名]
# 或者: from ereports.engine.datasource.Datasource import as_datasource [as 別名]
    def test_filter_queryset(self):
        instances = G(SimpleDemoModel, n=5, char='abc')

        self.assertEquals(len(instances), 5)

        ds = Datasource.as_datasource(queryset=SimpleDemoModel.objects.all(),
                                      columns=['id', 'char'])
        ds.add_filters(id__gt=instances[2].pk)
        self.assertSequenceEqual(ds, [(instances[3].pk, u'abc'), (instances[4].pk, u'abc')])
開發者ID:bugman80,項目名稱:django-easy-reports,代碼行數:11,代碼來源:datasource.py

示例11: test_create_from_queryset

# 需要導入模塊: from ereports.engine.datasource import Datasource [as 別名]
# 或者: from ereports.engine.datasource.Datasource import as_datasource [as 別名]
    def test_create_from_queryset(self):
        instances = G(SimpleDemoModel, n=2, char='abc')

        self.assertEquals(len(instances), 2)

        ds = Datasource.as_datasource(queryset=SimpleDemoModel.objects.all(),
                                      columns=['id', 'char'])

        self.assertSequenceEqual([c.name for c in ds.columns], ['id', 'char'])
        self.assertSequenceEqual([c.title for c in ds.columns], ['ID', 'Character'])
        self.assertSequenceEqual(ds, [(instances[0].pk, u'abc'), (instances[1].pk, u'abc')])
開發者ID:bugman80,項目名稱:django-easy-reports,代碼行數:13,代碼來源:datasource.py

示例12: test_create_from_model

# 需要導入模塊: from ereports.engine.datasource import Datasource [as 別名]
# 或者: from ereports.engine.datasource.Datasource import as_datasource [as 別名]
    def test_create_from_model(self):
        instances = G(SimpleDemoModel, n=2, char='1', integer1=1, integer2=2, boolean=True)

        self.assertEquals(len(instances), 2)

        ds = Datasource.as_datasource(model=SimpleDemoModel)

        self.assertSequenceEqual([c.name for c in ds.columns], ['id', 'char', 'integer1', 'integer2', 'boolean'])
        self.assertSequenceEqual([c.title for c in ds.columns],
                                 ['ID', 'Character', 'Integer #1', 'Integer #2', 'Boolean'])
        self.assertSequenceEqual(ds, [(instances[0].pk, u'1', 1, 2, True), (instances[1].pk, u'1', 1, 2, True)])
開發者ID:bugman80,項目名稱:django-easy-reports,代碼行數:13,代碼來源:datasource.py

示例13: test_custom_column_callable

# 需要導入模塊: from ereports.engine.datasource import Datasource [as 別名]
# 或者: from ereports.engine.datasource.Datasource import as_datasource [as 別名]
    def test_custom_column_callable(self):
        G(SimpleDemoModel, n=2, char='abc', integer1=10, integer2=20)

        def _custom_callable(obj, ds):
            return obj.integer1 + 100

        ds = Datasource.as_datasource(model=SimpleDemoModel,
                                      columns=[Column('integer1'),
                                               Column('integer2'),
                                               ColumnCallable(_custom_callable)])

        self.assertSequenceEqual(ds, [(10, 20, 110), (10, 20, 110)])
開發者ID:bugman80,項目名稱:django-easy-reports,代碼行數:14,代碼來源:datasource.py

示例14: test_custom_filter

# 需要導入模塊: from ereports.engine.datasource import Datasource [as 別名]
# 或者: from ereports.engine.datasource.Datasource import as_datasource [as 別名]
    def test_custom_filter(self):
        G(SimpleDemoModel, n=10, char='abc')
        ds = Datasource.as_datasource(model=SimpleDemoModel, columns=[Column('filter_source')])
        ds._get_queryset = mock.Mock(wraps=ds._get_queryset)
        ds._create_result_cache = mock.Mock(wraps=ds._create_result_cache)

        def filter_odd(row):
            if not row.filter_source.value % 2:
                raise RecordFilteredError

        ds.add_custom_filter(filter_odd)
        list(ds)
        list(ds)
        self.assertSequenceEqual(ds, [(1,), (3,), (5,), (7,), (9,)])
        assert ds._get_queryset.call_count == 1
        assert ds._create_result_cache.call_count == 1
開發者ID:bugman80,項目名稱:django-easy-reports,代碼行數:18,代碼來源:datasource.py

示例15: test_format_raw_value

# 需要導入模塊: from ereports.engine.datasource import Datasource [as 別名]
# 或者: from ereports.engine.datasource.Datasource import as_datasource [as 別名]
def test_format_raw_value():
    c = DecimalColumn('salary.currency')
    r = RowValue(Decimal("1000"), column=c)
    assert format_raw_value(r) == "1,000.00"

    r = RowValue("1000", column=c)
    assert format_raw_value(r) == "1000"

    ds = Datasource.as_datasource(model=User,
                                  queryset=FakeQuerySet(model=User, items=[User(username='username1'),
                                                                           User(username='username2')]))

    TestReport = type('TestReport', (BaseReport,), {'model': User, 'datasource': ds})
    report = TestReport.as_report()

    assert format_raw_value(report[0].username) == 'username1'
    assert format_raw_value(report[0]['username']) == 'username1'
開發者ID:saxix,項目名稱:django-easy-reports,代碼行數:19,代碼來源:ereports.py


注:本文中的ereports.engine.datasource.Datasource.as_datasource方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。