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

Topics are now sorted in descending order.

sh4nks 10 лет назад
Родитель
Сommit
e2f4243d20
2 измененных файлов с 8 добавлено и 3 удалено
  1. 1 1
      flaskbb/plugins/portal/templates/index.html
  2. 7 2
      flaskbb/plugins/portal/views.py

+ 1 - 1
flaskbb/plugins/portal/templates/index.html

@@ -87,7 +87,7 @@
           </div>
           <div class="panel-body" style="padding-top: 0px">
 
-          {% for topic in news %}
+          {% for topic in news.items %}
             <h1><a href="{{ topic.url }}">{{ topic.title }}</a></h1>
             <ul class="portal-info">
                 <li><i class="fa fa-calendar"></i> {{ topic.date_created|format_date('%b %d %Y') }}</li>

+ 7 - 2
flaskbb/plugins/portal/views.py

@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from flask import Blueprint, current_app, flash
+from flask import Blueprint, current_app, flash, request
 from flaskbb.utils.helpers import render_template
 from flaskbb.forum.models import Topic, Post
 from flaskbb.user.models import User
@@ -15,6 +15,8 @@ def inject_portal_link():
 
 @portal.route("/")
 def index():
+    page = request.args.get('page', 1, type=int)
+
     try:
         forum_ids = flaskbb_config["PLUGIN_PORTAL_FORUM_IDS"]
     except KeyError:
@@ -22,7 +24,10 @@ def index():
         flash("Please install the plugin first to configure the forums "
               "which should be displayed", "warning")
 
-    news = Topic.query.filter(Topic.forum_id.in_(forum_ids)).all()
+    news = Topic.query.filter(Topic.forum_id.in_(forum_ids)).\
+        order_by(Topic.id.desc()).\
+        paginate(page, flaskbb_config["TOPICS_PER_PAGE"], True)
+
     recent_topics = Topic.query.order_by(Topic.date_created).limit(5).offset(0)
 
     user_count = User.query.count()