Python django.core.paginator.PageNotAnInteger() Examples
The following are 30
code examples of django.core.paginator.PageNotAnInteger().
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 also want to check out all available functions/classes of the module
django.core.paginator
, or try the search function
.
Example #1
Source File: models.py From WF-website with GNU Affero General Public License v3.0 | 7 votes |
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 #2
Source File: views.py From WF-website with GNU Affero General Public License v3.0 | 7 votes |
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, })
Example #3
Source File: views.py From ran-django-template with GNU General Public License v3.0 | 7 votes |
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 #4
Source File: models.py From WF-website with GNU Affero General Public License v3.0 | 7 votes |
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 #5
Source File: views.py From ran-django-template with GNU General Public License v3.0 | 7 votes |
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 #6
Source File: views.py From osler with GNU General Public License v3.0 | 7 votes |
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 #7
Source File: jobs.py From tramcar with MIT License | 7 votes |
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 #8
Source File: views.py From FIR with GNU General Public License v3.0 | 7 votes |
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 #9
Source File: tools.py From dj-diabetes with BSD 3-Clause "New" or "Revised" License | 7 votes |
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 #10
Source File: views.py From dart with Apache License 2.0 | 7 votes |
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 #11
Source File: utils.py From Servo with BSD 2-Clause "Simplified" License | 7 votes |
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 #12
Source File: index.py From BikeMaps with MIT License | 7 votes |
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 #13
Source File: util.py From open-synthesis with GNU General Public License v3.0 | 6 votes |
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 #14
Source File: models.py From wagtail-cookiecutter-foundation with MIT License | 6 votes |
def get_context(self, request): # Get products products = self.products # Filter by tag tag = request.GET.get('tag') if tag: products = products.filter(tags__name=tag) # Pagination page = request.GET.get('page') paginator = Paginator(products, 12) # Show 10 products per page try: products = paginator.page(page) except PageNotAnInteger: products = paginator.page(1) except EmptyPage: products = paginator.page(paginator.num_pages) # Update template context context = super(ProductIndexPage, self).get_context(request) context['products'] = products return context
Example #15
Source File: blog_tags.py From Django-blog with MIT License | 6 votes |
def pagination_tag(context, object_list, page_count=5): """ context是Context 对象,object_list是你要分页的对象,page_count表示每页的数量 """ paginator = Paginator(object_list, page_count) page = context['request'].GET.get('page') # 前端里规定的字段, 传来的页码page try: object_list = paginator.page(page) # 根据页码获取对应页的数据 except PageNotAnInteger: # 如果page不是int,字符串或为None,就返回第一页 object_list = paginator.page(1) except EmptyPage: # 如果page是int, 负数,或0,或者超过最大页数,返回最后一页 object_list = paginator.page(paginator.num_pages) return object_list # 模板里as可以取得return {% pagination_tag article_list 2 as article_list %}
Example #16
Source File: views.py From Collaboration-System with GNU General Public License v2.0 | 6 votes |
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 #17
Source File: views.py From Collaboration-System with GNU General Public License v2.0 | 6 votes |
def display_published_media(request, mediatype): try: cmedialist = CommunityMedia.objects.filter(media__state__name='publish', media__mediatype=mediatype) medialist = list(cmedialist) page = request.GET.get('page', 1) paginator = Paginator(list(medialist), 5) try: mediaPublished = paginator.page(page) except PageNotAnInteger: mediaPublished = paginator.page(1) except EmptyPage: mediaPublished = paginator.page(paginator.num_pages) if mediatype == 'Image': return render(request, 'images_published.html',{'mediaPublished':mediaPublished}) elif mediatype == 'Audio': return render(request, 'audio_published.html',{'mediaPublished':mediaPublished}) else: return render(request, 'video_published.html',{'mediaPublished':mediaPublished}) except CommunityMedia.DoesNotExist: errormessage = 'No published media in community'
Example #18
Source File: views.py From Collaboration-System with GNU General Public License v2.0 | 6 votes |
def display_articles(request): """ display list of articles in article list page. """ articlelist = CommunityArticles.objects.filter(article__state__final=True) page = request.GET.get('page', 1) paginator = Paginator(list(articlelist), 5) try: articles = paginator.page(page) except PageNotAnInteger: articles = paginator.page(1) except EmptyPage: articles = paginator.page(paginator.num_pages) fav_articles = '' if request.user.is_authenticated: resource_ids = favourite.objects.values_list('resource').filter(user=request.user,category='article') fav_articles = Articles.objects.filter(pk__in=resource_ids) return render(request, 'articles.html',{'articles':articles, 'favs':fav_articles})
Example #19
Source File: views.py From freesound-datasets with GNU Affero General Public License v3.0 | 6 votes |
def taxonomy_node(request, short_name, node_id): dataset = get_object_or_404(Dataset, short_name=short_name) user_is_maintainer = dataset.user_is_maintainer(request.user) node_id = unquote(node_id) node = dataset.taxonomy.get_element_at_id(node_id) annotation_list = dataset.annotations_per_taxonomy_node(node_id)\ .annotate(num_votes=Count('votes')).order_by('-num_votes', 'pk') paginator = Paginator(annotation_list, 10) page = request.GET.get('page') try: annotations = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. annotations = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. annotations = paginator.page(paginator.num_pages) return render(request, 'datasets/taxonomy_node.html', {'dataset': dataset, 'node': node, 'user_is_maintainer': user_is_maintainer, 'sounds': annotations})
Example #20
Source File: views.py From ran-django-template with GNU General Public License v3.0 | 6 votes |
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 #21
Source File: views.py From dart with Apache License 2.0 | 6 votes |
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 #22
Source File: models.py From WF-website with GNU Affero General Public License v3.0 | 6 votes |
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 #23
Source File: models.py From wagtail-cookiecutter-foundation with MIT License | 6 votes |
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
Example #24
Source File: views.py From StormOnline with Apache License 2.0 | 6 votes |
def get(self, request): all_messages = UserMessage.objects.filter(user=request.user.id) # 用户进入个人中心消息页面,清空未读消息记录 all_unread_messages = UserMessage.objects.filter(user=request.user.id, has_read=False) for unread_message in all_unread_messages: unread_message.has_read = True unread_message.save() # 对课程机构进行分页 # 尝试获取前台get请求传递过来的page参数 # 如果是不合法的配置参数默认返回第一页 try: page = request.GET.get('page', 1) except PageNotAnInteger: page = 1 # 这里指从allorg中取五个出来,每页显示5个 p = Paginator(all_messages, 4) messages = p.page(page) return render(request, "usercenter-message.html", { "messages": messages }) # 首页view
Example #25
Source File: views.py From CATEd with MIT License | 6 votes |
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 #26
Source File: generic.py From aswan with GNU Lesser General Public License v2.1 | 6 votes |
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 #27
Source File: views.py From BioQueue with Apache License 2.0 | 5 votes |
def page_info(page_model, page): try: items = page_model.page(page) except PageNotAnInteger: items = page_model.page(1) except EmptyPage: items = page_model.page(page_model.num_pages) return items
Example #28
Source File: views.py From mangaki with GNU Affero General Public License v3.0 | 5 votes |
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 #29
Source File: companies.py From tramcar with MIT License | 5 votes |
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 #30
Source File: views.py From cornerwise with MIT License | 5 votes |
def list_proposals(req): proposals = _query(req) try: page = int(req.GET["page"]) except (ValueError, KeyError): page = 1 context = {} if page: try: per_page = int(req.GET.get("per_page", 50)) except ValueError: per_page = 50 paginator = Paginator(proposals, per_page=min(per_page, 50)) proposals = paginator.page(page) try: query_params = req.GET.copy() def make_url(page): query_params["page"] = str(page) return req.path + "?" + query_params.urlencode() context["paginator"] = paginator_context(proposals, make_url) except (PageNotAnInteger, EmptyPage) as err: raise ErrorResponse("No such page", {"page": page}, err=err) context["proposals"] = [ proposal_json( proposal, include_images=1, include_events=True) for proposal in proposals ] return context