Source

antibot-forms / templatetags / antibot_comments_tags.py

Full commit
from django import template
from django.template import TemplateSyntaxError
from antibot-forms.forms import CommentForm
from django.conf import settings
from django.utils.hashcompat import sha_constructor
import time

register = template.Library()

def generate_initial(obj):
    timestamp = int(time.time())
    initial = {'content_type':obj._meta, 'object_pk':obj._get_pk_val(), 'timestamp':str(timestamp)}
    info = (str(obj._meta), str(obj._get_pk_val()), str(timestamp), settings.SECRET_KEY)
    initial.update({'security_hash':sha_constructor("".join(info)).hexdigest()})
    #initial.update({'next':'/comments/done/'})
    return initial

@register.inclusion_tag("comments/form.html", takes_context=True)
def comment_form(context,obj):
    frm = CommentForm(context['request'], initial=generate_initial(obj))
    return {'frm':frm}