Commits

Scott Nixon committed 431f77a

add captcha

Comments (0)

Files changed (7)

run/captcha/__init__.py

+from captcha.models import CommentWithCaptcha
+from captcha.forms import CommentFormWithCaptcha
+
+def get_model():
+    return CommentWithCaptcha
+
+def get_form():
+    return CommentFormWithCaptcha

run/captcha/forms.py

+from django import forms
+from django.contrib.comments.forms import CommentForm
+from captcha.models import CommentWithCaptcha
+#added for captcha
+from hhv3 import fields as hh_captcha
+
+
+class CommentFormWithCaptcha(CommentForm):
+	#line below adds captcha
+	recaptcha = hh_captcha.ReCaptchaField()
+	def get_comment_model(self):
+		# Use our custom comment model instead of the built-in one.
+		return CommentWithCaptcha
+
+	def get_comment_create_data(self):
+        # Use the data of the superclass, and add in the title field
+		data = super(CommentFormWithCaptcha, self).get_comment_create_data()
+		return data
+

run/captcha/models.py

+from django.db import models
+from django.contrib.comments.models import Comment
+
+class CommentWithCaptcha(Comment):
+	pass

run/captcha/tests.py

+"""
+This file demonstrates two different styles of tests (one doctest and one
+unittest). These will both pass when you run "manage.py test".
+
+Replace these with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+class SimpleTest(TestCase):
+    def test_basic_addition(self):
+        """
+        Tests that 1 + 1 always equals 2.
+        """
+        self.failUnlessEqual(1 + 1, 2)
+
+__test__ = {"doctest": """
+Another way to test that 1 + 1 is equal to 2.
+
+>>> 1 + 1 == 2
+True
+"""}
+

run/captcha/views.py

+# Create your views here.

run/contact/forms.py

 from django import forms
 #added for captcha
-from run import fields as hh_captcha
+import fields as hh_captcha
 
 class ContactForm(forms.Form):
 	subject = forms.CharField(label='Subject', max_length=100)
 # Django settings for run project.
 
-DEBUG = True
+DEBUG = False
 TEMPLATE_DEBUG = DEBUG
 
 TIME_ZONE = 'America/New_York'
     'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
+    'maintenancemode.middleware.MaintenanceModeMiddleware',
 )
 
 ROOT_URLCONF = 'run.urls'