Browse Source

Added topic pages in the forums template

sh4nks 11 years ago
parent
commit
0f49a32ed5
3 changed files with 29 additions and 11 deletions
  1. 12 6
      flaskbb/templates/forum/forum.html
  2. 13 1
      flaskbb/templates/macros.html
  3. 4 4
      flaskbb/utils/query.py

+ 12 - 6
flaskbb/templates/forum/forum.html

@@ -3,7 +3,7 @@
 
 {% extends "layout.html" %}
 {% block content %}
-{% from 'macros.html' import render_pagination %}
+{% from 'macros.html' import render_pagination, topic_pages %}
 
 <ol class="breadcrumb">
     <li><a href="{{ url_for('forum.index') }}">Forum</a></li>
@@ -128,17 +128,23 @@
         {% for topic, topicread in topics.items %}
         <tr>
             <td width="4%">
-
-            {% if topicread|is_unread(topic.last_post) %}
-                <span class="fa fa-comment" style="font-size: 2em"></span>
+            {% if topic.locked %}
+                <span class="fa fa-locked" style="font-size: 2em"></span>
             {% else %}
-                <span class="fa fa-comment-o" style="font-size: 2em"></span>
+                {% if topicread|is_unread(topic.last_post) %}
+                    <span class="fa fa-comment" style="font-size: 2em"></span>
+                {% else %}
+                    <span class="fa fa-comment-o" style="font-size: 2em"></span>
+                {% endif %}
             {% endif %}
 
             </td>
             <td>
                 <div>
-                    <a href="{{ url_for('forum.view_topic', topic_id=topic.id) }}">{{ topic.title }}</a> <br />
+                    <a href="{{ url_for('forum.view_topic', topic_id=topic.id) }}">{{ topic.title }}</a>
+                    <!-- Topic Pagination -->
+                    {{ topic_pages(topic, config["POSTS_PER_PAGE"]) }}
+                    <br />
                     <small>by <a href="{{ url_for('user.profile', username=topic.user.username) }}">{{ topic.user.username }}</a></small>
                 </div>
             </td>

+ 13 - 1
flaskbb/templates/macros.html

@@ -151,7 +151,7 @@
 
 {% macro render_pagination(page_obj, url) %}
 <ul class="pagination" style="margin: 0; float:right">
-    <li><span class="pagination-text">Pages: </span></li>
+    <li><span class="pages-label">Pages: </span></li>
     {%- for page in page_obj.iter_pages() %}
         {% if page %}
             {% if page != page_obj.page %}
@@ -166,3 +166,15 @@
     {% endif %}
 </ul>
 {% endmacro %}
+
+
+{%- macro topic_pages(topic_obj, per_page=10) -%}
+{% set topic_pages = (topic_obj.post_count / per_page)|round|int %}
+{%- if topic_pages >  1 -%}
+<small>[
+    {% for page in range(0, topic_pages) %}
+            <a href="{{ url_for('forum.view_topic', topic_id=topic_obj.id) }}?page={{ page+1 }}">{{ page+1 }} </a>
+    {% endfor %}
+]</small>
+{%- endif -%}
+{%- endmacro -%}

+ 4 - 4
flaskbb/utils/query.py

@@ -47,12 +47,12 @@ class Pagination(object):
             pages = int(ceil(self.total / float(self.per_page)))
         return pages
 
-    def prev(self, error_out=False):
+    def prev(self, error_out=False, add_none=False):
         """Returns a :class:`Pagination` object for the previous page."""
         assert self.query is not None, 'a query object is required ' \
                                        'for this method to work'
         return self.query.paginate(self.page - 1, self.per_page, error_out,
-                                   add_none)
+                                   self.add_none)
 
     @property
     def prev_num(self):
@@ -64,12 +64,12 @@ class Pagination(object):
         """True if a previous page exists"""
         return self.page > 1
 
-    def next(self, error_out=False):
+    def next(self, error_out=False, add_none=False):
         """Returns a :class:`Pagination` object for the next page."""
         assert self.query is not None, 'a query object is required ' \
                                        'for this method to work'
         return self.query.paginate(self.page + 1, self.per_page, error_out,
-                                   add_none)
+                                   self.add_none)
 
     @property
     def has_next(self):