Commits

Matthew Schinckel committed 49b5686

Instead of raising a ValueError during form validation, raise a ValidationError.
This means that the error will be shown properly to the user.

  • Participants
  • Parent commits f8eb9ca
  • Tags 0.6.4

Comments (0)

Files changed (3)

 
 Changes
 --------
+
+0.6.4: Raise a ValidationError on a badly formed UUID string, rather than ValueError, in ``UUIDField.clean``.
+
 0.6.1: Treat the deprecation warning from django 1.3+
 
 setup(
     name = "django-uuidfield-2",
-    version = "0.6.3",
+    version = "0.6.4",
     description = "UUIDField for django models",
     url = "http://bitbucket.org/schinckel/django-uuidfield/",
     author = "Matthew Schinckel",

File uuidfield/fields.py

+from django.core.validators import RegexValidator
 from django.forms.util import ValidationError
 from django import forms
 from django.db import models
             data = unicode(val)
         return data
     
+    def clean(self, value, initial=None):
+        if isinstance(value, uuid.UUID):
+            return value
+        try:
+            return uuid.UUID(value)
+        except ValueError, arg:
+            raise forms.ValidationError(arg.args[0])
+        
 try:
     from south.modelsinspector import add_introspection_rules
 except ImportError: