@register.inclusion_tag('disqus/disqus_sso.html', takes_context=True)
def disqus_sso(context):
    """
    Return the HTML/js code to enable DISQUS SSO - so logged in users on
    your site can be logged in to disqus seemlessly.
    """

    DISQUS_SECRET_KEY = getattr(settings, 'DISQUS_SECRET_KEY', None)
    if DISQUS_SECRET_KEY is None:
        return "<p>You need to set DISQUS_SECRET_KEY before you can use SSO</p>"

    DISQUS_PUBLIC_KEY = getattr(settings, 'DISQUS_PUBLIC_KEY', None)
    if DISQUS_PUBLIC_KEY is None:
        return "<p>You need to set DISQUS_PUBLIC_KEY before you can use SSO</p>"

    user = context['user']

    if user.is_anonymous():
        return ""

    # create a JSON packet of our data attributes
    data = json.dumps({
        'id': user.id,
        'username': user.username,
        'email': user.email,
    })

    # encode the data to base64
    message = base64.b64encode(data.encode('utf-8'))

    # generate a timestamp for signing the message
    timestamp = int(time.time())

    key = DISQUS_SECRET_KEY.encode('utf-8')
    msg = ((message, timestamp) % '%s %s').encode('utf-8')
    digestmod = hashlib.sha1

    # generate our hmac signature
    sig = hmac.HMAC(key, msg, digestmod).hexdigest()

    return  dict(
        message=message,
        timestamp=timestamp,
        sig=sig,
        pub_key=DISQUS_PUBLIC_KEY,
    )
dataset/ETHPy150Open arthurk/django-disqus/disqus/templatetags/disqus_tags.py/disqus_sso/swapped operands of `%`