def test_paginate(self): # first page req = RequestFactory().get('/') page = infinite_paginator.paginate(req, self.queryset, per_page=15, lookup_field="pk") page_last_pk = list(self.queryset[:15])[-1].pk self.assertEqual(page.next_page_pk(), page_last_pk) # second page page_last_pk = list(self.queryset[:15])[-1].pk req = RequestFactory().get('/?id=%s' % page_last_pk) page = infinite_paginator.paginate(req, self.queryset, per_page=15, lookup_field="pk", page_var='id') second_page_last_pk = list(self.queryset[15:30])[-1].pk self.assertEqual(page.next_page_pk(), second_page_last_pk) # invalid (id) page last_pk = self.queryset.order_by("pk").last().pk req = RequestFactory().get('/?id=%s' % (last_pk + 1)) self.assertRaises(Http404, infinite_paginator.paginate, req, self.queryset, per_page=15, lookup_field="pk", page_var='id') # empty page valid_pk = self.queryset.last().pk req = RequestFactory().get('/?id=%s' % valid_pk) self.assertRaises(Http404, infinite_paginator.paginate, req, self.queryset.none(), per_page=15, lookup_field="pk", page_var='id') # empty first page req = RequestFactory().get('/') page = infinite_paginator.paginate(req, self.queryset.none(), per_page=15, lookup_field="pk") self.assertEqual(len(page), 0)
def notification_list_unread(request): notifications = TopicNotification.objects.for_access(request.user)\ .filter(is_read=False) page = paginate(request, query_set=notifications, lookup_field="date", page_var='notif', per_page=settings.ST_NOTIFICATIONS_PER_PAGE) next_page_pk = None if page: next_page_pk = page[-1].pk return render(request, 'foro/topic_notification/list_unread.html', {'page': page, 'next_page_pk': next_page_pk})
def topic_unread_list(request): # TODO: add button to clean up read topics? or read all? # redirect to first page if empty topics = Topic.objects.for_access(request.user)\ .filter(topicunread__user=request.user, topicunread__is_read=False) page = paginate(request, query_set=topics, lookup_field="last_active", page_var='topic_id') next_page_pk = None if page: next_page_pk = page[-1].pk return render(request, 'foro/topic_unread/list.html', {'page': page, 'next_page_pk': next_page_pk})
def notification_list_unread(request): notifications = TopicNotification.objects.for_access(request.user)\ .filter(is_read=False) page = paginate(request, query_set=notifications, lookup_field="date", page_var='notif', per_page=settings.ST_NOTIFICATIONS_PER_PAGE) next_page_pk = None if page: next_page_pk = page[-1].pk return render(request, 'foro/topic_notification/list_unread.html', { 'page': page, 'next_page_pk': next_page_pk })
def topic_unread_list(request): # TODO: add button to clean up read topics? or read all? # redirect to first page if empty topics = Topic.objects.for_access(request.user)\ .filter(topicunread__user=request.user, topicunread__is_read=False) page = paginate(request, query_set=topics, lookup_field="last_active", page_var='topic_id') next_page_pk = None if page: next_page_pk = page[-1].pk return render(request, 'foro/topic_unread/list.html', { 'page': page, 'next_page_pk': next_page_pk })