Browse Source

Adding pagination to blogs and agendas

jeremiewcz 1 year ago
parent
commit
0f55a48512
2 changed files with 17 additions and 3 deletions
  1. 1
    0
      .gitignore
  2. 16
    3
      app/main/views.py

+ 1
- 0
.gitignore View File

@@ -2,6 +2,7 @@ __pycache__
2 2
 *.pyc
3 3
 .DS_Store
4 4
 app/uploads/*
5
+app/static/podcasts/*
5 6
 venv/*
6 7
 doc/_build/
7 8
 .sass-cache

+ 16
- 3
app/main/views.py View File

@@ -57,7 +57,8 @@ def index():
57 57
            { "content": render_template("index.html",
58 58
                                         podcasts = Podcast.list(number=3),
59 59
                                         blog_posts = BlogPost.list(number=3),
60
-                                        events = Event.list(number=3)) } ]
60
+                                        events = Event.query.order_by(Event.begin.asc())\
61
+                                          .limit(5).all()) } ]
61 62
 
62 63
 
63 64
 #########################
@@ -163,9 +164,15 @@ def collective(id):
163 164
 @main.route('/blogs')
164 165
 @partial_content
165 166
 def blogs():
167
+    page = request.args.get('page', 1, type=int)
168
+    pagination = BlogPost.query                         \
169
+        .order_by(BlogPost.timestamp.desc())            \
170
+        .paginate(page, per_page=10, error_out=False)
171
+    blog_posts = pagination.items
166 172
     return [ 'displayMain',
167 173
              { "content": render_template("main_pages/blogs.html",
168
-                                          blog_posts = BlogPost.list(number=10)),
174
+                                          blog_posts = blog_posts,
175
+                                          pagination = pagination),
169 176
                "title": "Blogs",
170 177
                "description": "Les articles de blog de Radio Rhino" } ]
171 178
 
@@ -185,9 +192,15 @@ def blog(id):
185 192
 @main.route('/agendas')
186 193
 @partial_content
187 194
 def agendas():
195
+    page = request.args.get('page', 1, type=int)
196
+    pagination = Event.query                         \
197
+        .order_by(Event.begin.asc())            \
198
+        .paginate(page, per_page=10, error_out=False)
199
+    events = pagination.items
188 200
     return [ 'displayMain',
189 201
              { "content": render_template("main_pages/agendas.html",
190
-                                          events = Event.list(number=10)),
202
+                                          events = events,
203
+                                          pagination = pagination),
191 204
                "title": "Agendas" } ]
192 205
 
193 206
 @main.route('/agendas/<id>')

Loading…
Cancel
Save