Просмотр исходного кода

Subforum-related template tweaks.

Categories are now just interpreted as forums, there is no category-specific view.
Forums on "index" view list their immediate subforums; same with subforums on "forum" view.
Forum model has helper function "get_breadcrumbs", that navigates up through the parent hierarchy and returns a list of all the parents - top-most parent [category] first through to Forum's immediate parent last.
RJackson 11 лет назад
Родитель
Сommit
940592670f

+ 10 - 0
flaskbb/forum/models.py

@@ -233,6 +233,16 @@ class Forum(db.Model):
     def get_categories(cls):
         return cls.query.filter(cls.is_category)
 
+    def get_breadcrumbs(self):
+        breadcrumbs = []
+        parent = self.parent
+        while parent is not None:
+            breadcrumbs.append(parent)
+            parent = parent.parent
+
+        breadcrumbs.reverse()
+        return breadcrumbs
+
 
 """
 A topic can be tracked by many users

+ 0 - 8
flaskbb/forum/views.py

@@ -45,14 +45,6 @@ def index():
                            online_users=len(get_online_users()),
                            online_guests=len(get_online_users(guest=True)))
 
-
-@forum.route("/category/<int:category_id>")
-def view_category(category_id):
-    category = Forum.get_categories().filter_by(id=category_id).first()
-
-    return render_template("forum/category.html", category=category)
-
-
 @forum.route("/forum/<int:forum_id>")
 def view_forum(forum_id):
     page = request.args.get('page', 1, type=int)

+ 0 - 13
flaskbb/templates/forum/category.html

@@ -1,13 +0,0 @@
-{% set page_title = category.title ~ " - Category"%}
-{% set active_forum_nav=True %}
-
-{% extends "layout.html" %}
-{% block content %}
-
-<ol class="breadcrumb">
-    <li><a href="{{ url_for('forum.index') }}">Forum</a></li>
-    <li class="active">{{ category.title }}</li>
-</ol>
-{% include 'forum/category_layout.html' %}
-
-{% endblock %}

+ 13 - 5
flaskbb/templates/forum/category_layout.html

@@ -2,7 +2,7 @@
     <thead class="categoryhead">
         <tr>
             <td colspan="5">
-                <div><strong><a href="{{ url_for('forum.view_category', category_id=category.id) }}">{{ category.title }}</a></strong></div>
+                <div><strong><a href="{{ url_for('forum.view_forum', forum_id=category.id) }}">{{ category.title }}</a></strong></div>
             </td>
         </tr>
     </thead>
@@ -27,11 +27,19 @@
                     {% autoescape false %}
                     {{ forum.description|markup }}
                     {% endautoescape %}
-                    <br />
-                    <!--
-                    <strong>Sub Forums:</strong> <a href="#" title="">Subforum 1</a>, <a href="#" title="">Subforum 2</a>
-                     -->
                 </div>
+                {% if forum.children|length %}
+                <div class="forum-subforums">
+                    <ul class="list-inline">
+                        <li><strong>Subforums:</strong></li>
+                        {% for subforum in forum.children %}
+                        <li>
+                            <a href="{{ url_for('forum.view_forum', forum_id=subforum.id) }}">{{ subforum.title }}</a>
+                        </li>
+                        {% endfor %}
+                    </ul>
+                </div>
+                {% endif %}
             </td>
 
             <td valign="top" align="center" style="white-space: nowrap">{{ forum.topic_count }}</td>

+ 70 - 1
flaskbb/templates/forum/forum.html

@@ -7,7 +7,9 @@
 
 <ol class="breadcrumb">
     <li><a href="{{ url_for('forum.index') }}">Forum</a></li>
-    <li><a href="{{ url_for('forum.view_category', category_id=forum.parent_id) }}">{{ forum.parent.title }}</a></li>
+    {% for breadcrumb_item in forum.get_breadcrumbs() %}
+        <li><a href="{{ url_for('forum.view_forum', forum_id=breadcrumb_item.id) }}">{{ breadcrumb_item.title }}</a></li>
+    {% endfor %}
     <li class="active">{{ forum.title }}</li>
 </ol>
 
@@ -20,6 +22,72 @@
     <a href="{{ url_for('forum.new_topic', forum_id=forum.id) }}" class="btn btn-primary">New Topic</a>
 </div>
 {% endif %}
+{% if forum.children|length %}
+<table class="table table-bordered">
+    <thead>
+        <tr>
+            <th colspan="5">
+                Subforums
+            </th>
+        </tr>
+        <tr>
+            <th colspan="2">Forum</th>
+            <th width="85" align="center" style="white-space: nowrap">Topics</th>
+            <th width="85" align="center" style="white-space: nowrap">Posts</th>
+            <th width="200" align="center" style="white-space: nowrap">Last Post</th>
+        </tr>
+    </thead>
+
+    <tbody>
+        {% for subforum in forum.children %}
+        <tr>
+            <td align="center" valign="center" width="1">
+                New </br> Posts
+            </td>
+
+            <td valign="top">
+                <strong><a href="{{ url_for('forum.view_forum', forum_id=subforum.id) }}">{{ subforum.title }}</a></strong>
+
+                <div class="forum-description">
+                    {% autoescape false %}
+                    {{ subforum.description|markup }}
+                    {% endautoescape %}
+                </div>
+                {% if subforum.children|length %}
+                <div class="forum-subforums">
+                    <ul class="list-inline">
+                        <li><strong>Subforums:</strong></li>
+                        {% for subforum2 in subforum.children %}
+                        <li>
+                            <a href="{{ url_for('forum.view_forum', forum_id=subforum2.id) }}">{{ subforum2.title }}</a>
+                        </li>
+                        {% endfor %}
+                    </ul>
+                </div>
+                {% endif %}
+            </td>
+
+            <td valign="top" align="center" style="white-space: nowrap">{{ subforum.topic_count }}</td>
+            <td valign="top" align="center" style="white-space: nowrap">{{ subforum.post_count }}</td>
+
+            <td valign="top" align="right" style="white-space: nowrap">
+                {% if subforum.last_post_id %}
+                <a href="{{ url_for('forum.view_post', post_id=subforum.last_post_id) }}" title="{{ subforum.last_post.topic.title }}">
+                    <strong>{{ subforum.last_post.topic.title|crop_title }}</strong>
+                </a>
+                <br />
+                {{ subforum.last_post.date_created|time_since }}<br />
+                by <a href="{{ url_for('user.profile', username=subforum.last_post.user.username) }}">{{ subforum.last_post.user.username }}</a>
+                {% else %}
+                No posts
+                {% endif %}
+            </td>
+        </tr>
+        {% endfor %}
+    </tbody>
+</table>
+{% endif %}
+
 <table class="table table-bordered">
     <thead>
         <tr>
@@ -28,6 +96,7 @@
             </th>
         </tr>
     </thead>
+
     <tbody>
         <tr>
             <td colspan="2">Thread</td>

+ 5 - 2
flaskbb/templates/forum/new_post.html

@@ -7,8 +7,11 @@
 
 <ul class="breadcrumb">
     <li><a href="{{ url_for('forum.index') }}">Forum</a></li>
-    <li><a href="{{ url_for('forum.view_category', category_id=topic.forum.category.id) }}">{{ topic.forum.category.title }}</a></li>
-    <li><a href="{{ url_for('forum.view_forum', forum_id=topic.forum_id) }}">{{ topic.forum.title }}</a></li>
+    {% for breadcrumb_item in topic.forum.get_breadcrumbs() %}
+        <li><a href="{{ url_for('forum.view_forum', forum_id=breadcrumb_item.id) }}">{{ breadcrumb_item.title }}</a></li>
+    {% endfor %}
+
+    <li><a href="{{ url_for('forum.view_forum', forum_id=topic.forum.id) }}">{{ topic.forum.title }}</a></li>
     <li><a href="{{ url_for('forum.view_topic', topic_id=topic.id) }}">{{ topic.title }} </a></li>
     <li class="active">New Post</li>
 </ul>

+ 5 - 2
flaskbb/templates/forum/new_topic.html

@@ -7,8 +7,11 @@
 
 <ul class="breadcrumb">
     <li><a href="{{ url_for('forum.index') }}">Forum</a></li>
-    <li><a href="{{ url_for('forum.view_category', category_id=forum.category_id) }}">{{ forum.category.title }}</a></li>
-    <li><a href="{{ url_for('forum.view_forum', forum_id=forum.id) }}">{{ forum.title }}</a> </li>
+    {% for breadcrumb_item in forum.get_breadcrumbs() %}
+        <li><a href="{{ url_for('forum.view_forum', forum_id=breadcrumb_item.id) }}">{{ breadcrumb_item.title }}</a></li>
+    {% endfor %}
+
+    <li><a href="{{ url_for('forum.view_forum', forum_id=forum.id) }}">{{ forum.title }}</a></li>
     <li class="active">New Topic</li>
 </ul>
 

+ 5 - 2
flaskbb/templates/forum/topic.html

@@ -7,8 +7,11 @@
 
 <ol class="breadcrumb">
     <li><a href="{{ url_for('forum.index') }}">Forum</a></li>
-    <li><a href="{{ url_for('forum.view_category', category_id=topic.forum.category.id) }}">{{ topic.forum.category.title }}</a></li>
-    <li><a href="{{ url_for('forum.view_forum', forum_id=topic.forum_id) }}">{{ topic.forum.title }}</a></li>
+    {% for breadcrumb_item in topic.forum.get_breadcrumbs() %}
+        <li><a href="{{ url_for('forum.view_forum', forum_id=breadcrumb_item.id) }}">{{ breadcrumb_item.title }}</a></li>
+    {% endfor %}
+
+    <li><a href="{{ url_for('forum.view_forum', forum_id=topic.forum.id) }}">{{ topic.forum.title }}</a></li>
     <li class="active">{{ topic.title }}</li>
 </ol>