Implement pagination feature for blog_post_listing and blog_dashboard pages.
authorAditi Mittal <aditi.iitr@gmail.com>
Mon, 2 Sep 2013 16:28:17 +0000 (21:58 +0530)
committerAditi Mittal <aditi.iitr@gmail.com>
Mon, 2 Sep 2013 16:28:17 +0000 (21:58 +0530)
mediagoblin/media_types/blog/templates/mediagoblin/blog/blog_admin_dashboard.html
mediagoblin/media_types/blog/templates/mediagoblin/blog/blog_post_listing.html
mediagoblin/media_types/blog/views.py

index 5ce838bf91c746314cd8dfa77dfc5fba45dfa9b9..c553988c2c3e616f4e017d3cb80e94fd29fea745 100644 (file)
@@ -17,6 +17,7 @@
 #}
 
 {% extends "mediagoblin/base.html" %}
+{% from "mediagoblin/utils/pagination.html" import render_pagination %}
 
 {% block title -%}
 {{blog.title}} Dashboard &mdash; {{ super() }}
@@ -50,7 +51,7 @@
 </a>
 </p>
 <h2> Blog Post Entries </h2>
-    {% if blog_post_count!=0 %}
+    {% if blog_posts_list.count() %}
      <table class="media_panel processing">
         <tr>
             <th>Title</th>
@@ -90,6 +91,7 @@
     {% else %}
         {% trans %} No blog post yet. {% endtrans %}
     {% endif %}
+    {{ render_pagination(request, pagination) }}
 {% endblock %}
      
 
index ea712bb06daea7bf992bfa02b8f6a36be9e7417a..184693d9f7cd602e596b07d6f179c8bfaf718673 100644 (file)
@@ -18,6 +18,7 @@
 {% extends "mediagoblin/base.html" %}
 
 {% import "/mediagoblin/utils/wtforms.html" as wtforms_util %}
+{% from "mediagoblin/utils/pagination.html" import render_pagination %}
 
 {% block title -%}
   {% trans %}{{ blog_owner }} 's Blog{% endtrans %} &mdash; {{ super() }}
@@ -45,4 +46,5 @@
             </br>
         {% endfor %}
     </div>
+    {{ render_pagination(request, pagination) }}
 {% endblock %}
index a0ceb064e4a5a2075cf0d9a6647c5658c50a9b61..d5522f3e79bafe282b4229d848d5a1b7a9dcc1f8 100644 (file)
@@ -206,33 +206,36 @@ def blogpost_edit(request):
         })    
 
 @require_active_login
-def blog_dashboard(request):
+@uses_pagination
+def blog_dashboard(request, page):
     
     url_user = request.matchdict.get('user')
     blog_slug = request.matchdict.get('blog_slug', None)
-    _log.info(blog_slug)
-
+    
     blog = request.db.Blog.query.filter_by(slug=blog_slug).first()
    
     if not blog:
         return render_404(request)
    
-    blog_posts_list = blog.get_all_posts_of_a_blog(None)
-    blog_post_count = blog_posts_list.count()
+    blog_posts_list = blog.get_all_posts_of_a_blog().order_by(MediaEntry.created.desc())
+    pagination = Pagination(page, blog_posts_list)
+    pagination.per_page = 15
+    blog_posts_on_a_page = pagination()
 
     if may_edit_blogpost(request, blog):
         return render_to_response(
         request,
         'mediagoblin/blog/blog_admin_dashboard.html',
-        {'blog_posts_list': blog_posts_list,
+        {'blog_posts_list': blog_posts_on_a_page,
         'blog_slug':blog_slug,
         'blog':blog,
-        'blog_post_count':blog_post_count
+        'pagination':pagination 
         })                                                                                                   
     
 
 #supposed to list all the blog posts belonging to a particular blog of particular user.
-def blog_post_listing(request):
+@uses_pagination
+def blog_post_listing(request, page):
     
     blog_owner = request.matchdict.get('user')
     blog_slug = request.matchdict.get('blog_slug', None)
@@ -242,12 +245,16 @@ def blog_post_listing(request):
     if not owner_user or not blog:
         return render_404(request)
     
-    all_blog_posts = blog.get_all_posts_of_a_blog(u'processed')
+    all_blog_posts = blog.get_all_posts_of_a_blog(u'processed').order_by(MediaEntry.created.desc())
+    pagination = Pagination(page, all_blog_posts)
+    pagination.per_page = 8
+    blog_posts_on_a_page = pagination()
     
     return render_to_response(
         request,
         'mediagoblin/blog/blog_post_listing.html',
-        {'blog_posts': all_blog_posts,
+        {'blog_posts': blog_posts_on_a_page,
+         'pagination': pagination,
          'blog_owner': blog_owner
         })