antibot-forms / templatetags / antibot_comments_tags.py

from django import template
from django.template import TemplateSyntaxError
from nexgen_comments.forms import NexGenCommentForm
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 = NexGenCommentForm(context['request'], initial=generate_initial(obj))
    return {'frm':frm}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.