本文整理汇总了Python中tastypie.paginator.Paginator类的典型用法代码示例。如果您正苦于以下问题:Python Paginator类的具体用法?Python Paginator怎么用?Python Paginator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Paginator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: gather_steamies
def gather_steamies(self, request, **kwargs):
self.method_check(request, allowed=['get'])
self.throttle_check(request)
qs = Steamies.objects\
.filter(top_level_id=kwargs['top_level_id'])
paginator = Paginator(request.GET,
qs)
try:
page = paginator.page()
except InvalidPage:
raise Http404("Sorry, no results on that page.")
objects = []
for obj in page['objects']:
bundle = self.build_bundle(obj=obj,
request=request)
bundle = self.full_dehydrate(bundle)
objects.append(bundle)
page['objects'] = objects
self.log_throttled_access(request)
return self.create_response(request, page)
开发者ID:risd,项目名称:steam,代码行数:27,代码来源:resources.py
示例2: test_regression_nonqueryset
def test_regression_nonqueryset(self):
request = QueryDict('', mutable=True)
paginator = Paginator(request, ['foo', 'bar', 'baz'], limit=2, offset=0)
# This would fail due to ``count`` being present on ``list`` but called
# differently.
page = paginator.page()
self.assertEqual(page['objects'], ['foo', 'bar'])
开发者ID:georgemarshall,项目名称:django-tastypie,代码行数:7,代码来源:paginator.py
示例3: get_custom_list
def get_custom_list(self, request, queryset):
'''
Generic function to paginate a queryset with a set of items per page.
'''
self.method_check(request, allowed=['get'])
self.throttle_check(request)
# Do the query.
offset = int(request.GET.get('offset', 0))
limit = min(int(request.GET.get('limit', 20)), 1000)
paginator = Paginator(request.GET, queryset)
try:
object_list = paginator.get_slice(limit, offset)
except InvalidPage:
raise Http404("Sorry, no results on that page.")
objects = []
for result in object_list:
bundle = self.build_bundle(obj=result, request=request)
bundle = self.full_dehydrate(bundle)
objects.append(bundle)
page = {
"meta": {
"limit": limit,
"offset": offset,
"total_count": queryset.count()
},
'objects': objects,
}
self.log_throttled_access(request)
return self.create_response(request, page)
开发者ID:danigm,项目名称:agora-ciudadana,代码行数:35,代码来源:generic_resource.py
示例4: get_search
def get_search(self, request, **kwargs):
self.method_check(request, allowed=['get'])
self.is_authenticated(request)
self.throttle_check(request)
# Do the query.
ret = []
for field in self._meta.object_class.haystack_index:
kwargs = {field: request.GET.get('q', '')}
sqs = SearchQuerySet().models(self._meta.object_class).autocomplete(**kwargs)
ret.extend(sqs)
paginator = Paginator(request.GET, ret)
try:
page = paginator.page()
except InvalidPage:
raise Http404("Sorry, no results on that page.")
objects = []
for result in page['objects']:
bundle = self.build_bundle(obj=result.object, request=request)
bundle = self.full_dehydrate(bundle)
objects.append(bundle)
object_list = {
'objects': objects,
}
self.log_throttled_access(request)
return self.create_response(request, object_list)
开发者ID:chembl,项目名称:chembl_api,代码行数:31,代码来源:base_resource.py
示例5: get_search
def get_search(self, request, **kwargs):
'''
Custom endpoint for search
'''
self.method_check(request, allowed=['get'])
query = request.GET.get('q', "*:*")
if not query:
raise BadRequest(
'Please supply the search parameter (e.g. '
'"/api/v1/clips/search/?q=css")')
results = SearchQuerySet().raw_search(query)
if not results:
results = EmptySearchQuerySet()
paginator = Paginator(request.GET, results,
resource_uri='/api/v1/sample/search/')
bundles = []
for result in paginator.page()['objects']:
bundle = self.build_bundle(obj=result.object, request=request)
bundles.append(self.full_dehydrate(bundle))
object_list = {
'meta': paginator.page()['meta'],
'objects': bundles
}
object_list['meta']['search_query'] = query
self.log_throttled_access(request)
return self.create_response(request, object_list)
开发者ID:srkama,项目名称:haysolr,代码行数:31,代码来源:api.py
示例6: search
def search(self, request, **kwargs):
"""
An endpoint for performing full-text searches.
TKTK -- implement field searches
TKTK -- implement wildcard + boolean searches
"""
self.method_check(request, allowed=['get'])
self.is_authenticated(request)
self.throttle_check(request)
s = SolrSearch(self._solr()).query(full_text=request.GET.get('q'))
paginator = Paginator(request.GET, s, resource_uri=request.path_info)
page = paginator.page()
objects = []
for result in page['objects']:
obj = SolrObject(result)
bundle = self.build_bundle(obj=obj, request=request)
bundle = self.full_dehydrate(bundle)
objects.append(bundle)
page['objects'] = objects
self.log_throttled_access(request)
return self.create_response(request, page)
开发者ID:netconstructor,项目名称:panda,代码行数:29,代码来源:api.py
示例7: get_search
def get_search(self, request, **kwargs):
query = kwargs.pop('query')
source = 'flickr'
relevant_docs = request.GET.getlist('relevant')
irrelevant_docs = request.GET.getlist('irrelevant')
feature = request.GET.get('feature')
page = request.GET.get('page', 1)
per_page = request.GET.get('limit', 20)
results = flickr.photos_search(tags=query, page=str(page), per_page=str(per_page))[0]
for photo in results:
url = self._get_url(photo)
cache_key = '%s-%s' % (source, photo.get('id'))
feature_vectors = cache.get(cache_key)
if not feature_vectors:
features.extract_features(cache_key, url)
results = features.filter(results, source, relevant_docs, irrelevant_docs, feature)
paginator = Paginator(request.GET, results, resource_uri='/api/v1/flickr/search/')
bundles = []
for result in paginator.page()['objects']:
bundle = self.build_bundle(obj=self._output_adapter(result), request=request)
bundles.append(self.full_dehydrate(bundle))
object_list = {
'meta': paginator.page()['meta'],
'objects': bundles,
}
object_list['meta']['query'] = query
return self.create_response(request, object_list)
开发者ID:mattcaldwell,项目名称:react,代码行数:32,代码来源:api.py
示例8: get_search
def get_search(self, request, **kwargs):
self.method_check(request, allowed=['get'])
self.is_authenticated(request)
self.throttle_check(request)
print request.GET
query = request.GET.get('q', None)
if not query:
raise BadRequest('Please supply the search parameter (e.g. "/api/v1/notes/search/?q=css")')
# results = SearchQuerySet().models(Note).filter(user=request.user).auto_query(query)
results = SearchQuerySet().models(Donate).auto_query(query)
if not results:
results = EmptySearchQuerySet()
paginator = Paginator(request.GET, results, resource_uri='/api/v1/notes/search/')
bundles = []
for result in paginator.page()['objects']:
bundle = self.build_bundle(obj=result.object, request=request)
bundles.append(self.full_dehydrate(bundle))
object_list = {
'meta': paginator.page()['meta'],
'objects': bundles
}
object_list['meta']['search_query'] = query
self.log_throttled_access(request)
return self.create_response(request, object_list)
开发者ID:carriercomm,项目名称:donate-4,代码行数:30,代码来源:api.py
示例9: test_unicode_request
def test_unicode_request(self):
request = {
'slug__startswith': u'☃',
'format': 'json',
}
paginator = Paginator(request, self.data_set,
resource_uri='/api/v1/notes/', limit=2, offset=2)
meta = paginator.page()['meta']
self.assertEqual(meta['limit'], 2)
self.assertEqual(meta['offset'], 2)
self.assertTrue('limit=2' in meta['previous'])
self.assertTrue('offset=0' in meta['previous'])
self.assertTrue('slug__startswith=%E2%98%83' in meta['previous'])
self.assertTrue('format=json' in meta['previous'])
self.assertTrue('limit=2' in meta['next'])
self.assertTrue('offset=4' in meta['next'])
self.assertTrue('slug__startswith=%E2%98%83' in meta['next'])
self.assertTrue('format=json' in meta['next'])
self.assertEqual(meta['total_count'], 6)
request = QueryDict('slug__startswith=☃&format=json')
paginator = Paginator(request, self.data_set,
resource_uri='/api/v1/notes/', limit=2, offset=2)
meta = paginator.page()['meta']
self.assertEqual(meta['limit'], 2)
self.assertEqual(meta['offset'], 2)
self.assertTrue('limit=2' in meta['previous'])
self.assertTrue('offset=0' in meta['previous'])
self.assertTrue('slug__startswith=%E2%98%83' in meta['previous'])
self.assertTrue('format=json' in meta['previous'])
self.assertTrue('limit=2' in meta['next'])
self.assertTrue('offset=4' in meta['next'])
self.assertTrue('slug__startswith=%E2%98%83' in meta['next'])
self.assertTrue('format=json' in meta['next'])
self.assertEqual(meta['total_count'], 6)
开发者ID:SeanHayes,项目名称:django-tastypie,代码行数:35,代码来源:paginator.py
示例10: get_refresh
def get_refresh(self, request, **kwargs):
self.method_check(request, allowed=['get'])
self.is_authenticated(request)
self.throttle_check(request)
if 'marked_at__gt' not in request.GET:
results = UserStars.objects.filter(user_id=request.user.id).order_by('-marked_at').exclude(star=1)
else:
results = UserStars.objects.filter(user_id=request.user.id,
marked_at__gt=request.GET['marked_at__gt'])\
.order_by('-marked_at').exclude(star=1)
paginator = Paginator(request.GET, results, resource_uri='/api/v1/account/star/refresh/')
bundles = []
for result in paginator.page()['objects']:
bundle = self.build_bundle(obj=result, request=request)
bundle.data['refresh'] = True
bundle.data['id'] = bundle.obj.article_id
bundles.append(self.full_dehydrate(bundle))
object_list = {
'meta': paginator.page()['meta'],
'objects': bundles
}
self.log_throttled_access(request)
return self.create_response(request, object_list)
开发者ID:7achilles7,项目名称:newsreader,代码行数:28,代码来源:api.py
示例11: get_search
def get_search(self, request, **kwargs):
self.method_check(request, allowed=['get'])
self.is_authenticated(request)
self.throttle_check(request)
self.log_throttled_access(request)
query = request.GET.get('q', None)
if not query:
raise BadRequest('Please supply the search parameter (e.g. "/api/v1/feeds/search/?q=query")')
results = SearchQuerySet().filter(content__contains=query).filter_or(keywords__contains=query).models(Feed)
paginator = Paginator(request.GET, results, resource_uri='/api/v1/feeds/search/')
bundles = []
for result in paginator.page()['objects']:
bundle = self.build_bundle(obj=result.object, request=request)
bundles.append(self.full_dehydrate(bundle))
object_list = {
'meta': paginator.page()['meta'],
'objects': bundles
}
object_list['meta']['search_query'] = query
self.log_throttled_access(request)
return self.create_response(request, object_list)
开发者ID:7achilles7,项目名称:newsreader,代码行数:26,代码来源:api.py
示例12: get_populars
def get_populars(self, request, **kwargs):
self.method_check(request, allowed=['get'])
self.is_authenticated(request)
self.throttle_check(request)
time_frame = datetime.utcnow() - timedelta(days=1)
most_read = UserReads.objects.filter(marked_at__gte=time_frame)\
.annotate(occ=Count('article')).order_by('-occ')
if not most_read or len(most_read) < 1000:
results = Article.objects.filter(Q(id__in=most_read.values('article')) |
Q(feed_id__in=CategoryFeeds.objects.all().values('feed_id')))\
.order_by('-date_parsed')
else:
results = Article.objects.filter(id__in=most_read.values('article')).order_by('-date_parsed')
paginator = Paginator(request.GET, results, resource_uri='/api/v1/articles/populars/')
bundles = []
for result in paginator.page()['objects']:
bundle = self.build_bundle(obj=result, request=request)
bundles.append(self.full_dehydrate(bundle))
object_list = {
'meta': paginator.page()['meta'],
'objects': bundles
}
self.log_throttled_access(request)
return self.create_response(request, object_list)
开发者ID:7achilles7,项目名称:newsreader,代码行数:29,代码来源:api.py
示例13: test_multiple
def test_multiple(self):
request = QueryDict("a=1&a=2")
paginator = Paginator(request, self.data_set, resource_uri="/api/v1/notes/", limit=2, offset=2)
meta = paginator.page()["meta"]
self.assertEqual(meta["limit"], 2)
self.assertEqual(meta["offset"], 2)
self.assertEqual(meta["previous"], "/api/v1/notes/?a=1&a=2&limit=2&offset=0")
self.assertEqual(meta["next"], "/api/v1/notes/?a=1&a=2&limit=2&offset=4")
开发者ID:Bahus,项目名称:django-tastypie,代码行数:8,代码来源:paginator.py
示例14: test_large_limit
def test_large_limit(self):
paginator = Paginator({}, self.repr_set, limit=20, offset=0)
meta = paginator.page()['meta']
self.assertEqual(meta['limit'], 20)
self.assertEqual(meta['offset'], 0)
self.assertEqual(meta['previous'], None)
self.assertEqual(meta['next'], None)
self.assertEqual(meta['total_count'], 6)
开发者ID:mdornseif,项目名称:django-tastypie,代码行数:8,代码来源:paginator.py
示例15: test_large_limit
def test_large_limit(self):
paginator = Paginator({}, self.data_set, resource_uri="/api/v1/notes/", limit=20, offset=0)
meta = paginator.page()["meta"]
self.assertEqual(meta["limit"], 20)
self.assertEqual(meta["offset"], 0)
self.assertEqual(meta["previous"], None)
self.assertEqual(meta["next"], None)
self.assertEqual(meta["total_count"], 6)
开发者ID:Bahus,项目名称:django-tastypie,代码行数:8,代码来源:paginator.py
示例16: test_page2
def test_page2(self):
paginator = Paginator({}, self.repr_set, limit=2, offset=2)
meta = paginator.page()['meta']
self.assertEqual(meta['limit'], 2)
self.assertEqual(meta['offset'], 2)
self.assertEqual(meta['previous'], '/api/v1/notes/?limit=2&offset=0')
self.assertEqual(meta['next'], '/api/v1/notes/?limit=2&offset=4')
self.assertEqual(meta['total_count'], 6)
开发者ID:mdornseif,项目名称:django-tastypie,代码行数:8,代码来源:paginator.py
示例17: test_page3
def test_page3(self):
paginator = Paginator({}, self.data_set, resource_uri="/api/v1/notes/", limit=2, offset=4)
meta = paginator.page()["meta"]
self.assertEqual(meta["limit"], 2)
self.assertEqual(meta["offset"], 4)
self.assertEqual(meta["previous"], "/api/v1/notes/?limit=2&offset=2")
self.assertEqual(meta["next"], None)
self.assertEqual(meta["total_count"], 6)
开发者ID:Bahus,项目名称:django-tastypie,代码行数:8,代码来源:paginator.py
示例18: test_all
def test_all(self):
paginator = Paginator({'limit': 0}, self.data_set, resource_uri='/api/v1/notes/', limit=2, offset=0)
page = paginator.page()
meta = page['meta']
self.assertEqual(meta['limit'], 1000)
self.assertEqual(meta['offset'], 0)
self.assertEqual(meta['total_count'], 6)
self.assertEqual(len(page['objects']), 6)
开发者ID:5783354,项目名称:django-tastypie,代码行数:8,代码来源:paginator.py
示例19: projectsheet_search
def projectsheet_search(self, request, **kwargs):
""" Search project sheets. """
self.method_check(request, allowed=['get'])
self.throttle_check(request)
self.is_authenticated(request)
# Query params
query = request.GET.get('q', '')
autocomplete = request.GET.get('auto', None)
selected_facets = request.GET.getlist('facet', None)
order = request.GET.getlist('order', None)
sqs = SearchQuerySet().models(self.Meta.object_class).facet('tags')
# narrow down QS with facets
if selected_facets:
for facet in selected_facets:
sqs = sqs.narrow('tags:%s' % (facet))
# A: if autocomplete, we return only a list of tags
# starting with "auto" along with their count.
if autocomplete is not None:
tags = sqs.facet_counts()
tags = tags['fields']['tags']
if len(autocomplete) > 0:
tags = [t for t in tags if t[0].startswith(autocomplete)]
tags = [{'name': t[0], 'count': t[1]} for t in tags]
object_list = {
'objects': tags,
}
# B: else, we return a list of projectsheets
else:
# launch query
if query != "":
sqs = sqs.auto_query(query)
uri = reverse('api_projectsheet_search',
kwargs={'api_name': self.api_name,
'resource_name': self._meta.resource_name})
paginator = Paginator(request.GET, sqs, resource_uri=uri)
objects = []
for result in paginator.page()['objects']:
if result:
bundle = self.build_bundle(obj=result.object,
request=request)
bundle = self.full_dehydrate(bundle, for_list=True)
objects.append(bundle)
object_list = {
'meta': paginator.page()['meta'],
'objects': objects,
}
self.log_throttled_access(request)
return self.create_response(request, object_list)
开发者ID:14mmm,项目名称:dataserver,代码行数:57,代码来源:api.py
示例20: test_page2
def test_page2(self):
request = QueryDict('', mutable=True)
paginator = Paginator(request, self.data_set, resource_uri='/api/v1/notes/', limit=2, offset=2)
meta = paginator.page()['meta']
self.assertEqual(meta['limit'], 2)
self.assertEqual(meta['offset'], 2)
self.assertEqual(meta['previous'], '/api/v1/notes/?limit=2&offset=0')
self.assertEqual(meta['next'], '/api/v1/notes/?limit=2&offset=4')
self.assertEqual(meta['total_count'], 6)
开发者ID:georgemarshall,项目名称:django-tastypie,代码行数:9,代码来源:paginator.py
注:本文中的tastypie.paginator.Paginator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论