from django conf urls defaults import Uncomment the next two lines to

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Example:
# (r'^reChapterTest/', include('reChapterTest.foo.urls')),
# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
(r'test_app/', include('test_app.urls')),
(r'^comments/', include('django.contrib.comments.urls')),
)
# MAGIC code by Josh Vanderlinden (http://www.codekoala.com/blog/2008/adding-captcha-djangos-built-comments/)
from django.contrib.comments.forms import CommentForm
from test_app.recaptcha_newforms import RecaptchaField
from test_app.threadlocals import get_request
from django import forms
# self.fields['security_code'] = forms.CharField(label=req.META['REMOTE_ADDR'])
def add_captcha(func):
def wrapped(self, target_object, *args, **kwargs):
func(self, target_object, *args, **kwargs)
req = get_request()
if req:
self.fields['security_code'] = RecaptchaField(remote_ip = req.META['REMOTE_ADDR'])
return wrapped
CommentForm.__init__ = add_captcha(CommentForm.__init__)