def trending(request): sections = Section.objects.all() post_num = Post.objects.count() user_num = User.objects.filter(is_active=True).count() user_extend = None if request.user.is_authenticated(): user_extend = UserExtend.objects.get(user=request.user) query = Post.objects.exclude(status__exact='t').order_by('-comment_count') page = request.GET.get('page', 1) paginator = Paginator(query, 20, body=5) try: trending = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. trending = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. trending = paginator.page(paginator.num_pages) return render( request, 'main/trending_list.html', { 'trending': trending, 'sections': sections, 'post_num': post_num, 'user_num': user_num, 'user_extend': user_extend, }, )
def record(request, memberpid, pageno): try: q = member.objects.get(pid=memberpid) except member.DoesNotExist: raise Http404("Member does not exist.") qs = basehansard.objects.filter( pid=memberpid).order_by('-speechdate').all() paginator = DiggPaginator(qs, 5, body=5, tail=2, padding=2) thedate = datetime.datetime.now().date() baseurl = "/members/record/" + memberpid + '/' ridings = constituency.objects.filter( pid=memberpid).order_by('startdate').distinct( ) # this handles duplicates (for now) which need to be culled properly ridings_reverse = constituency.objects.filter( pid=memberpid).order_by('-startdate').all() try: lastparty = ridings_reverse[0].partyid except: lastparty = party.objects.get(partyid=31) try: lastconstituency = ridings_reverse[0] except: lastconstituency = None return render_to_response( 'members/member.html', { 'member': q, 'latest': qs, 'ridings': ridings, 'lastparty': lastparty, 'baseurl': baseurl, 'paginator': paginator, 'page': paginator.page(pageno), 'pageno': pageno, 'lastconstituency': lastconstituency })
def myPinnedPost(request): sections = Section.objects.all() post_num = Post.objects.count() user_num = User.objects.filter(is_active=True).count() user_extend = None if request.user.is_authenticated(): user_extend = UserExtend.objects.get(user=request.user) query = user_extend.pin_post.all() page = request.GET.get('page', 1) paginator = Paginator(query, 20, body=5) try: pin_post_list = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. pin_post_list = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. pin_post_list = paginator.page(paginator.num_pages) return render( request, 'main/myPinnedPost.html', { 'pin_post_list': pin_post_list, 'sections': sections, 'post_num': post_num, 'user_num': user_num, 'user_extend': user_extend, 'today': datetime.datetime.now(), }, )
def index(request): keyword = request.GET.get('kw') wanted_tag = u'求购' if keyword: post_list = Post.objects.filter(title__contains=keyword).order_by('-last_updated_at') wanted_post_list = Post.objects.filter(title__contains=keyword, tag=wanted_tag).order_by('-last_updated_at') else: post_list = Post.objects.all().order_by('-last_updated_at') wanted_post_list = Post.objects.filter(tag=wanted_tag).order_by('-last_updated_at') paginator = DiggPaginator(post_list, 17, body=5) # Show 17 posts per page wanted_paginator = DiggPaginator(wanted_post_list, 17, body=5) # Show 17 posts per page page = request.GET.get('page') wpage = request.GET.get('wpage') try: if not page: posts = paginator.page(1) else: posts = paginator.page(page) if not wpage: wanted_posts = wanted_paginator.page(1) else: wanted_posts = wanted_paginator.page(wpage) except PageNotAnInteger: # If page is not an integer, deliver first page. posts = paginator.page(1) wanted_posts = wanted_paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. posts = paginator.page(paginator.num_pages) wanted_posts = wanted_paginator.page(wanted_paginator.num_pages) return render_to_response('listing/index.html', {"posts": posts, "wanted_posts": wanted_posts}, context_instance=get_common_context(request))
def MyMention(request): sections = Section.objects.all() post_num = Post.objects.count() user_num = User.objects.filter(is_active=True).count() user_extend = None if request.GET.has_key('search'): form = SearchForm(request.GET) else: return render( request, 'main/my_mention.html', { 'sections': sections, 'post_num': post_num, 'user_num': user_num, 'err': 'error' }, ) if form.is_valid(): user_extend = form.cleaned_data['search'] query = Comment.objects.exclude(post__status='t').filter( \ Q(this_comment_quote__comment_by__user__username__iexact=user_extend) | \ Q(comment_made__icontains=user_extend) ).order_by('-id') page = request.GET.get('page', 1) paginator = Paginator(query, 20, body=5) try: allcomment = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. allcomment = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. allcomment = paginator.page(paginator.num_pages) return render( request, 'main/my_mention.html', { 'allcomment': allcomment, 'sections': sections, 'post_num': post_num, 'user_num': user_num, 'post_owner': user_extend, }, ) else: return render( request, 'main/my_mention.html', { 'sections': sections, 'post_num': post_num, 'user_num': user_num, }, )
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) digg_paginator = DiggPaginator( PaymentHistory.objects.filter( user=self.request.user).order_by('-date'), 10) page = self.request.GET.get('page') context.update({'data_with_paginate': digg_paginator.get_page(page)}) return context
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) premium_cache = PremiumCache.objects.filter( nick=self.request.user.steamid32).order_by('-pk') digg_paginator = DiggPaginator(premium_cache, 10) page = self.request.GET.get('page') context.update({ 'data_with_paginate': digg_paginator.get_page(page), }) return context
def popular(request, slug): slug = slug.strip() sections = Section.objects.all() post_num = Post.objects.count() user_num = User.objects.filter(is_active=True).count() user_extend = None try: sec_query = Section.objects.get(name=slug) except Section.DoesNotExist: return render( request, 'main/popular_section.html', { 'sections': sections, 'post_num': post_num, 'user_num': user_num, 'err': 'error' }, ) if request.user.is_authenticated(): user_extend = UserExtend.objects.get(user=request.user) if sec_query: query = sec_query.post_set.exclude( status__exact='t').order_by('-comment_count') page = request.GET.get('page', 1) paginator = Paginator(query, 20, body=5) try: section = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. section = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. section = paginator.page(paginator.num_pages) return render( request, 'main/popular_section.html', { 'section_name': sec_query, 'section_list': section, 'sections': sections, 'post_num': post_num, 'user_num': user_num, 'user_extend': user_extend, }, )
def allMyComment(request, slug): slug = slug.strip() sections = Section.objects.all() post_num = Post.objects.count() user_num = User.objects.filter(is_active=True).count() user_extend = None try: queryu = User.objects.get(username=slug) except User.DoesNotExist: return render( request, 'main/allmycomment.html', context={ 'sections': sections, 'post_num': post_num, 'user_num': user_num, }, ) if request.user.is_authenticated(): user_extend = UserExtend.objects.get(user=request.user) query = Comment.objects.exclude(post__status='t').filter( comment_by__user=queryu).order_by('-id') page = request.GET.get('page', 1) paginator = Paginator(query, 20, body=5) try: allcomment = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. allcomment = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. allcomment = paginator.page(paginator.num_pages) return render( request, 'main/allmycomment.html', { 'allcomment': allcomment, 'sections': sections, 'post_num': post_num, 'user_num': user_num, 'user_extend': user_extend, 'post_owner': queryu, }, )
def get_context_data(self, **kwargs): context = super(LeaveRequestListView, self).get_context_data(**kwargs) profile = self.request.user.profile # leave_type_list = LeaveType.methods.get_for_user(profile) leave_type_list = LeaveType.objects.user_types(user=self.request.user) type_list = [] for t in leave_type_list: t.no_of_days_left = t.count_no_of_days_left( profile=self.request.user.profile) type_list.append(t) additional_context = { 'leave_type_list': type_list, # leave_type_list, 'now': timezone.now(), 'category': self.category, 'paginator': DiggPaginator(self.get_queryset(), self.paginate_by, body=PGN['body'], tail=PGN['tail'], padding=PGN['padding']).page( self.kwargs.get('page', 1)) } context.update(additional_context) return context
def get(self, request): type = request.GET.get('cat') page = request.GET.get('page', 1) sort = request.GET.get('sort', "popular") toplist = apigrabber.getToplist(type, page, sort) # print(len(toplist)) paginator = DiggPaginator(toplist, 24, body=6) try: movies = DiggPaginator.page(paginator, number=page) except PageNotAnInteger: movies = DiggPaginator.page(paginator, number=1) except EmptyPage: movies = DiggPaginator.page(paginator, number=DiggPaginator.num_pages) return render(request, 'gui/toplist.html', {"posts": movies, "type": type, "page": int(page), "pagename": "Browse Top List"})
def get_context_data(self, **kwargs): context = super(OnLeaveReportView, self).get_context_data(**kwargs) additional_context = { 'form': OnLeaveReportForm(), 'show_form': True if self.kwargs.get('show_form') == 'on' else False, 'now': timezone.now(), 'page_message': self.page_message, 'paginator': DiggPaginator(self.get_queryset(), self.paginate_by, body=PGN['body'], tail=PGN['tail'], padding=PGN['padding']).page( self.kwargs.get('page', 1)) } context.update(additional_context) self.request.session['on_leave_list'] = context['object_list'] self.request.session['page_message'] = self.page_message return context
def get_context_data(self, **kwargs): context = super(NationalityListView, self).get_context_data(**kwargs) context['paginator'] = DiggPaginator(self.get_queryset(), self.paginate_by, body=PGN['body'], tail=PGN['tail'], padding=PGN['padding'] ).page(self.kwargs.get('page', 1)) return context
def hansard_view(request, year, month, day, pageno): y=int(year) m=int(month) d=int(day) dateobj = datetime.date(y,m,d) # qs = basehansard.objects.raw("select * from dilipadsite_basehansard where speechdate = %s order by basepk", [dateobj]) qs = basehansard.objects.filter(speechdate=dateobj).order_by('basepk') # need to add select_related to speed up rendering # but first basehansard needs foreignkeys to be added! qscount = len(qs) # use len() now so there's a cached verson for paginator ## this is horrible ## def items_count(): ## cursor = connection.cursor() ## cursor.execute("select count(*) from dilipadsite_basehansard where speechdate = %s", [dateobj]) ## row = cursor.fetchone() ## return row[0] paginator = DiggPaginator(qs, 20, body=5, tail=2, padding=2) paginator._count = qscount # items_count() datenavobject = datenav.objects.get(hansarddate=dateobj) storage = messages.get_messages(request) baseurl=("/full/"+str(year)+"/"+str(month)+"/"+str(day)+"/") if len(storage) == 0: try: context = {'year':year, 'baseurl':baseurl, 'month':month, 'day':day, 'hansard':qs[1], 'next':datenavobject.get_next_day_link(), 'paginator': paginator, 'page':paginator.page(pageno), 'pageno':pageno, 'previous':datenavobject.get_previous_day_link()} except InvalidPage: raise Http404("Page does not exist") else: refer_pk = None for m in storage: refer_pk = m.message break try: context = {'year':year, 'month':month, 'baseurl':baseurl, 'day':day, 'hansard':qs[1], 'next':datenavobject.get_next_day_link(), 'paginator': paginator, 'page':paginator.page(pageno), 'pageno':pageno, 'previous':datenavobject.get_previous_day_link(), 'refer_pk':refer_pk} except InvalidPage: raise Http404("Page does not exist") return render_to_response('full/hansard.html', context, context_instance=RequestContext(request))
def get_context_data(self, **kwargs): context = super(ReceivedEmployeeAppraisalMeasureView, self).get_context_data(**kwargs) reviewed = self.emp_appraisal.get_total_answered( reviewer=self.request.user.profile) total = self.emp_appraisal.measures.filter( reviewer=self.request.user.profile).count() # comments = self.emp_appraisal.flows.all() is_closed = False if self.emp_appraisal.is_complete is True: is_closed = True remarks = { 'open': { 'initiator': self.emp_appraisal.flows.order_by('id')[0].from_reviewer, 'date': self.emp_appraisal.flows.order_by('id')[0].created_at, 'comment': self.emp_appraisal.on_open_remarks }, 'close': { 'closed_by': self.emp_appraisal.flows.order_by('-id')[0].to_reviewer, 'date': self.emp_appraisal.closed_on, 'comment': self.emp_appraisal.on_close_remarks }, } extra_context = { 'remarks': remarks, 'is_closed': is_closed, 'emp_appraisal': self.emp_appraisal, 'total_measures_reviewed': reviewed, 'comments': self.emp_appraisal.flows.filter( comment__isnull=False).order_by('-id'), 'total_measures': total, 'self_score': self.emp_appraisal.get_average_rating( reviewer=self.emp_appraisal.employee_profile), 'adjusted_score': self.emp_appraisal.get_average_rating(), 'paginator': DiggPaginator(self.get_queryset(), self.paginate_by, body=PGN['body'], tail=PGN['tail'], padding=PGN['padding']).page( self.kwargs.get('page', 1)) } context.update(extra_context) return context
def build_page(self): try: page_no = int(self.request.GET.get('page', 1)) except (TypeError, ValueError): raise Http404("Not a valid number for page.") if page_no < 1: raise Http404("Pages should be 1 or greater.") paginator = DiggPaginator(self.results, 20, body=5, tail=2, padding=2) try: page = paginator.page(page_no) except InvalidPage: raise Http404("Problem with search results (no such page)!") return (paginator, page)
def get(self, request, filter_by='all'): """docstring Note: Do not include the `self` parameter in the ``Args`` section. Args: param1: The first parameter. param2: The second parameter. Returns: True if successful, False otherwise. """ # todo Finish docstring if not request.user.is_authenticated(): return render(request, 'music/auth/login.html') else: page = request.GET.get('page', 1) try: label_ids = [] labels = [] for label in Label.objects.all(): label_ids.append(label.pk) labels = Label.objects.filter(pk__in=label_ids) if filter_by == 'favorites': labels = labels.filter(fav=True) paginate_labels = Paginator(labels, 20, body=3, margin=1, tail=1) try: labels = paginate_labels.page(page) except PageNotAnInteger: labels = paginate_labels.page(1) except EmptyPage: labels = paginate_labels.page(paginate_labels.num_pages) except Label.DoesNotExist: labels = [] return render(request, 'music/label/labels.html', { 'label_list': labels, 'filter_by': filter_by, })
def get(self, request, filter_by='all'): """docstring Note: Do not include the `self` parameter in the ``Args`` section. Args: param1: The first parameter. param2: The second parameter. Returns: True if successful, False otherwise. """ # todo Finish docstring if not request.user.is_authenticated(): return render(request, 'music/auth/login.html') else: page = request.GET.get('page', 1) try: song_ids = [] for album in Album.objects.filter(user=request.user): for song in album.song_set.all(): song_ids.append(song.pk) user_songs = Song.objects.filter(pk__in=song_ids) if filter_by == 'favorites': user_songs = user_songs.filter(fav=True) paginate_songs = Paginator(user_songs, 20, body=3, margin=1, tail=1) try: user_songs = paginate_songs.page(page) except PageNotAnInteger: user_songs = paginate_songs.page(1) except EmptyPage: user_songs = paginate_songs.page(paginate_songs.num_pages) except Album.DoesNotExist: user_songs = [] return render(request, 'music/song/songs.html', { 'song_list': user_songs, 'filter_by': filter_by, })
def get_context_data(self, **kwargs): context = super(LeaveTypeListView, self).get_context_data(**kwargs) context['service_line_count'] = ServiceLine.objects.count() # context['position_count'] = Position.objects.count() context['paginator'] = DiggPaginator(self.get_queryset(), self.paginate_by, body=PGN['body'], tail=PGN['tail'], padding=PGN['padding']).page( self.kwargs.get('page', 1)) return context
def get_context_data(self, **kwargs): context = super(LeaveApplicationListView, self).get_context_data(**kwargs) context.update({ 'category': self.category, 'paginator': DiggPaginator(self.get_queryset(), self.paginate_by, body=PGN['body'], tail=PGN['tail'], padding=PGN['padding']).page( self.kwargs.get('page', 1)) }) return context
def record(request, memberpid, pageno): try: q = member.objects.get(pid=memberpid) except member.DoesNotExist: raise Http404("Member does not exist.") qs = basehansard.objects.filter(pid=memberpid).order_by('-speechdate').all() paginator = DiggPaginator(qs, 5, body=5, tail=2, padding=2) thedate = datetime.datetime.now().date() baseurl = "/members/record/"+memberpid+'/' ridings = constituency.objects.filter(pid=memberpid).order_by('startdate').distinct() # this handles duplicates (for now) which need to be culled properly ridings_reverse = constituency.objects.filter(pid=memberpid).order_by('-startdate').all() try: lastparty = ridings_reverse[0].partyid except: lastparty = party.objects.get(partyid=31) try: lastconstituency = ridings_reverse[0] except: lastconstituency = None return render_to_response('members/member.html', {'member':q, 'latest':qs, 'ridings':ridings, 'lastparty':lastparty, 'baseurl':baseurl,'paginator': paginator, 'page':paginator.page(pageno), 'pageno':pageno, 'lastconstituency':lastconstituency})
def get_context_data(self, **kwargs): Log(user=self.request.user, action='Reviewed user system activity.').save() context = super(ActivityListView, self).get_context_data(**kwargs) if self.request.session.get('activity_form'): context['form'] = self.request.session.get('activity_form') else: context['form'] = UserActivitySearchForm context['user_id'] = self.request.session.get('activity_user_id') context['start_date'] = self.request.session.get('activity_start_date') context['end_date'] = self.request.session.get('activity_end_date') context['paginator'] = DiggPaginator(self.get_queryset(), 20, body=10, tail=5, padding=3).page( self.kwargs.get('page', 1)) return context
def post(self, request, *args, **kwargs): form = OnLeaveReportForm(request.POST) if form.is_valid(): request.session['rpt_start_date'] = form.data['start_date'] request.session['rpt_end_date'] = form.data['end_date'] request.session['employee_profile'] = form.data['employee'] request.session['search'] = True return redirect('leave:leave_report_on_leave', search='on', show_form='on') else: context = { 'form': form, 'show_form': True if self.kwargs.get('show_form') == 'on' else \ False, 'now': timezone.now(), 'page_message': self.page_message, 'paginator': DiggPaginator(self.get_queryset(), self.paginate_by, body=PGN['body'], tail=PGN['tail'], padding=PGN['padding'] ).page(self.kwargs.get('page', 1)) } return render(self.request, self.template_name, context=context)
def home(request): keyword = request.GET.get('kw') if keyword: post_list = Post.objects.filter( title__contains=keyword).order_by('-last_updated_at') else: post_list = Post.objects.all().order_by('-last_updated_at') paginator = DiggPaginator(post_list, 17, body=5) # Show 17 posts per page page = request.GET.get('page') try: if not page: posts = paginator.page(1) else: 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 (e.g. 9999), deliver last page of results. posts = paginator.page(paginator.num_pages) return render_to_response('listing/home.html', {"posts": posts}, context_instance=RequestContext(request))
def get_queryset(self): digg_paginator = DiggPaginator( PremiumCache.objects.all().order_by('-pk'), 15) page = self.request.GET.get('page') return digg_paginator.get_page(page)
def get_context_data(self, **kwargs): context = super(EmployeeAppraisalMeasureView, self).get_context_data(**kwargs) reviewed = self.emp_appraisal.get_total_answered( reviewer=self.request.user.profile) total = self.emp_appraisal.measures.filter( reviewer=self.request.user.profile).count() remarks = { 'open': { 'initiator': self.emp_appraisal.flows.order_by('id')[0].from_reviewer, 'date': self.emp_appraisal.flows.order_by('id')[0].created_at, 'comment': self.emp_appraisal.on_open_remarks, }, 'close': { 'closed_by': self.emp_appraisal.flows.order_by('-id')[0].to_reviewer, 'date': self.emp_appraisal.closed_on, 'comment': self.emp_appraisal.on_close_remarks }, } is_closed = False if self.emp_appraisal.is_complete is True: is_closed = True show_submit = False if not is_closed and (self.request.user.profile.reports_to and reviewed == total ) and self.emp_appraisal.get_has_appraisal( ) == self.request.user.profile and total: show_submit = True extra_context = { 'is_closed': is_closed, 'remarks': remarks, 'emp_appraisal': self.emp_appraisal, 'total_measures_reviewed': reviewed, 'total_measures': total, 'paginator': DiggPaginator(self.get_queryset(), self.paginate_by, body=PGN['body'], tail=PGN['tail'], padding=PGN['padding']).page( self.kwargs.get('page', 1)) } context.update(extra_context) if show_submit: profile = self.request.user.profile context.update({ 'show_submit': show_submit, 'form': EmployeeAppraisalFlowForm( initial={ 'from_reviewer': profile, 'to_reviewer': profile.reports_to, 'employee_appraisal': self.emp_appraisal }) }) return context
def hansard_view(request, year, month, day, pageno): y = int(year) m = int(month) d = int(day) dateobj = datetime.date(y, m, d) # qs = basehansard.objects.raw("select * from dilipadsite_basehansard where speechdate = %s order by basepk", [dateobj]) qs = basehansard.objects.filter(speechdate=dateobj).order_by('basepk') # need to add select_related to speed up rendering # but first basehansard needs foreignkeys to be added! qscount = len(qs) # use len() now so there's a cached verson for paginator ## this is horrible ## def items_count(): ## cursor = connection.cursor() ## cursor.execute("select count(*) from dilipadsite_basehansard where speechdate = %s", [dateobj]) ## row = cursor.fetchone() ## return row[0] paginator = DiggPaginator(qs, 20, body=5, tail=2, padding=2) paginator._count = qscount # items_count() datenavobject = datenav.objects.get(hansarddate=dateobj) storage = messages.get_messages(request) baseurl = ("/full/" + str(year) + "/" + str(month) + "/" + str(day) + "/") if len(storage) == 0: try: context = { 'year': year, 'baseurl': baseurl, 'month': month, 'day': day, 'hansard': qs[1], 'next': datenavobject.get_next_day_link(), 'paginator': paginator, 'page': paginator.page(pageno), 'pageno': pageno, 'previous': datenavobject.get_previous_day_link() } except InvalidPage: raise Http404("Page does not exist") else: refer_pk = None for m in storage: refer_pk = m.message break try: context = { 'year': year, 'month': month, 'baseurl': baseurl, 'day': day, 'hansard': qs[1], 'next': datenavobject.get_next_day_link(), 'paginator': paginator, 'page': paginator.page(pageno), 'pageno': pageno, 'previous': datenavobject.get_previous_day_link(), 'refer_pk': refer_pk } except InvalidPage: raise Http404("Page does not exist") return render_to_response('full/hansard.html', context, context_instance=RequestContext(request))
def _item_s_pagination(self): paginator = DiggPaginator(self.search_set, self.PAGE_COUNT) self.page = paginator.page(self.params_storage['page'] or 1)
def get_queryset(self): digg_paginator = DiggPaginator( Application.objects.all().order_by('-pk'), 10) page = self.request.GET.get('page') return digg_paginator.get_page(page)
def page(request, pk, topic): sections = Section.objects.all() post_num = Post.objects.count() user_num = User.objects.filter(is_active=True).count() try: post_query = Post.objects.get(pk=pk) except Post.DoesNotExist: return render( request, 'main/post_detail.html', { 'sections': sections, 'post_num': post_num, 'user_num': user_num, }, ) if slugify(topic) != slugify(post_query.title[0:50]): return render( request, 'main/post_detail.html', { 'sections': sections, 'post_num': post_num, 'user_num': user_num, }, ) if post_query: if request.user.is_authenticated(): hit_count = HitCount.objects.get_for_object(post_query) hit_count_response = HitCountMixin.hit_count(request, hit_count) userextend_user = UserExtend.objects.get(user=request.user) userextend_user.last_seen = timezone.now() userextend_user.save(update_fields=['last_seen']) query = post_query.comment_set.all() page = request.GET.get('page', 1) paginator = Paginator(query, 20, body=5) try: comment = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. comment = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. comment = paginator.page(paginator.num_pages) return render( request, 'main/post_detail.html', { 'post': post_query, 'comment_list': comment, 'sections': sections, 'post_num': post_num, 'user_num': user_num, }, )
def make_paggination(self, queryset, limit): digg_paginator = DiggPaginator(queryset, limit) page = self.request.GET.get('page') return digg_paginator.get_page(page)
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) digg_paginator = DiggPaginator(self.queryset, 10) page = self.request.GET.get('page') context.update({'data_with_paginate': digg_paginator.get_page(page)}) return context