Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fixes #753 - ValidationError and CriticalValidationError now accept b…

…oth strings and promises from gettext_lazy

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1328 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit e4e28d907aee9f0e3977e2c6237406d7746c5719 1 parent a49fa74
authored November 21, 2005
5  django/core/validators.py
@@ -27,6 +27,7 @@
27 27
 
28 28
 from django.conf.settings import JING_PATH
29 29
 from django.utils.translation import gettext_lazy, ngettext
  30
+from django.utils.functional import Promise
30 31
 
31 32
 class ValidationError(Exception):
32 33
     def __init__(self, message):
@@ -34,7 +35,7 @@ def __init__(self, message):
34 35
         if isinstance(message, list):
35 36
             self.messages = message
36 37
         else:
37  
-            assert isinstance(message, basestring), ("%s should be a string" % repr(message))
  38
+            assert isinstance(message, (basestring, Promise)), ("%s should be a string" % repr(message))
38 39
             self.messages = [message]
39 40
     def __str__(self):
40 41
         # This is needed because, without a __str__(), printing an exception
@@ -49,7 +50,7 @@ def __init__(self, message):
49 50
         if isinstance(message, list):
50 51
             self.messages = message
51 52
         else:
52  
-            assert isinstance(message, basestring), ("'%s' should be a string" % message)
  53
+            assert isinstance(message, (basestring, Promise)), ("'%s' should be a string" % message)
53 54
             self.messages = [message]
54 55
     def __str__(self):
55 56
         return str(self.messages)
10  django/utils/functional.py
@@ -3,6 +3,14 @@ def _curried(*moreargs, **morekwargs):
3 3
         return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items()))
4 4
     return _curried
5 5
 
  6
+class Promise:
  7
+    """
  8
+    This is just a base class for the proxy class created in
  9
+    the closure of the lazy function. It can be used to recognize
  10
+    promises in code.
  11
+    """
  12
+    pass
  13
+
6 14
 def lazy(func, *resultclasses):
7 15
     """
8 16
     Turns any callable into a lazy evaluated callable. You need to give result
@@ -10,7 +18,7 @@ def lazy(func, *resultclasses):
10 18
     the lazy evaluation code is triggered. Results are not memoized; the
11 19
     function is evaluated on every access.
12 20
     """
13  
-    class __proxy__:
  21
+    class __proxy__(Promise):
14 22
         # This inner class encapsulates the code that should be evaluated
15 23
         # lazily. On calling of one of the magic methods it will force
16 24
         # the evaluation and store the result. Afterwards, the result

0 notes on commit e4e28d9

Please sign in to comment.
Something went wrong with that request. Please try again.