我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用django.core.paginator.PageNotAnInteger()。
def get_context(self, request): # Get blogs blogs = self.blogs # Filter by tag tag = request.GET.get('tag') if tag: blogs = blogs.filter(tags__name=tag) # Pagination page = request.GET.get('page') paginator = Paginator(blogs, 10) # Show 10 blogs per page try: blogs = paginator.page(page) except PageNotAnInteger: blogs = paginator.page(1) except EmptyPage: blogs = paginator.page(paginator.num_pages) # Update template context context = super(BlogIndexPage, self).get_context(request) context['blogs'] = blogs return context
def bookmark_list(request): all_bookmarks = request.user.bookmarkvideo_set.select_related('video') # ?? ??? ???? ?????? ?? paginator = Paginator(all_bookmarks, 5) page = request.GET.get('page') try: bookmarks = paginator.page(page) except PageNotAnInteger: bookmarks = paginator.page(1) except EmptyPage: bookmarks = paginator.page(paginator.num_pages) context = { 'bookmarks': bookmarks, } return render(request, 'video/bookmark_list.html', context)
def get_user_profile(request, username): user = User.objects.get(username=username) oglasi = Oglas.objects.filter(vlasnik=user) emp = Employee.objects.filter(user=user) if len(emp) > 0: employee = emp[0] else: employee = False paginator = Paginator(oglasi, 8) # Show 25 contacts per page page_request_var = "page" page = request.GET.get(page_request_var) try: queryset = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. queryset = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. queryset = paginator.page(paginator.num_pages) return render(request, 'music/user_profile.html', {'user': user, 'oglasi': queryset, 'employee': employee, 'request': request, 'kategorije': Kategorija.objects.all(), "page_request_var": page_request_var})
def get_context_data(self, **kwargs): context = super(PaginationView, self).get_context_data(**kwargs) lines = [] for i in range(200): lines.append('Line %s' % (i + 1)) paginator = Paginator(lines, 10) page = self.request.GET.get('page') try: show_lines = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. show_lines = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. show_lines = paginator.page(paginator.num_pages) context['lines'] = show_lines return context
def serve_listing(self, request): """Renders the children pages.""" pages = self.children # Pagination page = request.GET.get('page') paginator = Paginator(pages, settings.ITEMS_PER_PAGE) try: pages = paginator.page(page) except EmptyPage: pages = paginator.page(paginator.num_pages) except PageNotAnInteger: pages = paginator.page(1) return render(request, self.get_template(request), {'self': self, 'pages': pages})
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})
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
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
def faircoin_history(request, resource_id): resource = get_object_or_404(EconomicResource, id=resource_id) event_list = resource.events.all() agent = get_agent(request) init = {"quantity": resource.quantity,} unit = resource.resource_type.unit paginator = Paginator(event_list, 25) page = request.GET.get('page') try: events = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. events = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. events = paginator.page(paginator.num_pages) return render_to_response("work/faircoin_history.html", { "resource": resource, "agent": agent, "unit": unit, "events": events, }, context_instance=RequestContext(request))
def all_contributions(request): event_list = EconomicEvent.objects.filter(is_contribution=True) paginator = Paginator(event_list, 25) page = request.GET.get('page') try: events = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. events = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. events = paginator.page(paginator.num_pages) return render_to_response("valueaccounting/all_contributions.html", { "events": events, }, context_instance=RequestContext(request))
def project_wip(request, project_id): #import pdb; pdb.set_trace() project = get_object_or_404(EconomicAgent, pk=project_id) process_list = project.wip() paginator = Paginator(process_list, 25) page = request.GET.get('page') try: processes = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. processes = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. processes = paginator.page(paginator.num_pages) return render_to_response("valueaccounting/project_wip.html", { "project": project, "processes": processes, }, context_instance=RequestContext(request))
def todo_history(request): #import pdb; pdb.set_trace() todo_list = Commitment.objects.finished_todos().order_by('-due_date',) paginator = Paginator(todo_list, 25) page = request.GET.get('page') try: todos = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. todos = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. todos = paginator.page(paginator.num_pages) return render_to_response("valueaccounting/todo_history.html", { "todos": todos, }, context_instance=RequestContext(request))
def open_todos(request): #import pdb; pdb.set_trace() todo_list = Commitment.objects.todos().order_by('-due_date',) paginator = Paginator(todo_list, 25) page = request.GET.get('page') try: todos = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. todos = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. todos = paginator.page(paginator.num_pages) return render_to_response("valueaccounting/open_todos.html", { "todos": todos, }, context_instance=RequestContext(request))
def weibo_list(request): context = {} # ???? params = request.GET.copy() _obj_list = Weibo.objects.order_by('-id') paginator = Paginator(_obj_list, 50 ) # Show 10 contacts 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) context.update({ "active_nav": "weibos.weibo", "weibos": _objs, "params": params }) return render_to_response('weibos/weibo_list.html', {}, context_instance=RequestContext(request, context))
def device(request): values = {} # collect api_key and device id devices = [] for s in Service.objects.all(): for d in WorkSpace.objects.filter(service=s): devices.append({'apikey':s.apikey, 'device_id':d.ws_id, 'workspace':d.entity_name, 'address':d.address, 'maxsize':d.maxsize}) paginator = Paginator(devices, 11) try: page = request.GET.get('page') results = paginator.page(page) except PageNotAnInteger: results = paginator.page(1) except EmptyPage: results = paginator.page(paginator.num_pages) values = {'results':results} return render_to_response("RFID.html", values, context_instance=RequestContext(request))
def event_public_tickets(request, slug): event = get_object_or_404(Event.objects.published(), slug=slug) context = dict() update_event_context(event, context) available_tickets = event.tickettype_set.filter(accessibility=TicketType.PUBLIC)\ .exclude(attendee_type=TicketType.AID).exclude(attendee_type=TicketType.VOLUNTEER)\ .exclude(attendee_type=TicketType.PRESS).order_by('price', 'title') available_tickets = [t for t in available_tickets if t._get_current_status() in (TicketType.ACTIVE, TicketType.SOLDOUT)] paginator = Paginator(available_tickets, 10) page = request.GET.get('page') try: available_tickets = paginator.page(page) except PageNotAnInteger: available_tickets = paginator.page(1) except EmptyPage: available_tickets = paginator.page(paginator.num_pages) context['tickets'] = available_tickets context['dispaly_ticket_availability'] = settings.DISPLAY_TICKET_AVAILABILITY return render(request=request, template_name='konfera/event/public_tickets.html', context=context)
def rqloglist(request): if request.method != "GET": raise SuspiciousOperation if not request.user.is_authenticated() or not request.user.is_active: raise PermissionDenied is_admin = check_is_admin(request.user.username) if not is_admin: raise PermissionDenied log = models.RequestsLog.objects.all().order_by('-date') paginator = Paginator(log, 100) page = request.GET.get('page') try: logpage = paginator.page(page) except PageNotAnInteger: logpage = paginator.page(1) except EmptyPage: logpage = paginator.page(paginator.num_pages) vars = { 'list': logpage } return render(request, 'requests/rqloglist.html', vars)
def loglist(request): if request.method != "GET": raise SuspiciousOperation if not request.user.is_authenticated(): raise PermissionDenied is_admin = check_is_admin(request.user.username) if not is_admin: raise PermissionDenied log = Log.objects.all().order_by('-date') paginator = Paginator(log, 100) page = request.GET.get('page') try: logpage = paginator.page(page) except PageNotAnInteger: logpage = paginator.page(1) except EmptyPage: logpage = paginator.page(paginator.num_pages) vars = {'list': logpage } return render(request, 'logs/log.html', vars)
def paginate(self, page, per_page, data): list_games = data paginator = Paginator(list_games, per_page) try: games = paginator.page(page) except PageNotAnInteger: games = paginator.page(1) except EmptyPage: games = paginator.page(1) page = 1 interval_range = self.get_pagination_range(page, paginator.num_pages) list_games = GameSerializer(games.object_list, many=True).data paginated = { "games": list_games, "info": { "range_start": interval_range[0], "range_end": interval_range[1], "num_pages": paginator.num_pages, "page": page } } return paginated
def _build_page_range(paginator, index = 1): try: page = paginator.page(index) except PageNotAnInteger: page = paginator.page(1) except EmptyPage: page = paginator.page(paginator.num_pages) page.page_range = [page.number] crt_range = 0 for i in range(1,5): if (page.number + i) <= paginator.num_pages: page.page_range = page.page_range + [ page.number + i] crt_range +=1 if (page.number - i) > 0: page.page_range = [page.number -i] + page.page_range crt_range +=1 if crt_range == 4: break return page
def get(self, request): user = request.user comments = Comment.objects.all().filter(deleted=False).filter(user=user).order_by('-created') posts = Post.objects.all().filter(deleted=False).filter(user=user).order_by('-created') total_count = Comment.objects.all().filter(deleted=False).filter(user=user).count() + Post.objects.all().filter(deleted=False).filter(user=user).count() all_items = chain(comments, posts) all_items = sorted(all_items, key=attrgetter('created'), reverse=True) paginator = Paginator(all_items, self.paginate_by) 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 (e.g. 9999), deliver last page of results. posts = paginator.page(paginator.num_pages) return render(request, self.template_name, {'posts': posts})
def get_context_data(self): context = {} attempts = Attempt.objects.own(self.request).order_by('-created_time') paginator = Paginator(attempts, 10) page = self.request.GET.get('page') try: attempts = paginator.page(page) except PageNotAnInteger: attempts = paginator.page(1) except EmptyPage: attempts = paginator.page(paginator.num_pages) context['attempts'] = attempts success_rate = None if Attempt.objects.num_attempts(self.request): success_rate = 100 * (Attempt.objects.num_good_attempts(self.request) / Attempt.objects.num_attempts(self.request)) success_rate = round(success_rate, 1) context['success_rate'] = success_rate return context
def get_context_data(self, **kwargs): context = super(ScienceListView, self).get_context_data(**kwargs) science_lists = self.get_queryset() paginator = Paginator(science_lists, self.paginate_by) try: page = self.kwargs['page'] except: page = 1 try: scienceart = paginator.page(page) except PageNotAnInteger: scienceart = paginator.page(1) except EmptyPage: scienceart = paginator.page(paginator.num_pages) context['scienceart'] = scienceart context['sci'] = self.kwargs['sci_slug'] return context
def get_context_data(self, **kwargs): context = super(TermListView, self).get_context_data(**kwargs) term_lists = self.get_queryset() paginator = Paginator(term_lists, self.paginate_by) try: page = self.kwargs['page'] except: page = 1 try: terms = paginator.page(page) except PageNotAnInteger: terms = paginator.page(1) except EmptyPage: terms = paginator.page(paginator.num_pages) context['terms'] = terms context['term_slug'] = self.kwargs['term_slug'] return context
def get_context_data(self, **kwargs): context = super(VideoListView, self).get_context_data(**kwargs) video_lists = self.get_queryset() paginator = Paginator(video_lists, self.paginate_by) try: page = self.kwargs['page'] except: page = 1 try: videos = paginator.page(page) except PageNotAnInteger: videos = paginator.page(1) except EmptyPage: videos = paginator.page(paginator.num_pages) context['videos'] = videos context['vid'] = self.kwargs['vid_slug'] return context
def get_context_data(self, **kwargs): context = super(TwitsListView, self).get_context_data(**kwargs) twit_lists = self.get_queryset() paginator = Paginator(twit_lists, self.paginate_by) try: page = self.kwargs['page'] except: page = 1 try: twits = paginator.page(page) except PageNotAnInteger: twits = paginator.page(1) except EmptyPage: twits = paginator.page(paginator.num_pages) context['twits'] = twits context['twit_slug'] = self.kwargs['twit_slug'] return context
def index(request): posts_list = Post.objects.all() # .order_by("-timestamp") paginator = Paginator(posts_list, 5) page_var = 'page1' page = request.GET.get(page_var) try: posts = paginator.page(page) except PageNotAnInteger: posts = paginator.page(1) except EmptyPage: posts = paginator.page(paginator.num_pages) context = { 'page_title': 'List of Posts', 'posts': posts, 'page_var': page_var } return render(request, 'posts/index.html', context)
def list_vulns(request, vuln_list): myList = [] for vt in vuln_list: positives = VulnerabilityResult.objects.all().filter(name=vt) apps = set(App.objects.filter(vulnerabilityresult__name=vt)) myList.append({"name":vt, "count":positives.count, "appcount":len(apps)}) myList.sort(key= lambda vt:vt['appcount'], reverse=True) paginator = Paginator(myList,20) page = request.GET.get('page') try: vulns = paginator.page(page) except PageNotAnInteger: vulns = paginator.page(1) except EmptyPage: vulns = paginator.page(paginator.num_pages) context = {'vulns':vulns} return render_to_response('frontpage/static_vulns.html', RequestContext(request, context))
def movie_list(request): paginator = Paginator(TOP_MOVIE_LIST, 25) page_number = request.GET.get("page") try: page = paginator.page(page_number) except PageNotAnInteger: # If page is not an integer, show first page. page = paginator.page(1) except EmptyPage: # If page is out of range, show last existing page. page = paginator.page(paginator.num_pages) context = { "object_list": page, } return render(request, "movies/movie_list.html", context)
def list_guazi(request): after_range_num = 5 before_range_num = 4 page_size = 20 Guazi_list = GuaziCar.objects.all().order_by('-id') paginator = Paginator(Guazi_list, page_size) try: page = int(request.GET.get('page','1')) if page < 1: page=1 except ValueError: page=1 try: carlist = paginator.page(page) except (EmptyPage,InvalidPage,PageNotAnInteger): carlist = paginator.page(1) if page >= after_range_num: page_range = list(paginator.page_range)[page-after_range_num:page+before_range_num] else: page_range = list(paginator.page_range)[0:int(page)+before_range_num] return render(request, 'guazi.html', {'guazi_list': carlist, 'page_range': page_range})
def view_station(request, station_id): station = get_object_or_404(Station, abbreviation=station_id) incidents = Incident.objects.filter( station__id=station.id, ).order_by('-incident_dt') incidents_count = len(incidents) paginator = Paginator(incidents, 25) page = request.GET.get('page') try: incidents = paginator.page(page) except PageNotAnInteger: incidents = paginator.page(1) except EmptyPage: incidents = paginator.page(paginator.num_pages) return render(request, 'station.html', {'incidents_count': incidents_count, 'station': station, 'incidents': incidents})
def incidents_for_tag(request, slug): tag = get_object_or_404(Tag, slug=slug) incidents = Incident.objects.filter( tags__id=tag.id, ).order_by('-incident_dt') incidents_count = len(incidents) paginator = Paginator(incidents, 25) page = request.GET.get('page') try: incidents = paginator.page(page) except PageNotAnInteger: incidents = paginator.page(1) except EmptyPage: incidents = paginator.page(paginator.num_pages) return render(request, 'tag.html', {'tag': tag, 'incidents': incidents, 'incidents_count': incidents_count}) # pylint: disable=too-many-ancestors
def get_context(self, request): context = super(HutIndexPage, self).get_context(request) page = request.GET.get('page') tag = request.GET.get('tag') pages = HutPage.objects.child_of(self).live() if tag: pages = pages.filter(facilities__slug__iexact=tag) context['tag'] = Tag.objects.get(slug__iexact=tag) paginator = Paginator(pages, 10) # Show 10 huts per page try: pages = paginator.page(page) except PageNotAnInteger: pages = paginator.page(1) except EmptyPage: pages = paginator.page(paginator.num_pages) context['children'] = pages return context
def index(request): template = get_template('index.html') attractions_data = Attractions.objects.all() paginator = Paginator(attractions_data, 5) # Show 10 content per page page = request.GET.get('page') try: content = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. content = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. content = paginator.page(paginator.num_pages) index = content.number max_index = len(paginator.page_range) start_index = max_index - 7 if index >= max_index - 5 else index - 1 if index != 1 else 1 end_index = max_index + 1 if index >= max_index - 6 else index + 7 if index != 1 else index + 8 page_range = range(start_index, end_index) html = template.render(locals()) return HttpResponse(html)
def post_list(request, tag_slug=None): object_list = Post.published.all() tag = None if tag_slug: tag = get_object_or_404(Tag, slug=tag_slug) object_list = object_list.filter(tags__in=[tag]) paginator = Paginator(object_list, 3) # 3 posts in each page page = request.GET.get('page') try: posts = paginator.page(page) except PageNotAnInteger: # If page is not an integer deliver the 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,'blog/post/list.html',{'page': page, 'posts': posts, 'tag':tag})
def image_list(request): images = Image.objects.all() paginator = Paginator(images, 8) page = request.GET.get('page') try: images = paginator.page(page) images_by_popularity = Image.objects.order_by('-total_likes') except PageNotAnInteger: if request.is_ajax(): # If page is not an integer deliver the first page images = paginator.page(1) except EmptyPage: if request.is_ajax(): # If the request AJAX and the page is out of range # return an empty page return HttpResponse('') # If page is out of range deliver last page of results images = paginator.page(paginator.num_pages) if request.is_ajax(): return render(request, 'images/image/list_ajax.html',{'section': 'images', 'images': images}) return render(request, 'images/image/list.html', {'section': 'images', 'images': images})
def album_detail(request, pk): album = get_object_or_404(Album, pk=pk) photo_list = album.photo_set.all() paginator = Paginator(photo_list, 4) page = request.GET.get('page') try: photos = paginator.page(page) except PageNotAnInteger: photos = paginator.page(1) except EmptyPage: photos = paginator.page(paginator.num_pages) context = { 'album': album, 'photos': photos, } # template_file = 'photo/album_detail.html' template_file = 'photo/ajax_album_detail.html' return render(request, template_file, context)
def html_page(request): service_name = request.GET.get('service_name') log_path = dao_config.log_dir_master service_name_path = log_path + service_name all_file = [] for i in os.listdir(service_name_path): file_path = service_name_path +'/' + i if os.path.isfile(file_path): all_file.append([i,file_path]) print(all_file) all_file = sorted(all_file, key=lambda file_name: file_name[1]) paginator = Paginator(all_file, 10) # Show 25 contacts per page page = request.GET.get('page') try: contacts = paginator.page(page) except PageNotAnInteger: contacts = paginator.page(1) except EmptyPage: contacts = paginator.page(paginator.num_pages) return render(request, 'cat_down_log.html', {"contacts": contacts,'service_name':[service_name]})
def home(request): # TODO: Order by groupname group_objs = list(Group.objects.all()) paginator = Paginator(group_objs, 10) page = request.GET.get('page') try: groups = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. groups = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. groups = paginator.page(paginator.num_pages) ctx = { "user": request.user, "groups": groups, "group_count": len(group_objs) } return render(request, 'groups/index.html', ctx)
def home(request): # TODO: Order by username user_objs = list(User.objects.all()) paginator = Paginator(user_objs, 10) page = request.GET.get('page') try: users = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. users = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. users = paginator.page(paginator.num_pages) ctx = { "user": request.user, "users": users, "user_count": len(user_objs) } return render(request, 'users/index.html', ctx)
def get_pager(request, qs, per_page=25, page=None): """ Return django paginator for queryset. """ paginator = Paginator(qs, per_page) if page is None: page = request.GET.get('page', 1) try: pager = paginator.page(page) except PageNotAnInteger: pager = paginator.page(1) except EmptyPage: pager = paginator.page(paginator.num_pages) return pager
def campaign_detail(request, pk): ''' Renders a template showing the photo results of the campaign. 20 results per page, with pagination capabilities at the bottom of each page.''' campaign = get_object_or_404(Campaign, pk=pk) # Query the DB to find all Photo records associated with this campaign results = Photo.objects.filter(campaign_number=pk) # Set up the pagination of the results paginator = Paginator(results, 20) # Show 20 contacts per page page = request.GET.get('page') try: page_content = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. page_content = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. page_content = paginator.page(paginator.num_pages) return render(request, 'ig_miner_app/campaign_detail.html', {'campaign': campaign, 'results':results, 'page_content': page_content})
def project_list(request, language): """ Returns the projects list for a given language """ language = get_object_or_404(Language, name=language) paginator = Paginator(language.project_set.order_by('-publish_date'), 6) if 'page' not in request.GET: page = 1 else: page = request.GET['page'] try: projects = paginator.page(page) except PageNotAnInteger: projects = paginator.page(1) except EmptyPage: projects = paginator.page(paginator.num_pages) context = { 'projects': projects, 'language': language, } return render(request, 'projects_page.html', context)
def matrix(request): queue_matrix = OrmQ.objects.all().order_by('lock') complete_matrix = Task.objects.all().filter( func__exact='nimbus.tasks.crawler_matrix_job', ) paginator = Paginator(complete_matrix, 6) # Show 6 contacts per page page = request.GET.get('page') try: complete_matrix = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. complete_matrix = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. complete_matrix = paginator.page(paginator.num_pages) return render(request, 'nimbus/task_matrix_list.html', { 'queue_matrix': queue_matrix, 'complete_matrix': complete_matrix })
def get_context_data(self, *args, **kwargs): context = super().get_context_data() title = self.request.GET.get('title') planet = self.request.GET.get('planet') page = self.request.GET.get('page', 1) resource_qs = self.get_resource_queryset(title, planet) resource_link_qs = self.get_resource_link_queryset(title, planet) resources = [r for r in resource_qs] resources.extend([r for r in resource_link_qs]) paginator = Paginator(resources, self.paginate_by) try: current_resources = paginator.page(page) except PageNotAnInteger: current_resources = paginator.page(1) except EmptyPage: current_resources = paginator.page(paginator.num_pages) context['resources'] = current_resources return context
def get_context(self, request): # Get posts posts = self.posts # Pagination page = request.GET.get('page') paginator = Paginator(posts, 10) try: posts = paginator.page(page) except PageNotAnInteger: posts = paginator.page(1) except EmptyPage: posts = paginator.page(paginator.num_pages) context = super(NewsIndexPage, self).get_context(request) context['posts'] = posts return context
def home(request, page=1): articles = Article.objects.all().order_by('-create_time') # ?? paginator = Paginator(articles, 15) # ??15? try: articles = paginator.page(page) except PageNotAnInteger: articles = paginator.page(1) except EmptyPage: articles = paginator.page(paginator.num_pages) for article in articles: article.tags = article.tags.split() tag_info_list = get_tag_info() date_list = Article.objects.datetimes('create_time', 'month', order='DESC') return render(request, 'index.html', {'html_title': '??', 'articles': articles, 'tag_info_list': tag_info_list, 'date_list': date_list})