From 3f7c579968eff47dcac9683728d614c066ee3102 Mon Sep 17 00:00:00 2001 From: Emilie Date: Mon, 7 Nov 2016 11:46:56 +0100 Subject: [PATCH] Media : add pagination on list page --- app/local_settings.py | 3 ++- app/organization/media/views.py | 11 ++++++++--- app/templates/media/playlist_list.html | 2 ++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/local_settings.py b/app/local_settings.py index 525dd440..6a2711ae 100644 --- a/app/local_settings.py +++ b/app/local_settings.py @@ -189,7 +189,8 @@ else: SLUGIFY = 'django.template.defaultfilters.slugify' BLOG_POST_PER_PAGE = 200 -ARTICLE_PER_PAGE = 4 # just for tests because we haven't got enough content +ARTICLE_PER_PAGE = 10 +MEDIA_PER_PAGE = 9 # The numeric mode to set newly-uploaded files to. The value should be # a mode you'd pass directly to os.chmod. diff --git a/app/organization/media/views.py b/app/organization/media/views.py index 97046eda..5b04af6f 100644 --- a/app/organization/media/views.py +++ b/app/organization/media/views.py @@ -47,14 +47,19 @@ class PlaylistListView(ListView): template_name='media/playlist_list.html' context_object_name = 'playlists' def get_queryset(self): - qs = Playlist.objects.all() + self.qs = Playlist.objects.all() self.current_type = None if "type" in self.kwargs: - qs = qs.filter(type=self.kwargs['type']) + self.qs = self.qs.filter(type=self.kwargs['type']) self.current_type = self.kwargs['type'] - return qs + return self.qs def get_context_data(self, **kwargs): context = super(PlaylistListView, self).get_context_data(**kwargs) + + context['playlists'] = paginate(self.qs, self.request.GET.get("page", 1), + settings.MEDIA_PER_PAGE, + settings.MAX_PAGING_LINKS) + context['current_type'] = self.current_type return context diff --git a/app/templates/media/playlist_list.html b/app/templates/media/playlist_list.html index 301f63a4..70f7227b 100644 --- a/app/templates/media/playlist_list.html +++ b/app/templates/media/playlist_list.html @@ -42,4 +42,6 @@ {% endfor %} + {% pagination_for playlists %} + {% endblock %} -- 2.39.5