Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
79a09182
Kaydet (Commit)
79a09182
authored
Nis 15, 2016
tarafından
Claude Paroz
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Converted property syntax in django.core.paginator
üst
5cc8261c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
23 deletions
+18
-23
paginator.py
django/core/paginator.py
+18
-23
No files found.
django/core/paginator.py
Dosyayı görüntüle @
79a09182
...
...
@@ -2,6 +2,7 @@ import collections
from
math
import
ceil
from
django.utils
import
six
from
django.utils.functional
import
cached_property
class
InvalidPage
(
Exception
):
...
...
@@ -24,7 +25,6 @@ class Paginator(object):
self
.
per_page
=
int
(
per_page
)
self
.
orphans
=
int
(
orphans
)
self
.
allow_empty_first_page
=
allow_empty_first_page
self
.
_num_pages
=
self
.
_count
=
None
def
validate_number
(
self
,
number
):
"""
...
...
@@ -63,41 +63,36 @@ class Paginator(object):
"""
return
Page
(
*
args
,
**
kwargs
)
def
_get_count
(
self
):
@cached_property
def
count
(
self
):
"""
Returns the total number of objects, across all pages.
"""
if
self
.
_count
is
None
:
try
:
self
.
_count
=
self
.
object_list
.
count
()
except
(
AttributeError
,
TypeError
):
# AttributeError if object_list has no count() method.
# TypeError if object_list.count() requires arguments
# (i.e. is of type list).
self
.
_count
=
len
(
self
.
object_list
)
return
self
.
_count
count
=
property
(
_get_count
)
try
:
return
self
.
object_list
.
count
()
except
(
AttributeError
,
TypeError
):
# AttributeError if object_list has no count() method.
# TypeError if object_list.count() requires arguments
# (i.e. is of type list).
return
len
(
self
.
object_list
)
def
_get_num_pages
(
self
):
@cached_property
def
num_pages
(
self
):
"""
Returns the total number of pages.
"""
if
self
.
_num_pages
is
None
:
if
self
.
count
==
0
and
not
self
.
allow_empty_first_page
:
self
.
_num_pages
=
0
else
:
hits
=
max
(
1
,
self
.
count
-
self
.
orphans
)
self
.
_num_pages
=
int
(
ceil
(
hits
/
float
(
self
.
per_page
)))
return
self
.
_num_pages
num_pages
=
property
(
_get_num_pages
)
if
self
.
count
==
0
and
not
self
.
allow_empty_first_page
:
return
0
hits
=
max
(
1
,
self
.
count
-
self
.
orphans
)
return
int
(
ceil
(
hits
/
float
(
self
.
per_page
)))
def
_get_page_range
(
self
):
@property
def
page_range
(
self
):
"""
Returns a 1-based range of pages for iterating through within
a template for loop.
"""
return
six
.
moves
.
range
(
1
,
self
.
num_pages
+
1
)
page_range
=
property
(
_get_page_range
)
QuerySetPaginator
=
Paginator
# For backwards-compatibility.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment