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


Python ObjectPaginator.last_on_page方法代码示例

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


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

示例1: list

# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import last_on_page [as 别名]
 def list(self, request, queryset, page=None):
     """
     Renders a list of model objects to HttpResponse.
     """
     template_name = '%s/%s_list.html' % (self.template_dir, queryset.model._meta.module_name)
     if self.paginate_by:
         paginator = ObjectPaginator(queryset, self.paginate_by)
         if not page:
             page = request.GET.get('page', 1)
         try:
             page = int(page)
             object_list = paginator.get_page(page - 1)
         except (InvalidPage, ValueError):
             if page == 1 and self.allow_empty:
                 object_list = []
             else:
                 raise Http404
         c = RequestContext(request, {
             '%s_list' % self.template_object_name: object_list,
             'is_paginated': paginator.pages > 1,
             'results_per_page': self.paginate_by,
             'has_next': paginator.has_next_page(page - 1),
             'has_previous': paginator.has_previous_page(page - 1),
             'page': page,
             'next': page + 1,
             'previous': page - 1,
             'last_on_page': paginator.last_on_page(page - 1),
             'first_on_page': paginator.first_on_page(page - 1),
             'pages': paginator.pages,
             'hits' : paginator.hits,
         }, self.context_processors)
     else:
         object_list = queryset
         c = RequestContext(request, {
             '%s_list' % self.template_object_name: object_list,
             'is_paginated': False
         }, self.context_processors)
         if not self.allow_empty and len(queryset) == 0:
             raise Http404
     # Hide unexposed fields
     for obj in object_list:
         self._hide_unexposed_fields(obj, self.expose_fields)
     c.update(self.extra_context)        
     t = self.template_loader.get_template(template_name)
     return HttpResponse(t.render(c), mimetype=self.mimetype)
开发者ID:alatteri,项目名称:informer,代码行数:47,代码来源:responder.py

示例2: changes

# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import last_on_page [as 别名]
def changes(request, asset_type=None, asset_id=None,
            current_user=True, page_number=0, num_per_page=10):
    """Return a paginated list of recent asset changes,
       filtered in the following ways:

        - If 'asset_type' and 'asset_id' are supplied, this limits
          the changes to those from a single asset.

        - If 'current_user' is set, this only shows changes to objects
          that are owned by the currently logged-in user.

       This returns a JSON result which is used by client-side
       pagination code.
       """
    changes = models.AssetChangeset.objects.all()

    if asset_id is not None:
        changes = changes.filter(
            content_type = ContentType.objects.get_for_model(get_asset_by_type(asset_type)),
            object_id = int(asset_id),
            )

    if current_user:
        changes = changes.extra(
            tables = ["accounts_userasset"],
            where = ["accounts_userasset.content_type_id = accounts_assetchangeset.content_type_id",
                     "accounts_userasset.object_id = accounts_assetchangeset.object_id",
                     "accounts_userasset.user_id = %d" % request.user.id],
            )

    paginator = ObjectPaginator(changes.order_by('-id'),
                                num_per_page = num_per_page,
                                orphans = num_per_page / 2)
    return {
        'remaining': paginator.hits - paginator.last_on_page(page_number),

        'html': smart_unicode(loader.render_to_string(
            'accounts/asset_changes.html',
            RequestContext(request, {
                'changesets': paginator.get_page(page_number),
                'show_asset_name': asset_id is None,
            }))),
        }
开发者ID:SkyFire,项目名称:cia-vc,代码行数:45,代码来源:assets.py

示例3: object_list

# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import last_on_page [as 别名]
def object_list(request, queryset, paginate_by=None, page=None,
        allow_empty=True, template_name=None, template_loader=loader,
        extra_context=None, context_processors=None, template_object_name='object',
        mimetype=None):
    """
    Generic list of objects.

    Templates: ``<app_label>/<model_name>_list.html``
    Context:
        object_list
            list of objects
        is_paginated
            are the results paginated?
        results_per_page
            number of objects per page (if paginated)
        has_next
            is there a next page?
        has_previous
            is there a prev page?
        page
            the current page
        next
            the next page
        previous
            the previous page
        pages
            number of pages, total
        hits
            number of objects, total
        last_on_page
            the result number of the last of object in the
            object_list (1-indexed)
        first_on_page
            the result number of the first object in the
            object_list (1-indexed)
        page_range:
            A list of the page numbers (1-indexed).
    """
    if extra_context is None: extra_context = {}
    queryset = queryset._clone()
    if paginate_by:
        paginator = ObjectPaginator(queryset, paginate_by)
        if not page:
            page = request.GET.get('page', 1)
        try:
            page_number = int(page)
        except ValueError:
            if page == 'last':
                page_number = paginator.pages
            else:
                # Page is not 'last', nor can it be converted to an int
                raise Http404
        try:
            object_list = paginator.get_page(page_number - 1)
        except InvalidPage:
            if page_number == 1 and allow_empty:
                object_list = []
            else:
                raise Http404
        c = RequestContext(request, {
            '%s_list' % template_object_name: object_list,
            'is_paginated': paginator.pages > 1,
            'results_per_page': paginate_by,
            'has_next': paginator.has_next_page(page_number - 1),
            'has_previous': paginator.has_previous_page(page_number - 1),
            'page': page_number,
            'next': page_number + 1,
            'previous': page_number - 1,
            'last_on_page': paginator.last_on_page(page_number - 1),
            'first_on_page': paginator.first_on_page(page_number - 1),
            'pages': paginator.pages,
            'hits' : paginator.hits,
            'page_range' : paginator.page_range
        }, context_processors)
    else:
        c = RequestContext(request, {
            '%s_list' % template_object_name: queryset,
            'is_paginated': False
        }, context_processors)
        if not allow_empty and len(queryset) == 0:
            raise Http404
    for key, value in extra_context.items():
        if callable(value):
            c[key] = value()
        else:
            c[key] = value
    if not template_name:
        model = queryset.model
        template_name = "%s/%s_list.html" % (model._meta.app_label, model._meta.object_name.lower())
    t = template_loader.get_template(template_name)
    return HttpResponse(t.render(c), mimetype=mimetype)
开发者ID:taylanpince,项目名称:orangeblog,代码行数:93,代码来源:list_detail.py

示例4: Paginator

# 需要导入模块: from django.core.paginator import ObjectPaginator [as 别名]
# 或者: from django.core.paginator.ObjectPaginator import last_on_page [as 别名]
class Paginator(object):
    """
    Much like Django's ``ObjectPaginator`` (which it uses), but always
    represents a specific current page instead of just providing an interface
    to the data. Based on the active page it makes a number of properties
    available which mostly work exactly like the context that the
    ``object_list`` generic view provides.

    ``__init__`` takes the same arguments as ``ObjectPaginator``, plus an
    additional parameter ``page`` to initialize the active page number. It does
    not need to be an int, i.e. it can come directly from ``request.GET``; if
    conversion to an integer fails, a ``Http404`` exception is raised.
    
    You can also later assign to to ``page`` attribute.
    
    >>> items = range(1,6789)
    >>> paginator = Paginator(items, num_per_page=10, page=3)
    >>> paginator.items
    [21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
    >>> paginator.is_paginated
    True
    >>> paginator.results_per_page
    10
    >>> paginator.has_next
    True
    >>> paginator.has_previous
    True
    >>> paginator.page
    3
    >>> paginator.page0
    2
    >>> paginator.next
    4
    >>> paginator.previous
    2
    >>> paginator.last_on_page
    30
    >>> paginator.first_on_page
    21
    >>> paginator.pages
    679
    >>> paginator.hits
    6788
    """
    def __init__(self, *args, **kwargs):
        page = kwargs.pop('page', 1)
        self._paginator = DjangoPaginator(*args, **kwargs)
        
        # Resolve the page number; this is similar to what the Django
        # ``object_list`` generic view is doing.
        try:
            self.page = int(page)
        except ValueError:
            if page == 'last': self.page = self._paginator.pages
            else: raise Http404
        
    def _set_page(self, new_page):
        self.__page = new_page
        try:
            self.object_list = self._paginator.get_page(new_page-1)
        except InvalidPage:
            if new_page != -1: raise Http404
            else: self.object_list = []   # allow empty
        self.items = self.object_list # alias
        # update all exposed info for the new page number
        self.update_attrs()
    def _get_page(self): return self.__page
    page = property(_get_page, _set_page)

    def update_attrs(self):
        """Override in descendants to set custom fields."""
        self.page0 = self.page-1
        self.is_paginated = self._paginator.pages > 1
        self.results_per_page = self._paginator.num_per_page
        self.has_next = self._paginator.has_next_page(self.page-1)
        self.has_previous = self._paginator.has_previous_page(self.page-1)
        self.next = self.page+1
        self.previous = self.page-1
        self.last_on_page = self._paginator.last_on_page(self.page-1)
        self.first_on_page = self._paginator.first_on_page(self.page-1)
        self.pages = self._paginator.pages
        self.hits = self._paginator.hits
        self.page_range = self._paginator.page_range
开发者ID:gmacgregor,项目名称:rewinder,代码行数:85,代码来源:stateful_paginator.py


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