def get_num_comments_with_disqus(blog_page, entry_page): try: from tapioca.exceptions import ClientError from tapioca_disqus import Disqus disqus_client = Disqus(api_secret=blog_page.disqus_api_secret) try: params = {'forum': blog_page.disqus_shortname, 'thread': 'ident:{}'.format(entry_page.id)} thread = disqus_client.threads_details().get(params=params) return thread.response.posts().data() except ClientError: return 0 except ImportError: raise Exception('You need to install tapioca-disqus before using Disqus as comment system.')
def post(self, request, entry_page_id, *args, **kwargs): try: entry_page = EntryPage.objects.get(pk=entry_page_id) blog_page = entry_page.blog_page disqus_client = Disqus(api_secret=blog_page.disqus_api_secret) try: params = {'forum': blog_page.disqus_shortname, 'thread': 'ident:{}'.format(entry_page_id)} thread = disqus_client.threads_details().get(params=params) entry_page.num_comments = thread.response.posts().data() entry_page.save() return HttpResponse() except ClientError: raise Http404 except EntryPage.DoesNotExist: raise Http404
def post(self, request, entry_page_id, *args, **kwargs): try: entry_page = EntryPage.objects.get(pk=entry_page_id) blog_page = entry_page.blog_page disqus_client = Disqus(api_secret=blog_page.disqus_api_secret) try: params = { 'forum': blog_page.disqus_shortname, 'thread': 'ident:{}'.format(entry_page_id) } thread = disqus_client.threads_details().get(params=params) entry_page.num_comments = thread.response.posts().data() entry_page.save() return HttpResponse() except ClientError: raise Http404 except EntryPage.DoesNotExist: raise Http404
def get_num_comments_with_disqus(blog_page, entry_page): try: from tapioca.exceptions import ClientError from tapioca_disqus import Disqus disqus_client = Disqus(api_secret=blog_page.disqus_api_secret) try: params = { 'forum': blog_page.disqus_shortname, 'thread': 'ident:{}'.format(entry_page.id) } thread = disqus_client.threads_details().get(params=params) return thread.response.posts().data() except ClientError: return 0 except ImportError: raise Exception( 'You need to install tapioca-disqus before using Disqus as comment system.' )