本文整理汇总了Python中tastypie.paginator.Paginator.limit方法的典型用法代码示例。如果您正苦于以下问题:Python Paginator.limit方法的具体用法?Python Paginator.limit怎么用?Python Paginator.limit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tastypie.paginator.Paginator
的用法示例。
在下文中一共展示了Paginator.limit方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_limit
# 需要导入模块: from tastypie.paginator import Paginator [as 别名]
# 或者: from tastypie.paginator.Paginator import limit [as 别名]
def test_limit(self):
paginator = Paginator({}, self.data_set, limit=20, offset=0)
paginator.limit = '10'
self.assertEqual(paginator.get_limit(), 10)
paginator.limit = None
self.assertEqual(paginator.get_limit(), 20)
paginator.limit = 10
self.assertEqual(paginator.get_limit(), 10)
paginator.limit = -10
self.assertRaises(BadRequest, paginator.get_limit)
paginator.limit = 'hAI!'
self.assertRaises(BadRequest, paginator.get_limit)
示例2: test_limit
# 需要导入模块: from tastypie.paginator import Paginator [as 别名]
# 或者: from tastypie.paginator.Paginator import limit [as 别名]
def test_limit(self):
request = QueryDict('', mutable=True)
paginator = Paginator(request, self.data_set, limit=20, offset=0)
paginator.limit = '10'
self.assertEqual(paginator.get_limit(), 10)
paginator.limit = None
self.assertEqual(paginator.get_limit(), 20)
paginator.limit = 10
self.assertEqual(paginator.get_limit(), 10)
paginator.limit = -10
self.assertRaises(BadRequest, paginator.get_limit)
paginator.limit = 'hAI!'
self.assertRaises(BadRequest, paginator.get_limit)
# Test the max_limit.
paginator.limit = 1000
self.assertEqual(paginator.get_limit(), 1000)
paginator.limit = 1001
self.assertEqual(paginator.get_limit(), 1000)
paginator = Paginator({}, self.data_set, limit=20, offset=0, max_limit=10)
self.assertEqual(paginator.get_limit(), 10)
示例3: test_limit
# 需要导入模块: from tastypie.paginator import Paginator [as 别名]
# 或者: from tastypie.paginator.Paginator import limit [as 别名]
def test_limit(self):
paginator = Paginator({}, self.data_set, limit=20, offset=0)
paginator.limit = '10'
self.assertEqual(paginator.get_limit(), 10)
paginator.limit = None
self.assertEqual(paginator.get_limit(), 20)
paginator.limit = 10
self.assertEqual(paginator.get_limit(), 10)
paginator.limit = -10
raised = False
try:
paginator.get_limit()
except BadRequest, e:
raised = e
示例4: test_limit
# 需要导入模块: from tastypie.paginator import Paginator [as 别名]
# 或者: from tastypie.paginator.Paginator import limit [as 别名]
def test_limit(self):
paginator = Paginator({}, self.data_set, limit=20, offset=0)
paginator.limit = '10'
self.assertEqual(paginator.get_limit(), 10)
paginator.limit = None
self.assertEqual(paginator.get_limit(), 20)
paginator.limit = 10
self.assertEqual(paginator.get_limit(), 10)
paginator.limit = -10
raised = False
try:
paginator.get_limit()
except BadRequest as e:
raised = e
self.assertTrue(raised)
self.assertEqual(str(raised), "Invalid limit '-10' provided. Please provide a positive integer >= 0.")
paginator.limit = 'hAI!'
raised = False
try:
paginator.get_limit()
except BadRequest as e:
raised = e
self.assertTrue(raised)
self.assertEqual(str(raised), "Invalid limit 'hAI!' provided. Please provide a positive integer.")
# Test the max_limit.
paginator.limit = 1000
self.assertEqual(paginator.get_limit(), 1000)
paginator.limit = 1001
self.assertEqual(paginator.get_limit(), 1000)
paginator = Paginator({},
self.data_set, limit=20, offset=0, max_limit=10)
self.assertEqual(paginator.get_limit(), 10)
示例5: Paginator
# 需要导入模块: from tastypie.paginator import Paginator [as 别名]
# 或者: from tastypie.paginator.Paginator import limit [as 别名]
self.assertEqual(str(raised), "Invalid limit 'hAI!' provided. Please provide a positive integer.")
# Test the max_limit.
paginator.limit = 1000
self.assertEqual(paginator.get_limit(), 1000)
paginator.limit = 1001
self.assertEqual(paginator.get_limit(), 1000)
paginator = Paginator({}, self.data_set, limit=20, offset=0, max_limit=10)
self.assertEqual(paginator.get_limit(), 10)
# Test the global max limit
paginator = Paginator({}, self.data_set, limit=20, offset=0)
settings.API_MAX_LIMIT_PER_PAGE = 10000
paginator.limit = 20000
self.assertEqual(paginator.get_limit(), 10000)
# Test that if a limit is passed into the Paginator instance,
# it will defer to that
paginator = Paginator({}, self.data_set, limit=20, offset=0, max_limit=10)
paginator.limit = 20000
self.assertEqual(paginator.get_limit(), 10)
def test_offset(self):
paginator = Paginator({}, self.data_set, limit=20, offset=0)
paginator.offset = '10'
self.assertEqual(paginator.get_offset(), 10)