Paginage by 10 in "My Maps" page (cf #211)
This commit is contained in:
parent
dce5d137cc
commit
f566247b91
1 changed files with 6 additions and 5 deletions
|
@ -32,8 +32,8 @@ User = get_user_model()
|
||||||
class PaginatorMixin(object):
|
class PaginatorMixin(object):
|
||||||
per_page = 5
|
per_page = 5
|
||||||
|
|
||||||
def paginate(self, qs):
|
def paginate(self, qs, per_page=None):
|
||||||
paginator = Paginator(qs, self.per_page)
|
paginator = Paginator(qs, per_page or self.per_page)
|
||||||
page = self.request.GET.get('p')
|
page = self.request.GET.get('p')
|
||||||
try:
|
try:
|
||||||
qs = paginator.page(page)
|
qs = paginator.page(page)
|
||||||
|
@ -109,11 +109,12 @@ class UserMaps(DetailView, PaginatorMixin):
|
||||||
context_object_name = "current_user"
|
context_object_name = "current_user"
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
manager = Map.objects if self.request.user == self.object\
|
owner = self.request.user == self.object
|
||||||
else Map.public
|
manager = Map.objects if owner else Map.public
|
||||||
maps = manager.filter(Q(owner=self.object) | Q(editors=self.object))
|
maps = manager.filter(Q(owner=self.object) | Q(editors=self.object))
|
||||||
maps = maps.distinct().order_by('-modified_at')[:50]
|
maps = maps.distinct().order_by('-modified_at')[:50]
|
||||||
maps = self.paginate(maps)
|
per_page = 10 if owner else self.per_page
|
||||||
|
maps = self.paginate(maps, per_page)
|
||||||
kwargs.update({
|
kwargs.update({
|
||||||
"maps": maps
|
"maps": maps
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue