diff PersonasBackend/personas/forms.py @ 94:e1bfeffce0f0

Added an 'I accept the terms of use' checkbox to Persona submission.
author Atul Varma <varmaa@toolness.com>
date Thu, 27 Mar 2008 19:55:37 -0700
parents c5d76a735410
children b42e3997fe58
line wrap: on
line diff
--- a/PersonasBackend/personas/forms.py	Thu Mar 27 18:21:22 2008 -0700
+++ b/PersonasBackend/personas/forms.py	Thu Mar 27 19:55:37 2008 -0700
@@ -1,4 +1,4 @@
-from django.newforms import ModelForm, ValidationError
+import django.newforms as forms
 from PersonasBackend.personas import models
 
 def newforms_validator( func ):
@@ -14,11 +14,11 @@
         try:
             return func( *args, **kwargs )
         except ValueError, e:
-            raise ValidationError( e.message )
+            raise forms.ValidationError( e.message )
 
     return wrapper
 
-class PersonaForm( ModelForm ):
+class PersonaForm( forms.ModelForm ):
     """
     Form given to normal users who don't have the permission to
     publish Personas.
@@ -28,6 +28,19 @@
         model = models.Persona
         exclude = ["owner", "date_published", "popularity", "status"]
 
+    agree_to_terms = forms.BooleanField(
+        label = "I agree to the terms of use.",
+        # TODO: setting required to True doesn't seem to have any effect,
+        # but the Django docs say it should ensure that the checkbox
+        # is filled out.
+        required = True,
+        help_text = ("Terms of use: I agree that Mozilla is providing "
+                     "a service by hosting the "
+                     "content I am submitting, and that they are in no "
+                     "way responsible for any damages that occur as "
+                     "a result of hosting said content.")
+        )
+
     @newforms_validator
     def _color_cleaner( self, field ):
         models.ensure_color_is_valid( self.cleaned_data[field] )
@@ -45,5 +58,10 @@
         newforms_validator(
             models.ensure_header_and_footer_are_valid
             )( form_data )
+        if not self.cleaned_data["agree_to_terms"]:
+            raise forms.ValidationError(
+                "You must agree to the terms of service to "
+                "submit your Persona."
+                )
 
         return self.cleaned_data