Browse Source

make the disqus_static plugin work for sites with over 25 comments

Ivan Dyedov 12 years ago
parent
commit
4e7a4bd592

+ 3 - 1
pelicanext/disqus_static/README.rst

@@ -9,6 +9,9 @@ Installation
 Because we use disqus API to retrieve the comments you need to create an application at
 Because we use disqus API to retrieve the comments you need to create an application at
 http://disqus.com/api/applications/ which will provide you with a secret and public keys for the API.
 http://disqus.com/api/applications/ which will provide you with a secret and public keys for the API.
 
 
+We use disqus-python package for communication with disqus API:
+``pip install disqus-python``
+
 Put ``disqus_static.py`` plugin in ``plugins`` folder in pelican installation 
 Put ``disqus_static.py`` plugin in ``plugins`` folder in pelican installation 
 and use the following in your settings::
 and use the following in your settings::
 
 
@@ -57,4 +60,3 @@ TODO
 -----
 -----
 
 
  - handle replies to comments properly and maintain parent-child relationships
  - handle replies to comments properly and maintain parent-child relationships
- - test for sites with over 100 comments (I think disqus API only returns 100 items per request)

+ 6 - 3
pelicanext/disqus_static/disqus_static.py

@@ -6,7 +6,7 @@ This plugin adds a disqus_comments property to all articles.
 Comments are fetched at generation time using disqus API.
 Comments are fetched at generation time using disqus API.
 """
 """
 
 
-from disqusapi import DisqusAPI
+from disqusapi import DisqusAPI, Paginator
 from pelican import signals
 from pelican import signals
 
 
 def initialized(pelican):
 def initialized(pelican):
@@ -20,11 +20,13 @@ def initialized(pelican):
 def disqus_static(generator):
 def disqus_static(generator):
     disqus = DisqusAPI(generator.settings['DISQUS_SECRET_KEY'], 
     disqus = DisqusAPI(generator.settings['DISQUS_SECRET_KEY'], 
                        generator.settings['DISQUS_PUBLIC_KEY'])
                        generator.settings['DISQUS_PUBLIC_KEY'])
-    threads = disqus.threads.list(forum=generator.settings['DISQUS_SITENAME'])
+    threads = Paginator(disqus.threads.list, 
+                        forum=generator.settings['DISQUS_SITENAME'])
     thread_dict = {} # disqus thread id => title
     thread_dict = {} # disqus thread id => title
     for thread in threads:
     for thread in threads:
         thread_dict[thread['id']] = thread['title']
         thread_dict[thread['id']] = thread['title']
-    posts = disqus.posts.list(forum=generator.settings['DISQUS_SITENAME'])
+
+    posts = Paginator(disqus.posts.list, forum=generator.settings['DISQUS_SITENAME'])
     post_dict = {} # title => [post1, post2, ...]
     post_dict = {} # title => [post1, post2, ...]
     for post in posts:
     for post in posts:
         if post['thread'] not in thread_dict.keys():
         if post['thread'] not in thread_dict.keys():
@@ -32,6 +34,7 @@ def disqus_static(generator):
         if thread_dict[post['thread']] not in post_dict.keys():
         if thread_dict[post['thread']] not in post_dict.keys():
             post_dict[thread_dict[post['thread']]] = []
             post_dict[thread_dict[post['thread']]] = []
         post_dict[thread_dict[post['thread']]].append(post)
         post_dict[thread_dict[post['thread']]].append(post)
+
     for article in generator.articles:
     for article in generator.articles:
         if article.title in post_dict:
         if article.title in post_dict:
             article.disqus_comments = post_dict[article.title]
             article.disqus_comments = post_dict[article.title]