Example #1
0
    def process(self, request, **kwargs):
        if self.featured_only:
            entries = Entry.objects.featured().transform(
                entry_list_lookup_related)
        else:
            entries = Entry.objects.active().transform(
                entry_list_lookup_related)

        if self.category:
            entries = entries.filter(categories=self.category)

        if self.only_active_language:
            entries = entries.filter(
                language__istartswith=short_language_code())

        if self.paginate_by:
            paginator = Paginator(entries, self.paginate_by)
            page = request.GET.get('page', 1)
            try:
                self.entries = paginator.page(page).object_list
            except PageNotAnInteger:
                self.entries = paginator.page(1).object_list
            except EmptyPage:
                self.entries = paginator.page(paginator.num_pages).object_list

        else:
            self.entries = entries
Example #2
0
    def get_context_data(self, object_list=None, **kwargs):
        """
        Adds ``object_list`` to the context, and ``page`` and ``paginator``
        as well if paginating.
        """
        context = super(ListView,
                        self).get_context_data(object_list=object_list,
                                               **kwargs)

        if object_list is not None:
            paginate_by = self.get_paginate_by(object_list)
            if paginate_by:
                paginator = Paginator(object_list, paginate_by)

                try:
                    page = int(self.request.GET.get('page'))
                except (TypeError, ValueError):
                    page = 1
                try:
                    page = paginator.page(page)
                except (EmptyPage, InvalidPage):
                    page = paginator.page(paginator.num_pages)

                context.update({
                    'object_list': page.object_list,
                    'page': page,
                    'paginator': paginator,
                })

        return context
Example #3
0
    def process(self, request, **kwargs):
        entries = Entry.objects.active().transform(entry_list_lookup_related)

        if self.category:
            entries = entries.filter(categories=self.category)

        if self.paginate_by:
            paginator = Paginator(entries, self.paginate_by)
            page = request.GET.get('page', 1)
            try:
                self.entries = paginator.page(page).object_list
            except PageNotAnInteger:
                self.entries = paginator.page(1).object_list
            except EmptyPage:
                self.entries = paginator.page(paginator.num_pages).object_list

        else:
            self.entries = entries