From 846e8085a756fca20ed5d43e96cfadc519ae9312 Mon Sep 17 00:00:00 2001 From: Serghei Mihai Date: Thu, 2 Feb 2017 18:34:54 +0100 Subject: [PATCH] add pagination for announces (#13878) --- corbo/templates/corbo/announce_form.html | 2 +- corbo/templates/corbo/announce_list.html | 79 ++++++++++++++++++++++++++++++ corbo/templates/corbo/category_detail.html | 49 ------------------ corbo/views.py | 12 +++-- 4 files changed, 88 insertions(+), 54 deletions(-) create mode 100644 corbo/templates/corbo/announce_list.html delete mode 100644 corbo/templates/corbo/category_detail.html diff --git a/corbo/templates/corbo/announce_form.html b/corbo/templates/corbo/announce_form.html index ece7a8e..814e5eb 100644 --- a/corbo/templates/corbo/announce_form.html +++ b/corbo/templates/corbo/announce_form.html @@ -1,4 +1,4 @@ -{% extends "corbo/category_detail.html" %} +{% extends "corbo/announce_list.html" %} {% load i18n %} {% block breadcrumb %} diff --git a/corbo/templates/corbo/announce_list.html b/corbo/templates/corbo/announce_list.html new file mode 100644 index 0000000..5b2d6f1 --- /dev/null +++ b/corbo/templates/corbo/announce_list.html @@ -0,0 +1,79 @@ +{% extends 'corbo/manage.html' %} +{% load i18n %} + +{% block breadcrumb %} +{{ block.super }} +{% if category %} +{{ category }} +{% endif %} +{% endblock %} + +{% block appbar %} +

{{ category.name }}

+ + + +{% trans 'Delete' %} +{% trans 'Edit' %} +{% trans 'New announce' %} +{% endblock %} + +{% block content %} +
+ + +{% if not object_list %} +
+ {% blocktrans %} + This category doesn't have any announces yet. Click on "New announce" button in the top + right of the page to add a first one. + {% endblocktrans %} +
+{% endif %} + +{% if is_paginated %} +

+ {% if page_obj.number > 1 %} + {% if page_obj.previous_page_number != 1 %} + 1 + ... + {% endif %} + {% endif %} + + {% if page_obj.has_previous %} + {{ page_obj.previous_page_number }} + {% endif %} + + {{ page_obj.number }} + + {% if page_obj.has_next %} + {{ page_obj.next_page_number }} + {% endif %} + + {% if page_obj.number != page_obj.paginator.num_pages %} + {% if page_obj.paginator.num_pages > 1 %} + {% if page_obj.next_page_number != page_obj.paginator.num_pages %} + ... + {{ page_obj.paginator.num_pages }} + {% endif %} + {% endif %} + {% endif %} +

+{% endif %} + +{% endblock %} diff --git a/corbo/templates/corbo/category_detail.html b/corbo/templates/corbo/category_detail.html deleted file mode 100644 index 6c6f836..0000000 --- a/corbo/templates/corbo/category_detail.html +++ /dev/null @@ -1,49 +0,0 @@ -{% extends 'corbo/manage.html' %} -{% load i18n %} - -{% block breadcrumb %} -{{ block.super }} -{% if category %} -{{ category }} -{% endif %} -{% endblock %} - -{% block appbar %} -

{{ object.name }}

- - - -{% trans 'Delete' %} -{% trans 'Edit' %} -{% trans 'New announce' %} -{% endblock %} - -{% block content %} -
- - -{% if not announces %} -
- {% blocktrans %} - This category doesn't have any announces yet. Click on "New announce" button in the top - right of the page to add a first one. - {% endblocktrans %} -
-{% endif %} - -{% endblock %} diff --git a/corbo/views.py b/corbo/views.py index 1a30e1d..08e7b2c 100644 --- a/corbo/views.py +++ b/corbo/views.py @@ -129,13 +129,17 @@ class CategoryEditView(UpdateView): edit_category = CategoryEditView.as_view() -class CategoryView(DetailView): - model = models.Category +class CategoryView(ListView): + model = models.Announce + paginate_by = settings.ANNOUNCES_PER_PAGE + + def get_queryset(self): + qs = super(CategoryView, self).get_queryset() + return qs.filter(category__slug=self.kwargs['slug']) def get_context_data(self, **kwargs): context = super(CategoryView, self).get_context_data(**kwargs) - context['announces'] = self.object.announce_set.all().order_by( - '-publication_time', '-ctime') + context['category'] = models.Category.objects.get(slug=self.kwargs['slug']) return context -- 2.11.0