Projet

Général

Profil

0001-add-pagination-for-announces-13878.patch

Serghei Mihai (congés, retour 15/05), 06 février 2017 10:52

Télécharger (6,23 ko)

Voir les différences:

Subject: [PATCH] add pagination for announces (#13878)

 corbo/templates/corbo/announce_form.html   |  2 +-
 corbo/templates/corbo/announce_list.html   | 77 ++++++++++++++++++++++++++++++
 corbo/templates/corbo/category_detail.html | 49 -------------------
 corbo/views.py                             | 12 +++--
 4 files changed, 86 insertions(+), 54 deletions(-)
 create mode 100644 corbo/templates/corbo/announce_list.html
 delete mode 100644 corbo/templates/corbo/category_detail.html
corbo/templates/corbo/announce_form.html
1
{% extends "corbo/category_detail.html" %}
1
{% extends "corbo/announce_list.html" %}
2 2
{% load i18n %}
3 3

  
4 4
{% block breadcrumb %}
corbo/templates/corbo/announce_list.html
1
{% extends 'corbo/manage.html' %}
2
{% load i18n %}
3

  
4
{% block breadcrumb %}
5
{{ block.super }}
6
{% if category %}
7
<a href='{% url "view_category" slug=category.slug %}'>{{ category }}</a>
8
{% endif %}
9
{% endblock %}
10

  
11
{% block appbar %}
12
<h2>{{ category.name }}</h2>
13
<a class="extra-actions-menu-opener">☰</a>
14
<ul class="extra-actions-menu">
15
  <li><a href="{% url 'subscriptions-import' slug=category.slug %}" rel="popup">{% trans 'Import subscriptions' %}</a></li>
16
</ul>
17

  
18
<a href="{% url 'delete_category' slug=category.slug %}" rel="popup">{% trans 'Delete' %}</a>
19
<a href="{% url 'edit_category' slug=category.slug %}" rel="popup">{% trans 'Edit' %}</a>
20
<a href="{% url 'add_announce' slug=category.slug %}">{% trans 'New announce' %}</a>
21
{% endblock %}
22

  
23
{% block content %}
24
<div id="management">
25
<ul class='objects-list single-links'>
26
{% for announce in object_list %}
27
<li class="{% if not announce.is_published %}unpublished{% endif %}">
28
  <a href="{% url 'edit_announce' announce.id %}">{{ announce.title }}</a>
29
  <div class="datetime">
30
    {% if announce.publication_time %}
31
    {% blocktrans with mtime=announce.publication_time|date:'DATETIME_FORMAT' %}
32
    Published on {{ mtime }}
33
    {% endblocktrans %}
34
    {% endif %}
35
  </div>
36
</li>
37
{% empty %}
38
<div class="big-msg-info">
39
  {% blocktrans %}
40
  This category doesn't have any announces yet. Click on "New announce" button in the top
41
  right of the page to add a first one.
42
  {% endblocktrans %}
43
</div>
44
{% endfor %}
45
</ul>
46

  
47
{% if is_paginated %}
48
<p class="paginator">
49
  {% if page_obj.number > 1 %}
50
    {% if page_obj.previous_page_number != 1 %}
51
      <a href="?page=1">1</a>
52
      ...
53
    {% endif %}
54
  {% endif %}
55

  
56
  {% if page_obj.has_previous %}
57
    <a href="?page={{ page_obj.previous_page_number }}">{{ page_obj.previous_page_number }}</a>
58
  {% endif %}
59
  <span class="this-page">
60
    {{ page_obj.number }}
61
  </span>
62
  {% if page_obj.has_next %}
63
    <a href="?page={{ page_obj.next_page_number }}">{{ page_obj.next_page_number }}</a>
64
  {% endif %}
65

  
66
  {% if page_obj.number != page_obj.paginator.num_pages %}
67
    {% if page_obj.paginator.num_pages > 1 %}
68
       {% if page_obj.next_page_number != page_obj.paginator.num_pages %}
69
         ...
70
         <a href="?page={{ page_obj.paginator.num_pages }}">{{ page_obj.paginator.num_pages }}</a>
71
       {% endif %}
72
     {% endif %}
73
   {% endif %}
74
</p>
75
{% endif %}
76

  
77
{% endblock %}
corbo/templates/corbo/category_detail.html
1
{% extends 'corbo/manage.html' %}
2
{% load i18n %}
3

  
4
{% block breadcrumb %}
5
{{ block.super }}
6
{% if category %}
7
<a href='{% url "view_category" slug=category.slug %}'>{{ category }}</a>
8
{% endif %}
9
{% endblock %}
10

  
11
{% block appbar %}
12
<h2>{{ object.name }}</h2>
13
<a class="extra-actions-menu-opener">☰</a>
14
<ul class="extra-actions-menu">
15
  <li><a href="{% url 'subscriptions-import' slug=category.slug %}" rel="popup">{% trans 'Import subscriptions' %}</a></li>
16
</ul>
17

  
18
<a href="{% url 'delete_category' slug=object.slug %}" rel="popup">{% trans 'Delete' %}</a>
19
<a href="{% url 'edit_category' slug=object.slug %}" rel="popup">{% trans 'Edit' %}</a>
20
<a href="{% url 'add_announce' slug=object.slug %}">{% trans 'New announce' %}</a>
21
{% endblock %}
22

  
23
{% block content %}
24
<div id="management">
25
<ul class='objects-list single-links'>
26
{% for announce in announces %}
27
<li class="{% if not announce.is_published %}unpublished{% endif %}">
28
  <a href="{% url 'edit_announce' announce.id %}">{{ announce.title }}</a>
29
  <div class="datetime">
30
    {% if announce.publication_time %}
31
    {% blocktrans with mtime=announce.publication_time|date:'DATETIME_FORMAT' %}
32
    Published on {{ mtime }}
33
    {% endblocktrans %}
34
    {% endif %}
35
  </div>
36
</li>
37
{% endfor %}
38
</ul>
39

  
40
{% if not announces %}
41
<div class="big-msg-info">
42
  {% blocktrans %}
43
  This category doesn't have any announces yet. Click on "New announce" button in the top
44
  right of the page to add a first one.
45
  {% endblocktrans %}
46
</div>
47
{% endif %}
48

  
49
{% endblock %}
corbo/views.py
129 129
edit_category = CategoryEditView.as_view()
130 130

  
131 131

  
132
class CategoryView(DetailView):
133
    model = models.Category
132
class CategoryView(ListView):
133
    model = models.Announce
134
    paginate_by = settings.ANNOUNCES_PER_PAGE
135

  
136
    def get_queryset(self):
137
        qs = super(CategoryView, self).get_queryset()
138
        return qs.filter(category__slug=self.kwargs['slug'])
134 139

  
135 140
    def get_context_data(self, **kwargs):
136 141
        context = super(CategoryView, self).get_context_data(**kwargs)
137
        context['announces'] = self.object.announce_set.all().order_by(
138
                '-publication_time', '-ctime')
142
        context['category'] = models.Category.objects.get(slug=self.kwargs['slug'])
139 143
        return context
140 144

  
141 145

  
142
-