本文整理汇总了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)
示例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)])
示例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
示例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'))
示例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')])
示例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)])
示例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)])
示例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)])
示例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))
示例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')])
示例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')])
示例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)])
示例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)])
示例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
示例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'