Browse Source

Pagination on thread view.

Rafał Pitoń 10 years ago
parent
commit
0484e1d996

+ 39 - 0
misago/templates/misago/thread/pagination.html

@@ -0,0 +1,39 @@
+{% load i18n misago_capture misago_pagination %}
+<ul class="pager pull-left">
+  <li class="page">
+    {% capture trimmed as page_strong %}
+    <strong>{{ page.number }}</strong>
+    {% endcapture %}
+    {% capture trimmed as pages_strong %}
+    <strong>{{ paginator.num_pages }}</strong>
+    {% endcapture %}
+    {% blocktrans with page=page_strong|safe pages=pages_strong|safe %}
+    Page {{ page }} of {{ pages }}
+    {% endblocktrans %}
+  </li>
+  {% if page.has_previous %}
+    <li>
+      <a href="{% pageurl link_name links_params %}" class="tooltip-top" title="{% trans "Go to first page" %}">
+        {% if page.number > 2 %}
+        {% trans "First" %}
+        {% else %}
+        <span class="glyphicon glyphicon-chevron-left"></span>
+        {% endif %}
+      </a>
+    </li>
+    {% if page.number > 2 %}
+    <li>
+      <a href="{% pageurl link_name links_params page.previous_page_number %}" class="tooltip-top" title="{% trans "Go to previous page" %}">
+        <span class="glyphicon glyphicon-chevron-left"></span>
+      </a>
+    </li>
+    {% endif %}
+  {% endif %}
+  {% if page.has_next %}
+    <li>
+      <a href="{% pageurl link_name links_params page.next_page_number %}" class="tooltip-top" title="{% trans "Go to next page" %}">
+        <span class="glyphicon glyphicon-chevron-right"></span>
+      </a>
+    </li>
+  {% endif %}
+</ul>

+ 12 - 0
misago/templates/misago/thread/replies.html

@@ -58,12 +58,24 @@
   </div>
   <div class="container">
 
+    <div class="table-actions">
+
+      {% include "misago/thread/pagination.html" %}
+
+    </div>
+
     <div class="posts-list">
       {% for post in posts %}
       {% include "misago/thread/post.html" %}
       {% endfor %}
     </div>
 
+    <div class="table-actions">
+
+      {% include "misago/thread/pagination.html" %}
+
+    </div>
+
   </div>
 </div>
 {% endblock %}

+ 4 - 2
misago/threads/models/thread.py

@@ -112,12 +112,14 @@ class Thread(models.Model):
         else:
             return 'thread'
 
-    def get_url(self, suffix=None):
+    def get_url_name(self, suffix=None):
         link = 'misago:%s' % self.link_prefix
         if suffix:
             link = '%s_%s' % (link, suffix)
+        return link
 
-        return reverse(link, kwargs={
+    def get_url(self, suffix=None):
+        return reverse(self.get_url_name(suffix), kwargs={
             'thread_slug': self.slug,
             'thread_id': self.id
         })

+ 8 - 1
misago/threads/views/generic/thread.py

@@ -68,10 +68,17 @@ class ThreadView(ViewBase):
         threadstracker.read_thread(request.user, thread, posts[-1])
 
         return self.render(request, {
+            'link_name': thread.get_url(),
+            'links_params': {
+                'thread_id': thread.id, 'thread_slug': thread.slug
+            },
+
             'forum': forum,
             'path': get_forum_path(forum),
+
             'thread': thread,
             'posts': posts,
-            'page': page,
+
             'paginator': page.paginator,
+            'page': page,
         })