def get_disqus_sso(request, user): # create a JSON packet of our data attributes output = ["""<script type="text/javascript"> var disqus_config = function() {"""] if user.is_authenticated(): data = json.dumps({ 'id': user.pk, 'username': user.get_full_name(), 'email': user.email, # Link comments to members where possible 'url': "{domain}{member_url}".format(domain=Site.objects.get_current().domain, member_url=user.member.get_absolute_url()) if user.member else None, }) # encode the data to base64 message = base64.b64encode(data) # generate a timestamp for signing the message timestamp = int(time.time()) # generate our hmac signature sig = hmac.HMAC(settings.DISQUS_SECRET_KEY, '%s %s' % (message, timestamp), hashlib.sha1).hexdigest() output.append(""" this.page.remote_auth_s3 = "%(message)s %(sig)s %(timestamp)s"; """ % dict( message=message, timestamp=timestamp, sig=sig, pub_key=settings.DISQUS_PUBLIC_KEY )) output.append(""" this.page.api_key = "%(pub_key)s"; // This adds the custom login/logout functionality this.sso = { name: "CSHC", button: "%(static_url)smedia/disqus-sso-login-button.gif", icon: "%(static_url)simg/favicon.png", url: "//%(domain)s%(login_url)s", logout: "//%(domain)s%(logout_url)s?next=%(current_url)s", width: "360", height: "480" }; }; </script>""" % dict( pub_key=settings.DISQUS_PUBLIC_KEY, static_url=get_absolute_static_url(request), domain=Site.objects.get_current().domain, login_url=reverse('auth_login'), logout_url=reverse('auth_logout'), current_url=request.get_full_path())) return "".join(output)
def cshc_get_recent_entries(context, number=5, template='zinnia/tags/entries_recent.html'): """ Return the most recent blog entries. """ return {'request': context['request'], 'template': template, 'absolute_static_url': get_absolute_static_url(context['request']), 'entries': Entry.published.all()[:number]}