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


Python paginator.ObjectPaginator类代码示例

本文整理汇总了Python中django.core.paginator.ObjectPaginator的典型用法代码示例。如果您正苦于以下问题:Python ObjectPaginator类的具体用法?Python ObjectPaginator怎么用?Python ObjectPaginator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: topics

def topics(request):
    if not request.user.is_authenticated():
        return HttpResponseRedirect("/")

    # retrieve related topics
    user = request.user
    topics = Topic.objects.filter(Q(user1=user) | Q(user2=user)).order_by('-update_on')

    paginator = ObjectPaginator(topics, 10)
    try:
        page = int(request.GET.get('page', '1'))
        topics = paginator.get_page(page - 1)
    except:
        page = 1
        topics = []

    # prepare data to display
    messages_command = []
    TopicDto = type('TopicDto', (object,), {})
    for topicItem in topics:
        topicDto = TopicDto()
        topicDto.topic = topicItem
        topicDto.companion = topicItem.get_companion(user)
        topicDto.not_read_messages_count = topicItem.get_count_of_not_read_messages(user)
        messages_command.append(topicDto)

    page_title = user.get_profile().get_name().encode('utf8') + ' : ' + u'Список приватних повідомлень '.encode('utf8')

    return render_to_response('messages/topics.html',
                              {'pagetitle': page_title,
                               'u': user.get_profile(), 'can_subscribe': False, 'can_unsubscribe': False,
                               'page':page, 'paginator':paginator,
                               'messages_command': messages_command,
                               'topics': topics},
                              context_instance=RequestContext(request))
开发者ID:andrewkuzmych,项目名称:litclub,代码行数:35,代码来源:views.py

示例2: _get

    def _get(self):
        upload_url = blobstore.create_upload_url('/image/submit')
        page = self.request.get("page")
        try:
            page = int(page) - 1
        except:
            page = 0

        query = ImageAsset.all().order('-created_at')
        images = query.fetch(1000)
        if (self.PAGESIZE * page)/1000 > 0:
            cursor_iterations = (self.PAGESIZE * page)/1000
            for i in range(0, cursor_iterations):
                logging.info("Iterating though images %d/%d" % (i,cursor_iterations))
                cursor = query.cursor()
                query.with_cursor()
                images = query.fetch(1000)
        paginator = ObjectPaginator(images, self.PAGESIZE)
        #if page>=paginator.pages:
        #    page = paginator.pages - 1
        #if page < 0:
        #    page = 0
        self.template_values = {
              "images" : paginator.get_page(page),
              "pages" : range(page+1,page+paginator.pages+1),
              "page" : page+1,
              "upload_url" : upload_url
        }
        self.page_display(self,"templates/gallery.html")
开发者ID:spidaman,项目名称:image_hulk,代码行数:29,代码来源:handlers.py

示例3: get

    def get(self):
        
        page = int(self.request.get('page', '0')) 
        
        paginator = ObjectPaginator(db.GqlQuery('SELECT * FROM BlogPostModel ORDER BY created DESC'),10)
        
        blogposts = paginator.get_page(page)
        
        nextPageNumber = 0
        prevPageNumber = 0
        
        if paginator.has_next_page(page):
            nextPageNumber = str(page+1)
        
        if paginator.has_previous_page(page):
            prevPageNumber = str(page-1)
        
        template_values = {
            'menulinks':menuLinks(),
            'blogposts': blogposts,
            'user': authenticatedUser(sessions.Session()),
            'nextPageNumber': nextPageNumber,
            'prevPageNumber': prevPageNumber,
        }

        path = os.path.join(os.path.dirname(__file__), 'news.html')
        self.response.out.write(template.render(path, template_values))
开发者ID:jnydal,项目名称:greenblog,代码行数:27,代码来源:greenblog.py

示例4: get

 def get(self):
   user = self.getAuthentificatedUser()
   page = self.request.get('page')
   try:
     page = int(page) - 1
   except:
     page = 0
   allUsers = self.getUsers().order('login')
   paginator = ObjectPaginator(allUsers, 50)
   if page >= paginator.pages or page < 0:
     page = paginator.pages - 1
   if page >= paginator.pages - 1: 
     next = None
   else:
     next = page + 2
   if page < 1:
     prev = None
   else:
     prev = page
   
   forum = self.getForumInstance()
   template_values = {
     'url' : users.CreateLogoutURL(self.request.uri),
     'user' : user.nickname(),
     'forum' : forum,
     'users' : paginator.get_page(page),
     'pages' : range(1, paginator.pages + 1),
     'page' : page+1,
     'next' : next,
     'prev' : prev,
   }
   #for user in self.getUsers().order('-login'):
     #print user.login
   path = os.path.join(os.path.dirname(__file__), os.path.join('templates', 'viewUsers.htm'))
   self.response.out.write(template.render(path, template_values))
开发者ID:itsredwan,项目名称:tunedforum,代码行数:35,代码来源:main.py

示例5: get

    def get(self, slug):
        s = utils.lookup_agency_alias(slug)
        if s:
            return self.redirect('/agency/%s/' % (s))
        
        agency = utils.get_agency(slug)
        if not agency:
            raise tornado.web.HTTPError(404)
        messages =model.MessageAgency.all().filter('agency', agency).order('-date').fetch(1000)

        paginator = ObjectPaginator(messages, 10, 1)
        try:
            page = int(self.get_argument('page', '1'))
        except ValueError:
            page = 1
        if page <= 0:
            page = 1

        try:
            records = paginator.get_page(page-1)
        except:
            records = paginator.get_page(0)
            page = 1

        self.render('agency.html', agency=agency, messages=records, 
                    paginator=paginator,
                    next=paginator.has_next_page(page-1),
                    previous=paginator.has_previous_page(page-1),
                    previous_page_number=page-1,
                    next_page_number=page+1,
                    page=page)
开发者ID:stefanw,项目名称:gtfs-data-exchange,代码行数:31,代码来源:agency.py

示例6: listNamespaces

def listNamespaces(page=0, page_size=10):

    namespaces = memcache.get("namespace_list")
    if not namespaces:
        query = db.GqlQuery("SELECT * FROM Namespace WHERE owner = :1", users.get_current_user())
        namespaces = query.fetch((page_size * 10))
        memcache.set("namespace_list", namespaces, (60*1))

    paginator = ObjectPaginator(namespaces, page_size) 

    try:
        items = paginator.get_page(page)
    except InvalidPage:
        raise http.Http404     

    options = {
        "items": items,
        "is_paginated": True,
        "results_per_page" : page_size,
        "has_next": paginator.has_next_page(page),
        "has_previous": paginator.has_previous_page(page),
        "page": page + 1,
        "next": page + 1,
        "previous": page - 1,
        "pages": paginator.pages,
    }

    return options
开发者ID:jinglemansweep,项目名称:log4gae,代码行数:28,代码来源:dao.py

示例7: get

    def get(self,page):
        user = users.get_current_user()
        if user:
            if users.is_current_user_admin():
                try:
                    page = int(page) - 1
                except:
                    page = 0
                uploads = Upload.all()
                paginator = ObjectPaginator(uploads,10)
                if page>=paginator.pages:
                    page = paginator.pages - 1
        
                pages = range(1,paginator.pages+1)
                page_max = len(pages)
            
                template_values = {
			    'images': paginator.get_page(page),
			    'user': user,
			    'pages': pages,
			    'page_max': page_max,
			    'page': page+1
		        }
		
                path = os.path.join(os.path.dirname(__file__), 'templates/index.html')
                self.response.out.write(template.render(path, template_values))
            else:
                template_values = {}
                
                path = os.path.join(os.path.dirname(__file__), 'templates/404.html')
                self.response.out.write(template.render(path, template_values))
        else:
            self.redirect(users.create_login_url(self.request.uri))
开发者ID:cpow,项目名称:cpow_hosting,代码行数:33,代码来源:main.py

示例8: listMessages

def listMessages(page=0, page_size=10):

    messages = memcache.get("message_list_%s" % (users.get_current_user()))
    if not messages:
        query = db.GqlQuery("SELECT * FROM Message WHERE namespace_owner = :1 ORDER BY created DESC", users.get_current_user())
        messages = query.fetch((page_size * 10))
        memcache.set("message_list_%s" % (users.get_current_user()), messages, (60*1))

    paginator = ObjectPaginator(messages, page_size) 

    try:
        items = paginator.get_page(page)
    except InvalidPage:
        raise http.Http404     

    options = {
        "items": items,
        "is_paginated": True,
        "results_per_page" : page_size,
        "has_next": paginator.has_next_page(page),
        "has_previous": paginator.has_previous_page(page),
        "page": page + 1,
        "next": page + 1,
        "previous": page - 1,
        "pages": paginator.pages,
    }

    return options
开发者ID:jinglemansweep,项目名称:log4gae,代码行数:28,代码来源:dao.py

示例9: list

def list(request, listing_id):
  user = users.GetCurrentUser()
  if user is None:
    return http.HttpResponseForbidden('You must be signed in to view listing values')
  listing_values = None
  listing = None
  lvs_paginator = None
  if request.GET.has_key('page'):
    page = int(request.GET['page'])
  else:
    page = 0

  if listing_id:
    listing = get_listing(listing_id)
    lvs = ListingValue.all().order('-date').filter('listing_key = ', str(listing.key()))
    lvs_paginator = ObjectPaginator(lvs, 10)
    listing_values = lvs_paginator.get_page(page)

  if listing is None or listing_values is None or listing_id is None:
      return http.HttpResponseNotFound(
          'No values exists for that listing (%r)' %
          listing_id)

  paginator = {}
  paginator['has_previous_page'] = lvs_paginator.has_previous_page(page)
  paginator['has_next_page'] = lvs_paginator.has_next_page(page)
  paginator['next_page_number'] = page+1
  paginator['previous_page_number'] = page-1
  return common.respond(request, user,
                        'values_list',
                        {'listing': listing,
                         'listing_values' : listing_values,
                         'paginator': paginator})
开发者ID:wgrose,项目名称:leanto,代码行数:33,代码来源:listingvalues.py

示例10: user_page

def user_page(request, username):
  user = get_object_or_404(User, username=username)
  query_set = user.bookmark_set.order_by('-id')
  paginator = ObjectPaginator(query_set, ITEM_PER_PAGE)

  is_friend = Friendship.objects.filter(
    from_friend=request.user,
    to_friend=user
  )
  
  try:
    page = int(request.GET['page'])
  except:
    page = 1

  try:
    bookmarks = paginator.get_page(page - 1)
  except:
    raise Http404

  variables = RequestContext(request, {
    'bookmarks': bookmarks,
    'username': username,
    'show_tags': True,
    'show_edit': username == request.user.username,
    'show_paginator': paginator.pages > 1,
    'has_prev': paginator.has_previous_page(page - 1),
    'has_next': paginator.has_next_page(page - 1),
    'page': page,
    'pages': paginator.pages,
    'next_page': page + 1,
    'prev_page': page - 1,
    'is_friend': is_friend
  })
  return render_to_response('user_page.html', variables)
开发者ID:vicjung,项目名称:gae_test,代码行数:35,代码来源:views.py

示例11: get_page

 def get_page(self, page_num=None):
     try:
         if page_num is None:
             return ObjectPaginator.get_page(self, self.current_page - 1)
         else:
             return ObjectPaginator.get_page(self, page_num)
     except InvalidPage:
         return None
开发者ID:cstroie,项目名称:tranpy,代码行数:8,代码来源:paginator.py

示例12: _run_query

 def _run_query(cls, query, pagination=False, current_page=0, items_per_page=10):
     if pagination:
         paginator = ObjectPaginator(query, items_per_page)
         synopsis_list = paginator.get_page(current_page)
     else:
         paginator = None
         synopsis_list = query
     return synopsis_list, paginator
开发者ID:CarlosGabaldon,项目名称:zenopsis,代码行数:8,代码来源:models.py

示例13: filtered_kwips_page

def filtered_kwips_page(request,user_login,year,month=0,day=0,hour=0,serial=0,filter_by='day',with_reply_box=False):
  
  is_single = False
  paginate_by = 10
  dict = details_for_kwips_page(request,user_login)     
  month_in_words = ['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec']
  
  i=1
  for mon in month_in_words:
    if month==mon:
      month=i
    i=i+1
    
  #getting all accounts for user  
  accounts = Account.objects.filter(user=dict['user'],status=1)
  if accounts:
    accounts_list_in_csv = queryset_to_csv(accounts,'account')
    if filter_by=='year':
      quips =  Quip.objects.filter(account__in=accounts_list_in_csv,created_at__year=int(year)).order_by('-created_at')      
    elif filter_by=='month':
      quips =  Quip.objects.filter(account__in=accounts_list_in_csv,created_at__year=int(year),created_at__month=int(month)).order_by('-created_at')            
    elif filter_by=='date':
      quips =  Quip.objects.filter(account__in=accounts_list_in_csv,created_at__year=int(year),created_at__month=int(month),created_at__day=int(day)).order_by('-created_at')                  
    elif filter_by=='hour':
      quips = quip_for_a_time(dict['user'],filter_by,year,month,day,hour)
    elif filter_by=='minute':
      minute=hour[2]+hour[3]    
      hour = hour[0]+hour[1]    
      quips = quip_for_a_time(dict['user'],filter_by,year,month,day,int(hour),int(minute))
    elif filter_by=='second':
      second=hour[4]+hour[5]
      minute=hour[2]+hour[3]    
      hour = hour[0]+hour[1]      
      quips = quip_for_a_time(dict['user'],filter_by,year,month,day,int(hour),int(minute),int(second))
      if len(quips)==1:
        is_single=True
    elif filter_by=='single':
      second=hour[4]+hour[5]
      minute=hour[2]+hour[3]    
      hour = hour[0]+hour[1]
      quipsnow = quip_for_a_time(dict['user'],filter_by,year,month,day,int(hour),int(minute),int(second))
      is_single=True
      for q in quipsnow:
        quips = q.quips_on_same_time_serial(int(serial))
        #break commented by MD
    paginator = ObjectPaginator(quips, paginate_by)
    page = int(request.GET.get('page',0)) 
    quips = paginator.get_page(page)
    return render_to_response('mypage.html', {'is_paginated': paginator.pages > 1, 'results_per_page': paginate_by,
                              'has_next': paginator.has_next_page(page), 'has_previous': paginator.has_previous_page(page),
                              'page': page + 1, 'next': page + 1, 'previous': page - 1, 'pages': paginator.pages, 'is_following': dict['is_following'],'is_following_on_im': dict['is_following_on_im'],
                              'hits' : paginator.hits, 'login': user_login,'user_profile': dict['user_profile'],'quips': quips,'is_receiver_following':dict['is_receiver_following'],
                              'users_followees': dict['users_followees'], 'users_followers': dict['users_followers'], 'profile_for_display': dict['profile_for_display'],
                              'followees_count':dict['followees_count'], 'followers_count':dict['followers_count'],'displayname': dict['displayname'],'favs_count':dict['favs_count'],
                              'quips_for': 'self','with_reply_box':with_reply_box,'is_single':is_single,
                              'kwip_count':kwip_count(dict['user']),'comment_count':comment_count(dict['user'])},context_instance=template.RequestContext(request))
开发者ID:kwippy-com,项目名称:kwippycore,代码行数:56,代码来源:mykwips.py

示例14: comments

def comments(request, page):
    paginator = ObjectPaginator(Comments.objects.all(), 10)
    comments = paginator.get_page(page)
    template_parms = {'comment_list': comments, 'comments': True}
    if paginator.has_next_page(page):
        template_parms['next'] = True
    if paginator.has_previous_page(page):
        template_parms['prev'] = True

    return render_to_response('comments.html', template_parms)
开发者ID:ambrice,项目名称:wedding,代码行数:10,代码来源:views.py

示例15: paginate

def paginate(obj, page):
  p = ObjectPaginator(
    obj,
    PAGE_ELEMENTS
  )
  try:
    obj_list = p.get_page(page - 1)
  except InvalidPage:
    obj_list = []
  return (obj_list, p)
开发者ID:gunyarakun,项目名称:django-wikipedia-search,代码行数:10,代码来源:views.py


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