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

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

        if self.only_active_language:
            entries = entries.filter(language=get_language())

        entries = entries.transform(entry_list_lookup_related)

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

        else:
            self.entries = entries
    def process(self, request, **kwargs):
        if self.featured_only:
            entries = Entry.objects.featured()
        else:
            entries = Entry.objects.active()

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

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

        entries = entries.transform(entry_list_lookup_related)

        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 #3
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 #4
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
    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
Example #6
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
Example #7
0
    def get_context_data(self, **kwargs):
        kwargs['entity'] = self.entity._meta.verbose_name

        items = self.process_filter()

        paginator = Paginator(items, 10)
        page = self.request.GET.get('page')
        try:
            found = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            found = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results
            found = paginator.page(paginator.num_pages)

        kwargs.update({'found': found})
        kwargs.update(self.extra_content())
        return super(InformationIndex, self).get_context_data(**kwargs)