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

Fixed breadcrumbs; Moved the category layout in another file, so the same file can be used on the index view and categories view.

sh4nks 11 лет назад
Родитель
Сommit
976d1802a2

+ 2 - 1
flaskbb/forum/views.py

@@ -112,7 +112,7 @@ def view_category(category_id):
                        for category, forum in forum_query]
 
     category = get_forums(forum_query)
-    return render_template("forum/category.html", category=category)
+    return render_template("forum/category.html", categories=category)
 
 
 @forum.route("/forum/<int:forum_id>")
@@ -122,6 +122,7 @@ def view_forum(forum_id):
     if current_user.is_authenticated():
         forum = Forum.query.\
             filter(Forum.id == forum_id).\
+            options(db.joinedload("category")).\
             outerjoin(ForumsRead,
                       db.and_(ForumsRead.forum_id == Forum.id,
                               ForumsRead.user_id == current_user.id)).\

+ 5 - 64
flaskbb/templates/forum/category.html

@@ -1,73 +1,14 @@
+{% set page_title = categories.keys()[0].title %}
+{% 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.keys()[0].title }}</li>
+    <li class="active">{{ categories.keys()[0].title }}</li>
 </ol>
 
-{% for category in category.iteritems() %}
-<table class="table table-bordered">
-    <thead class="categoryhead">
-        <tr>
-            <td colspan="5">
-                <div><strong><a href="{{ url_for('forum.view_category', category_id=category[0].id) }}">{{ category[0].title }}</a></strong></div>
-            </td>
-        </tr>
-    </thead>
-    <tbody class="forumbody">
-        <tr class="forum_stats">
-            <td colspan="2"><strong>Forum</strong></td>
-            <td width="85" align="center" style="white-space: nowrap"><strong>Topics</strong></td>
-            <td width="85" align="center" style="white-space: nowrap"><strong>Posts</strong></td>
-            <td width="200" align="center" style="white-space: nowrap"><strong>Last Post</strong></td>
-        </tr>
-
-        {% for forum in category[1] %}
-        <tr>
-            <td align="center" valign="center" width="4%">
-
-            {% if forum[0]|forum_is_unread(forum[1], current_user) %}
-                <span class="fa fa-comments" style="font-size: 2em"></span>
-            {% else %}
-                <span class="fa fa-comments-o" style="font-size: 2em"></span>
-            {% endif %}
-
-            </td>
-
-            <td valign="top">
-                <strong><a href="{{ url_for('forum.view_forum', forum_id=forum[0].id) }}">{{ forum[0].title }}</a></strong>
-
-                <div class="forum-description">
-                    {% autoescape false %}
-                    {{ forum[0].description|markup }}
-                    {% endautoescape %}
-                </div>
-            </td>
-
-            <td valign="top" align="center" style="white-space: nowrap">{{ forum[0].topic_count }}</td>
-            <td valign="top" align="center" style="white-space: nowrap">{{ forum[0].post_count }}</td>
-
-            <td valign="top" align="right" style="white-space: nowrap">
-                {% if forum[0].last_post_id %}
-                <a href="{{ url_for('forum.view_post', post_id=forum[0].last_post_id) }}" title="{{ forum[0].last_post.topic.title }}">
-                    <strong>{{ forum[0].last_post.topic.title|crop_title }}</strong>
-                </a>
-                <br />
-                {{ forum[0].last_post.date_created|time_since }}<br />
-                    {% if forum[0].last_post.user_id %}
-                    by <a href="{{ url_for('user.profile', username=forum[0].last_post.user.username) }}">{{ forum[0].last_post.user.username }}</a>
-                    {% else %}
-                    {{ forum[0].last_post.username }}
-                    {% endif %}
-                {% else %}
-                No posts
-                {% endif %}
-            </td>
-        </tr>
-        {% endfor %}
+{% include "forum/category_layout.html" %}
 
-    </tbody>
-</table>
-{% endfor %}
 {% endblock %}

+ 74 - 0
flaskbb/templates/forum/category_layout.html

@@ -0,0 +1,74 @@
+{% for category in categories.iteritems() %}
+<table class="table table-bordered">
+    <thead class="categoryhead">
+        <tr>
+            <td colspan="5">
+                <div><strong><a href="{{ url_for('forum.view_category', category_id=category[0].id) }}">{{ category[0].title }}</a></strong></div>
+            </td>
+        </tr>
+    </thead>
+    <tbody class="forumbody">
+        <tr class="forum_stats">
+            <td colspan="2"><strong>Forum</strong></td>
+            <td width="85" align="center" style="white-space: nowrap"><strong>Topics</strong></td>
+            <td width="85" align="center" style="white-space: nowrap"><strong>Posts</strong></td>
+            <td width="200" align="center" style="white-space: nowrap"><strong>Last Post</strong></td>
+        </tr>
+
+        {% for forum in category[1] %}
+        <tr>
+            <td align="center" valign="center" width="4%">
+
+            {% if forum[0]|forum_is_unread(forum[1], current_user) %}
+                <span class="fa fa-comments" style="font-size: 2em"></span>
+            {% else %}
+                <span class="fa fa-comments-o" style="font-size: 2em"></span>
+            {% endif %}
+
+            </td>
+
+            <td valign="top">
+                <strong><a href="{{ url_for('forum.view_forum', forum_id=forum[0].id) }}">{{ forum[0].title }}</a></strong>
+
+                <div class="forum-description">
+                    {% autoescape false %}
+                    {{ forum[0].description|markup }}
+                    {% endautoescape %}
+                    {% if forum[0].show_moderators %}
+                    <div class="forum-moderators">
+                        Moderators:
+                        {% for moderator in forum[0].moderators %}
+                        <a href="{{ url_for('user.profile', username=moderator.username) }}">{{ moderator.username }}</a>{% if not loop.last %}, {% endif %}
+                        {% endfor %}
+                    </div>
+                    {% endif %}
+                </div>
+            </td>
+
+            <td valign="top" align="center" style="white-space: nowrap">{{ forum[0].topic_count }}</td>
+            <td valign="top" align="center" style="white-space: nowrap">{{ forum[0].post_count }}</td>
+
+            <td valign="top" align="right" style="white-space: nowrap">
+                {% if forum[0].last_post_id %}
+                <a href="{{ url_for('forum.view_post', post_id=forum[0].last_post_id) }}" title="{{ forum[0].last_post.topic.title }}">
+                    <strong>{{ forum[0].last_post.topic.title|crop_title }}</strong>
+                </a>
+                <br />
+                {{ forum[0].last_post.date_created|time_since }}<br />
+
+                    {% if forum[0].last_post.user_id %}
+                    by <a href="{{ url_for('user.profile', username=forum[0].last_post.user.username) }}">{{ forum[0].last_post.user.username }}</a>
+                    {% else %}
+                    {{ forum[0].last_post.username }}
+                    {% endif %}
+
+                {% else %}
+                No posts
+                {% endif %}
+            </td>
+        </tr>
+        {% endfor %}
+
+    </tbody>
+</table>
+{% endfor %}

+ 3 - 4
flaskbb/templates/forum/forum.html

@@ -1,4 +1,4 @@
-{% set page_title = forum[0].title ~ " - Forum" %}
+{% set page_title = forum[0].title %}
 {% set active_forum_nav=True %}
 
 {% extends "layout.html" %}
@@ -7,6 +7,7 @@
 
 <ol class="breadcrumb">
     <li><a href="{{ url_for('forum.index') }}">Forum</a></li>
+    <li><a href="{{ url_for('forum.view_category', category_id=forum[0].category.id) }}">{{ forum[0].category.title }}</a></li>
     <li class="active">{{ forum[0].title }}</li>
 </ol>
 
@@ -14,7 +15,7 @@
     {{ render_pagination(topics, url_for('forum.view_forum', forum_id=forum[0].id)) }}
 </div> <!-- end span pagination -->
 
-{% if current_user|post_topic(forum[0]) and not forum[0].is_category %}
+{% if current_user|post_topic(forum[0]) %}
 <div class="pull-right" style="padding-bottom: 10px">
     <!-- star tick pencil -->
     <div class="btn-group">
@@ -28,7 +29,6 @@
 </div>
 {% endif %}
 
-{% if not forum[0].is_category %}
 <table class="table table-bordered">
     <thead>
         <tr>
@@ -102,6 +102,5 @@
 
     </tbody>
 </table>
-{% endif %}
 
 {% endblock %}

+ 1 - 74
flaskbb/templates/forum/index.html

@@ -5,80 +5,7 @@
     <li><a href="{{ url_for('forum.index') }}">Forum</a></li>
 </ol>
 
-{% for category in categories.iteritems() %}
-<table class="table table-bordered">
-    <thead class="categoryhead">
-        <tr>
-            <td colspan="5">
-                <div><strong><a href="{{ url_for('forum.view_category', category_id=category[0].id) }}">{{ category[0].title }}</a></strong></div>
-            </td>
-        </tr>
-    </thead>
-    <tbody class="forumbody">
-        <tr class="forum_stats">
-            <td colspan="2"><strong>Forum</strong></td>
-            <td width="85" align="center" style="white-space: nowrap"><strong>Topics</strong></td>
-            <td width="85" align="center" style="white-space: nowrap"><strong>Posts</strong></td>
-            <td width="200" align="center" style="white-space: nowrap"><strong>Last Post</strong></td>
-        </tr>
-
-        {% for forum in category[1] %}
-        <tr>
-            <td align="center" valign="center" width="4%">
-
-            {% if forum[0]|forum_is_unread(forum[1], current_user) %}
-                <span class="fa fa-comments" style="font-size: 2em"></span>
-            {% else %}
-                <span class="fa fa-comments-o" style="font-size: 2em"></span>
-            {% endif %}
-
-            </td>
-
-            <td valign="top">
-                <strong><a href="{{ url_for('forum.view_forum', forum_id=forum[0].id) }}">{{ forum[0].title }}</a></strong>
-
-                <div class="forum-description">
-                    {% autoescape false %}
-                    {{ forum[0].description|markup }}
-                    {% endautoescape %}
-                    {% if forum[0].show_moderators %}
-                    <div class="forum-moderators">
-                        Moderators:
-                        {% for moderator in forum[0].moderators %}
-                        <a href="{{ url_for('user.profile', username=moderator.username) }}">{{ moderator.username }}</a>{% if not loop.last %}, {% endif %}
-                        {% endfor %}
-                    </div>
-                    {% endif %}
-                </div>
-            </td>
-
-            <td valign="top" align="center" style="white-space: nowrap">{{ forum[0].topic_count }}</td>
-            <td valign="top" align="center" style="white-space: nowrap">{{ forum[0].post_count }}</td>
-
-            <td valign="top" align="right" style="white-space: nowrap">
-                {% if forum[0].last_post_id %}
-                <a href="{{ url_for('forum.view_post', post_id=forum[0].last_post_id) }}" title="{{ forum[0].last_post.topic.title }}">
-                    <strong>{{ forum[0].last_post.topic.title|crop_title }}</strong>
-                </a>
-                <br />
-                {{ forum[0].last_post.date_created|time_since }}<br />
-
-                    {% if forum[0].last_post.user_id %}
-                    by <a href="{{ url_for('user.profile', username=forum[0].last_post.user.username) }}">{{ forum[0].last_post.user.username }}</a>
-                    {% else %}
-                    {{ forum[0].last_post.username }}
-                    {% endif %}
-
-                {% else %}
-                No posts
-                {% endif %}
-            </td>
-        </tr>
-        {% endfor %}
-
-    </tbody>
-</table>
-{% endfor %}
+{% include "forum/category_layout.html" %}
 
 <!-- Forum Stats -->
 <table class="table table-bordered">

+ 1 - 0
flaskbb/templates/forum/topic.html

@@ -7,6 +7,7 @@
 
 <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>
     <li class="active">{{ topic.title }}</li>
 </ol>