1+ import os
2+
13from django import template
24from django .conf import settings
5+ from django .template .loader import get_template
36
47register = template .Library ()
58
@@ -9,7 +12,6 @@ def recaptcha_key():
912 return settings .RECAPTCHA_PUBLIC_KEY
1013
1114
12- @register .inclusion_tag ('snowpenguin/recaptcha/recaptcha_init.html' )
1315def recaptcha_init (public_key = None ):
1416
1517 return {
@@ -19,7 +21,6 @@ def recaptcha_init(public_key=None):
1921 }
2022
2123
22- @register .inclusion_tag ('snowpenguin/recaptcha/recaptcha_ready.html' )
2324def recaptcha_ready (public_key = None , action_name = None , custom_callback = None ):
2425 return {
2526 'public_key' : public_key or settings .RECAPTCHA_PUBLIC_KEY ,
@@ -28,10 +29,23 @@ def recaptcha_ready(public_key=None, action_name=None, custom_callback=None):
2829 }
2930
3031
31- @register .inclusion_tag ('snowpenguin/recaptcha/recaptcha_execute.html' )
3232def recaptcha_execute (public_key = None , action_name = None , custom_callback = None ):
3333 return {
3434 'public_key' : public_key or settings .RECAPTCHA_PUBLIC_KEY ,
3535 'action_name' : action_name or settings .RECAPTCHA_DEFAULT_ACTION ,
3636 'custom_callback' : custom_callback
3737 }
38+
39+
40+ def return_empty_context (* args , ** kwargs ):
41+ return ''
42+
43+
44+ if not os .environ .get ('RECAPTCHA_DISABLE' , None ):
45+ register .inclusion_tag (get_template ('snowpenguin/recaptcha/recaptcha_init.html' ))(recaptcha_init )
46+ register .inclusion_tag (get_template ('snowpenguin/recaptcha/recaptcha_ready.html' ))(recaptcha_ready )
47+ register .inclusion_tag (get_template ('snowpenguin/recaptcha/recaptcha_execute.html' ))(recaptcha_execute )
48+ else :
49+ register .simple_tag (return_empty_context , name = 'recaptcha_init' )
50+ register .simple_tag (return_empty_context , name = 'recaptcha_ready' )
51+ register .simple_tag (return_empty_context , name = 'recaptcha_execute' )
0 commit comments