Python django.core.paginator.EmptyPage() Examples

The following are 30 code examples for showing how to use django.core.paginator.EmptyPage(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module django.core.paginator , or try the search function .

Example 1
Project: ran-django-template   Author: nature1995   File: views.py    License: GNU General Public License v3.0 7 votes vote down vote up
def search_category(request, id):
    posts = Article.objects.filter(category_id=str(id))
    category = categories.get(id=str(id))
    paginator = Paginator(posts, settings.PAGE_NUM)  # 每页显示数量
    try:
        page = request.GET.get('page')  # 获取URL中page参数的值
        post_list = paginator.page(page)
    except PageNotAnInteger:
        post_list = paginator.page(1)
    except EmptyPage:
        post_list = paginator.page(paginator.num_pages)
    return render(request, 'category.html',
                  {'post_list': post_list,
                   'category_list': categories,
                   'category': category,
                   'months': months
                  }
    ) 
Example 2
Project: polls-api   Author: apiaryio   File: resource.py    License: MIT License 6 votes vote down vote up
def get_relations(self):
        paginator = self.get_paginator()

        try:
            page = paginator.page(int(self.request.GET.get('page', 1)))
        except EmptyPage:
            raise Http404()

        objects = page.object_list
        relations = {
            self.relation: self.get_resources(page)
        }

        relations['first'] = self.__class__()

        if page.has_next():
            relations['next'] = self.__class__(page.next_page_number())

        if page.has_previous():
            relations['prev'] = self.__class__(page.previous_page_number())

        if page.has_other_pages():
            relations['last'] = self.__class__(paginator.num_pages)

        return relations 
Example 3
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
def discussion_index(request, course_slug):
    """
    Index page to view all discussion topics
    """
    course, view = _get_course_and_view(request, course_slug)
    if view is None:
        # course is an HttpResponse in this case
        return course
    topics = DiscussionTopic.objects.filter(offering=course).order_by('-pinned', '-last_activity_at')
    activity.update_last_viewed(_get_member(request.user.username, view, course_slug))
    paginator = Paginator(topics, 10)
    try:
        page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1
    try:
        topics = paginator.page(page)
    except (EmptyPage, InvalidPage):
        topics = paginator.page(paginator.num_pages)
    context = {'course': course, 'topics': topics, 'view': view, 'paginator': paginator, 'page': page}
    return render(request, 'discuss/index.html', context) 
Example 4
Project: WF-website   Author: WesternFriend   File: models.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def get_paginated_archive_issues(self, archive_issues, request):
        items_per_page = 9

        paginator = Paginator(archive_issues, items_per_page)

        archive_issues_page = request.GET.get("page")

        try:
            paginated_archive_issues = paginator.page(archive_issues_page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            paginated_archive_issues = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            paginated_archive_issues = paginator.page(paginator.num_pages)

        return paginated_archive_issues 
Example 5
Project: WF-website   Author: WesternFriend   File: models.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def get_paginated_memorials(self, filtered_memorials, request):
        items_per_page = 10

        paginator = Paginator(filtered_memorials, items_per_page)

        memorials_page = request.GET.get("page")

        try:
            paginated_memorials = paginator.page(memorials_page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            paginated_memorials = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            paginated_memorials = paginator.page(paginator.num_pages)

        return paginated_memorials 
Example 6
Project: WF-website   Author: WesternFriend   File: models.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def get_context(self, request, *args, **kwargs):
        context = super().get_context(request)

        upcoming_events = Event.objects.all().filter(
            Q(date__gt=date.today())).order_by('date')

        # Show three archive issues per page
        paginator = Paginator(upcoming_events, 3)

        upcoming_events_page = request.GET.get("page")

        try:
            paginated_events = paginator.page(upcoming_events_page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            paginated_events = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            paginated_events = paginator.page(paginator.num_pages)

        context["events"] = paginated_events

        return context 
Example 7
Project: ran-django-template   Author: nature1995   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
def search_tag(request, tag):
    posts = Article.objects.filter(tags__name__contains=tag)
    paginator = Paginator(posts, settings.PAGE_NUM)  # 每页显示数量
    try:
        page = request.GET.get('page')  # 获取URL中page参数的值
        post_list = paginator.page(page)
    except PageNotAnInteger:
        post_list = paginator.page(1)
    except EmptyPage:
        post_list = paginator.page(paginator.num_pages)
    return render(request, 'tag.html', {
        'post_list': post_list,
        'category_list': categories,
        'tag': tag,
        'months': months
        }
    ) 
Example 8
Project: ran-django-template   Author: nature1995   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
def archives(request, year, month):
    posts = Article.objects.filter(pub_time__year=year, pub_time__month=month).order_by('-pub_time')
    paginator = Paginator(posts, settings.PAGE_NUM)  # 每页显示数量
    try:
        page = request.GET.get('page')  # 获取URL中page参数的值
        post_list = paginator.page(page)
    except PageNotAnInteger:
        post_list = paginator.page(1)
    except EmptyPage:
        post_list = paginator.page(paginator.num_pages)
    return render(request, 'archive.html', {
        'post_list': post_list,
        'category_list': categories,
        'months': months,
        'year_month': year+'.'+month
        }
    ) 
Example 9
Project: aswan   Author: momosecurity   File: generic.py    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
def validate_number(self, number):
        """
        Validates the given 1-based page number.
        """
        try:
            number = int(number)
        except (TypeError, ValueError):
            raise PageNotAnInteger('That page number is not an integer')
        if number < 1:
            raise EmptyPage('That page number is less than 1')
        if number > self.num_pages:
            if number == 1 and self.allow_empty_first_page:
                pass
            else:
                number = self.num_pages
        return number 
Example 10
Project: FIR   Author: certsocietegenerale   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
def dashboard(request):
    bls = BusinessLine.authorization.for_user(request.user, 'incidents.view_incidents')
    bl_filter = Q(business_line__in=bls) | Q(business_line__isnull=True)
    todos = TodoItem.objects.filter(incident__isnull=False, done=False).filter(bl_filter)
    todos = todos.select_related('incident', 'category')
    todos = todos.order_by('-incident__date')

    page = request.GET.get('page', 1)
    todos_per_page = request.user.profile.incident_number
    p = Paginator(todos, todos_per_page)

    try:
        todos = p.page(page)
    except (PageNotAnInteger, EmptyPage):
        todos = p.page(1)

    return render(request, 'fir_todos/dashboard.html', {'todos': todos}) 
Example 11
Project: dj-diabetes   Author: push-things   File: tools.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def page_it(data, record_per_page, page=''):
    """
        return the data of the current page
    """
    paginator = Paginator(data, record_per_page)
    try:
        data = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        data = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999),
        # deliver last page of results.
        data = paginator.page(paginator.num_pages)

    return data 
Example 12
Project: dart   Author: lmco   File: views.py    License: Apache License 2.0 6 votes vote down vote up
def get_context_data(self, **kwargs):
        logger.debug('GET: ListMissionView')
        context = super(ListMissionView, self).get_context_data(**kwargs)
        missions = Mission.objects.all()
        paginator = Paginator(missions, 10)
        page = self.request.GET.get('page')
        try:
            show_missions = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            show_missions = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            show_missions = paginator.page(paginator.num_pages)
        context['missions'] = show_missions
        return context 
Example 13
Project: dart   Author: lmco   File: views.py    License: Apache License 2.0 6 votes vote down vote up
def get_context_data(self, **kwargs):
        context = super(ListMissionTestsSupportingDataView, self).get_context_data(**kwargs)
        testdata = self.get_queryset()
        paginator = Paginator(testdata, 10)
        page = self.request.GET.get('page')
        try:
            show_data = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            show_data = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            show_data = paginator.page(paginator.num_pages)
        context['show_data'] = show_data
        context['this_mission'] = Mission.objects.get(id=self.kwargs['mission'])
        context['this_test'] = TestDetail.objects.get(id=self.kwargs['test_detail'])
        return context 
Example 14
Project: monasca-ui   Author: openstack   File: views.py    License: Apache License 2.0 6 votes vote down vote up
def get_data(self):
        page_offset = self.request.GET.get('page_offset')
        results = []
        if page_offset is None:
            page_offset = 0
        limit = utils.get_page_size(self.request)
        try:
            results = api.monitor.alarmdef_list(self.request, page_offset, limit)
            paginator = Paginator(results, limit)
            results = paginator.page(1)
        except EmptyPage:
            results = paginator.page(paginator.num_pages)
        except Exception as ex:
            LOG.exception(str(ex))
            messages.error(self.request, _("Could not retrieve alarm definitions"))

        return results 
Example 15
Project: kboard   Author: kboard   File: views.py    License: MIT License 6 votes vote down vote up
def comment_list(request, post_id):
    post = Post.objects.get(id=post_id)
    comments_all_list = Comment.objects.filter(post=post, is_deleted=False).order_by('-id')

    paginator = Paginator(comments_all_list, post.board.comments_chunk_size)
    page = request.GET.get('page')

    try:
        comments = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        comments = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        comments = paginator.page(paginator.num_pages)

    pages_nav_info = get_pages_nav_info(comments, nav_chunk_size=post.board.comment_pages_nav_chunk_size)

    return render(request, 'comment_list.html', {
        'post': post,
        'comments': comments,
        'pages_nav_info': pages_nav_info
    }) 
Example 16
Project: BikeMaps   Author: SPARLab   File: index.py    License: MIT License 6 votes vote down vote up
def index(request):
	POSTS_PER_PAGE = 5
	
	if request.user.is_superuser:
		post_list = Post.objects.all().order_by('-post_date')
	else:
		#post_list = Post.objects.filter(published=True).order_by('-post_date')
		post_list = get_Posts_By_Language_Code(request.LANGUAGE_CODE)

	paginator = Paginator(post_list, POSTS_PER_PAGE)

	page = request.GET.get('page')
	try:
		posts = paginator.page(page)
	except PageNotAnInteger:
		# If page is not an integer, deliver first page.
		posts = paginator.page(1)
	except EmptyPage:
		# If page is out of range, deliver last page of results.
		posts = paginator.page(paginator.num_pages)

	return render(request, 'blogApp/index.html', {'posts': posts}) 
Example 17
Project: BioQueue   Author: liyao001   File: views.py    License: Apache License 2.0 6 votes vote down vote up
def query_job(request):
    if request.user.is_superuser:
        job_list = Queue.objects.order_by('-create_time').all()
    else:
        job_list = Queue.objects.filter(user_id=request.user.id).order_by('-create_time').all()
    paginator = Paginator(job_list, 12)

    page = request.GET.get('page')
    '''
    try:
        jobs = paginator.page(page)
    except PageNotAnInteger:
        jobs = paginator.page(1)
    except EmptyPage:
        jobs = paginator.page(paginator.num_pages)
    '''
    jobs = page_info(paginator, page)
    dt, du, dp = get_disk_quota_info(request.user.id)
    return render(request, 'ui/query_job.html', {'job_list': jobs, 't_disk': dt, 'u_disk': du, 'disk_per': dp}) 
Example 18
Project: civet   Author: idaholab   File: views.py    License: Apache License 2.0 6 votes vote down vote up
def get_paginated(request, obj_list, obj_per_page=30):
    limit = request.GET.get('limit')
    if limit:
        obj_per_page = min(int(limit), 500)

    paginator = Paginator(obj_list, obj_per_page)

    page = request.GET.get('page')
    try:
        objs = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        objs = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        objs = paginator.page(paginator.num_pages)
    objs.limit = obj_per_page
    copy_get = request.GET.copy()
    if copy_get.get('page'):
        del copy_get['page']
    copy_get['limit'] = obj_per_page
    objs.get_params = copy_get.urlencode()
    return objs 
Example 19
Project: tramcar   Author: tramcar   File: companies.py    License: MIT License 6 votes vote down vote up
def companies_index(request):
    companies_list = Company.objects \
                            .filter(site_id=get_current_site(request).id)

    for c in companies_list:
        if len(c.paid_jobs()) == 0:
            companies_list = companies_list.exclude(id=c.id)

    paginator = Paginator(companies_list, 25)
    page = request.GET.get('page')
    meta_desc = 'Browse an extensive list of companies with active and ' \
                'expired jobs'
    title = 'Companies'
    try:
        companies = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        companies = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        companies = paginator.page(paginator.num_pages)
    context = {'meta_desc': meta_desc, 'title': title, 'companies': companies}
    return render(request, 'job_board/companies_index.html', context) 
Example 20
Project: tramcar   Author: tramcar   File: jobs.py    License: MIT License 6 votes vote down vote up
def jobs_mine(request):
    jobs_list = Job.objects.filter(site_id=get_current_site(request).id) \
                           .filter(user_id=request.user.id) \
                           .order_by('-created_at')
    paginator = Paginator(jobs_list, 25)
    page = request.GET.get('page')
    title = 'My Jobs'
    try:
        jobs = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        jobs = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        jobs = paginator.page(paginator.num_pages)
    context = {'jobs': jobs, 'title': title}
    return render(request, 'job_board/jobs_mine.html', context) 
Example 21
Project: CATEd   Author: OnGridSystems   File: views.py    License: MIT License 6 votes vote down vote up
def index(request):
    transaction = Transaction.objects.all().order_by('-date')
    if len(transaction) > 0:
        paginator = Paginator(transaction, 100)
        page = request.GET.get('page')
        try:
            transactions = paginator.page(page)
        except PageNotAnInteger:
            transactions = paginator.page(1)
        except EmptyPage:
            transactions = paginator.page(paginator.num_pages)
    else:
        transactions = None
    args = {'exchange_form': UserExchangesForm(),
            'wallet_form': UserWalletForm(),
            'ue': UserExchange.objects.all(),
            'uw': UserWallet.objects.all(),
            'trans': transactions}
    return render(request, 'trade/home.html', args) 
Example 22
Project: palanaeum   Author: Palanaeum   File: admin_views.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def users_list(request):
    only_staff = request.GET.get('only_staff', False)
    if only_staff:
        users = User.objects.filter(is_staff=True)
    else:
        users = User.objects.all()

    users = users.order_by('username')

    paginator = Paginator(users, 50, 10)
    try:
        page = paginator.page(request.GET.get('page', 0))
    except PageNotAnInteger:
        page = paginator.page(1)
    except EmptyPage:
        page = paginator.page(paginator.num_pages)

    to_show = page_numbers_to_show(paginator, page.number)

    return render(request, 'palanaeum/admin/users_list.html', {'page': page,
                                                               'page_numbers_to_show': to_show}) 
Example 23
Project: palanaeum   Author: Palanaeum   File: search.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def paginate_search_results(request, search_results: list) -> tuple:
    """
    Preload a page of search results. Return loaded entries, paginator object and page object.
    """
    page_length = UserSettings.get_page_length(request)
    paginator = Paginator(search_results, page_length, orphans=page_length // 10)

    page_num = request.GET.get('page', '1')

    try:
        page = paginator.page(page_num)
    except PageNotAnInteger:
        page = paginator.page(1)
    except EmptyPage:
        page = paginator.page(paginator.num_pages)

    entries_ids = [entry[0] for entry in page]
    entries_map = Entry.prefetch_entries(entries_ids)

    entries = [(entries_map[entry_id], rank) for entry_id, rank in page]

    return entries, paginator, page 
Example 24
Project: mangaki   Author: mangaki   File: views.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def fix_index(request):
    suggestion_list = Suggestion.objects.select_related('work', 'user').prefetch_related(
        'work__category', 'evidence_set__user').annotate(
            count_agrees=Count(Case(When(evidence__agrees=True, then=1))),
            count_disagrees=Count(Case(When(evidence__agrees=False, then=1)))
        ).all().order_by('is_checked', '-date')

    paginator = Paginator(suggestion_list, FIXES_PER_PAGE)
    page = request.GET.get('page')

    try:
        suggestions = paginator.page(page)
    except PageNotAnInteger:
        suggestions = paginator.page(1)
    except EmptyPage:
        suggestions = paginator.page(paginator.num_pages)

    context = {
        'suggestions': suggestions
    }

    return render(request, 'fix/fix_index.html', context) 
Example 25
Project: osler   Author: SaturdayNeighborhoodHealthClinic   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
def clinic_date_list(request):

    qs = models.ClinicDate.objects.prefetch_related(
        'workup_set',
        'clinic_type',
        'workup_set__attending',
        'workup_set__signer',
    )

    paginator = Paginator(qs, per_page=10)
    page = request.GET.get('page')

    try:
        clinic_days = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        clinic_days = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        clinic_days = paginator.page(paginator.num_pages)

    return render(request, 'workup/clindate-list.html',
                  {'object_list': clinic_days,
                   'page_range': paginator.page_range}) 
Example 26
Project: Collaboration-System   Author: fresearchgroup   File: views.py    License: GNU General Public License v2.0 6 votes vote down vote up
def feed_content(request, pk):
	grpfeeds = ''
	try:
		group = Group.objects.get(pk=pk)
		uid = request.user.id
		membership = GroupMembership.objects.get(user=uid, group=group.pk)
		if membership:
			gfeeds = group.target_actions.all()
			page = request.GET.get('page', 1)
			paginator = Paginator(list(gfeeds), 10)
			try:
				grpfeeds = paginator.page(page)
			except PageNotAnInteger:
				grpfeeds = paginator.page(1)
			except EmptyPage:
				grpfeeds = paginator.page(paginator.num_pages)

	except GroupMembership.DoesNotExist:
		return redirect('group_view', group.pk)
	return render(request, 'groupfeed.html', {'group': group, 'membership':membership, 'grpfeeds':grpfeeds}) 
Example 27
Project: Servo   Author: fpsw   File: utils.py    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
def paginate(queryset, page, count=10):
    """
    Shortcut for paginating a queryset
    """
    paginator = Paginator(queryset, count)

    try:
        results = paginator.page(page)
    except PageNotAnInteger:
        results = paginator.page(1)
    except EmptyPage:
        results = paginator.page(paginator.num_pages)

    return results 
Example 28
Project: open-synthesis   Author: twschiller   File: util.py    License: GNU General Public License v3.0 5 votes vote down vote up
def make_paginator(request, object_list, per_page=10, orphans=3):
    """Return a paginator for object_list from request."""
    paginator = Paginator(object_list, per_page=per_page, orphans=orphans)
    page = request.GET.get('page')
    try:
        objects = paginator.page(page)
    except PageNotAnInteger:
        # if page is not an integer, deliver first page.
        objects = paginator.page(1)
    except EmptyPage:
        # if page is out of range (e.g. 9999), deliver last page of results.
        objects = paginator.page(paginator.num_pages)
    return objects 
Example 29
Project: WF-website   Author: WesternFriend   File: models.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def get_context(self, request, *args, **kwargs):
        context = super().get_context(request)

        # number of days for archive threshold
        archive_days_ago = 180

        # TODO: see if there is a better way to deal with
        # irregular month lengths for archive threshold
        archive_threshold = datetime.date.today() - timedelta(days=archive_days_ago)

        published_issues = MagazineIssue.objects.live().order_by("-publication_date")

        # recent issues are published after the archive threshold
        context["recent_issues"] = published_issues.filter(
            publication_date__gte=archive_threshold
        )

        archive_issues = published_issues.filter(publication_date__lt=archive_threshold)

        # Show three archive issues per page
        paginator = Paginator(archive_issues, 3)

        archive_issues_page = request.GET.get("archive-issues-page")

        try:
            paginated_archive_issues = paginator.page(archive_issues_page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            paginated_archive_issues = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            paginated_archive_issues = paginator.page(paginator.num_pages)

        # archive issues are published before the archive threshold
        context["archive_issues"] = paginated_archive_issues

        return context 
Example 30
Project: WF-website   Author: WesternFriend   File: views.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def search(request):
    search_query = request.GET.get('query', None)
    page = request.GET.get('page', 1)

    # Search
    if search_query:
        search_results = Page.objects.live().search(search_query)
        query = Query.get(search_query)

        # Record hit
        query.add_hit()
    else:
        search_results = Page.objects.none()

    # Pagination
    paginator = Paginator(search_results, 10)
    try:
        search_results = paginator.page(page)
    except PageNotAnInteger:
        search_results = paginator.page(1)
    except EmptyPage:
        search_results = paginator.page(paginator.num_pages)

    return render(request, 'search/search.html', {
        'search_query': search_query,
        'search_results': search_results,
    })