Browse Source

Use last_post instead of topic.last_post

Peter Justin 7 years ago
parent
commit
f89da19853

+ 12 - 9
flaskbb/forum/views.py

@@ -570,15 +570,18 @@ class TopicTracker(MethodView):
 
     def get(self):
         page = request.args.get('page', 1, type=int)
-        topics = real(current_user).tracked_topics.outerjoin(
-            TopicsRead,
-            db.and_(
-                TopicsRead.topic_id == Topic.id,
-                TopicsRead.user_id == real(current_user).id
-            )
-        ).add_entity(TopicsRead).order_by(Topic.last_updated.desc()).paginate(
-            page, flaskbb_config['TOPICS_PER_PAGE'], True
-        )
+        topics = real(current_user).tracked_topics.\
+            outerjoin(
+                TopicsRead,
+                db.and_(
+                    TopicsRead.topic_id == Topic.id,
+                    TopicsRead.user_id == real(current_user).id
+                )).\
+            outerjoin(Post, Topic.last_post_id == Post.id).\
+            add_entity(Post).\
+            add_entity(TopicsRead).\
+            order_by(Topic.last_updated.desc()).\
+            paginate(page, flaskbb_config['TOPICS_PER_PAGE'], True)
 
         return render_template('forum/topictracker.html', topics=topics)
 

+ 5 - 5
flaskbb/templates/forum/edit_forum.html

@@ -35,7 +35,7 @@
                     <div class="col-md-1 col-sm-1 col-xs-2 topic-select-all"><input type="checkbox" name="rowtoggle" class="action-checkall" title="Select All"/></div>
                 </div>
 
-                {% for topic, topicread in topics.items %}
+                {% for topic, last_post, topicread in topics.items %}
                 <div class="row forum-row hover clearfix">
 
                     <div class="col-md-4 col-sm-4 col-xs-6 topic-info">
@@ -85,14 +85,14 @@
                     </div>
 
                     <div class="col-md-3 col-sm-3 col-xs-4 topic-last-post">
-                        <a href="{{ topic.last_post.url }}">{{ topic.last_post.date_created|time_since }}</a><br />
+                        <a href="{{ last_post.url }}">{{ last_post.date_created|time_since }}</a><br />
 
                         <div class="topic-author">
                             {% trans %}by{% endtrans %}
-                            {% if topic.last_post.user_id %}
-                            <a href="{{ topic.last_post.user.url }}">{{ topic.last_post.user.username }}</a>
+                            {% if last_post.user_id %}
+                            <a href="{{ last_post.user.url }}">{{ last_post.user.username }}</a>
                             {% else %}
-                            {{ topic.last_post.username }}
+                            {{ last_post.username }}
                             {% endif %}
                         </div>
                     </div>

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

@@ -109,14 +109,14 @@
                 </div>
 
                 <div class="col-md-3 col-sm-3 col-xs-4 topic-last-post">
-                    <a href="{{ topic.last_post.url }}">{{ topic.last_post.date_created|time_since }}</a><br />
+                    <a href="{{ last_post.url }}">{{ last_post.date_created|time_since }}</a><br />
 
                     <div class="topic-author">
                         {% trans %}by{% endtrans %}
-                        {% if topic.last_post.user_id %}
-                        <a href="{{ topic.last_post.user.url }}">{{ topic.last_post.user.username }}</a>
+                        {% if last_post.user_id %}
+                        <a href="{{ last_post.user.url }}">{{ last_post.user.username }}</a>
                         {% else %}
-                        {{ topic.last_post.username }}
+                        {{ last_post.username }}
                         {% endif %}
                     </div>
                 </div>

+ 5 - 5
flaskbb/templates/forum/topictracker.html

@@ -35,7 +35,7 @@
                     <div class="col-md-1 col-sm-1 col-xs-2 topic-select-all"><input type="checkbox" name="rowtoggle" class="action-checkall" title="Select All"/></div>
                 </div>
 
-                {% for topic, topicread in topics.items %}
+                {% for topic, last_post, topicread in topics.items %}
                 <div class="row forum-row hover clearfix">
 
                     <div class="col-md-4 col-sm-4 col-xs-6 topic-info">
@@ -85,14 +85,14 @@
                     </div>
 
                     <div class="col-md-3 col-sm-3 col-xs-4 topic-last-post">
-                        <a href="{{ topic.last_post.url }}">{{ topic.last_post.date_created|time_since }}</a><br />
+                        <a href="{{ last_post.url }}">{{ last_post.date_created|time_since }}</a><br />
 
                         <div class="topic-author">
                             {% trans %}by{% endtrans %}
-                            {% if topic.last_post.user_id %}
-                            <a href="{{ topic.last_post.user.url }}">{{ topic.last_post.user.username }}</a>
+                            {% if last_post.user_id %}
+                            <a href="{{ last_post.user.url }}">{{ last_post.user.username }}</a>
                             {% else %}
-                            {{ topic.last_post.username }}
+                            {{ last_post.username }}
                             {% endif %}
                         </div>
                     </div>