]> git.openstreetmap.org Git - osqa.git/blobdiff - forum_modules/localauth/forms.py
the mark_favorite view should accept not only Questions but any Nodes (required for...
[osqa.git] / forum_modules / localauth / forms.py
index 9529bbaa24fcea3feeb36de01eb6f8d2e05cdefd..ee6157775ae867d52e3d6889b7aa8f31fa1f7c24 100644 (file)
@@ -17,15 +17,23 @@ class ClassicRegisterForm(SetPasswordForm):
     def __init__(self, *args, **kwargs):
         super(ClassicRegisterForm, self).__init__(*args, **kwargs)
 
-        spam_fields = call_all_handlers('create_anti_spam_field')
-        if spam_fields:
-            spam_fields = dict(spam_fields)
-            for name, field in spam_fields.items():
-                self.fields[name] = field
-
-            self._anti_spam_fields = spam_fields.keys()
-        else:
-            self._anti_spam_fields = []
+        # Try importing the ReCapthca public and private keys, Import Error will be raised in case it has been disabled
+        try:
+            from forum.settings import RECAPTCHA_PUB_KEY, RECAPTCHA_PRIV_KEY
+            recaptcha_enabled = len(str(RECAPTCHA_PUB_KEY.value)) > 0 and len(str(RECAPTCHA_PRIV_KEY.value)) > 0
+        except ImportError:
+            recaptcha_enabled = False
+
+        if recaptcha_enabled:
+            spam_fields = call_all_handlers('create_anti_spam_field')
+            if spam_fields:
+                spam_fields = dict(spam_fields)
+                for name, field in spam_fields.items():
+                    self.fields[name] = field
+
+                self._anti_spam_fields = spam_fields.keys()
+            else:
+                self._anti_spam_fields = []
 
     def anti_spam_fields(self):
         return [self[name] for name in self._anti_spam_fields]