Django

Code

Changeset 1328

Show
Ignore:
Timestamp:
11/21/05 04:41:54 (3 years ago)
Author:
hugo
Message:

fixes #753 - ValidationError? and CriticalValidationError? now accept both strings and promises from gettext_lazy

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/validators.py

    r1202 r1328  
    2828from django.conf.settings import JING_PATH 
    2929from django.utils.translation import gettext_lazy, ngettext 
     30from django.utils.functional import Promise 
    3031 
    3132class ValidationError(Exception): 
     
    3536            self.messages = message 
    3637        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)) 
    3839            self.messages = [message] 
    3940    def __str__(self): 
     
    5051            self.messages = message 
    5152        else: 
    52             assert isinstance(message, basestring), ("'%s' should be a string" % message) 
     53            assert isinstance(message, (basestring, Promise)), ("'%s' should be a string" % message) 
    5354            self.messages = [message] 
    5455    def __str__(self): 
  • django/trunk/django/utils/functional.py

    r1098 r1328  
    33        return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items())) 
    44    return _curried 
     5 
     6class 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 
    513 
    614def lazy(func, *resultclasses): 
     
    1119    function is evaluated on every access. 
    1220    """ 
    13     class __proxy__
     21    class __proxy__(Promise)
    1422        # This inner class encapsulates the code that should be evaluated 
    1523        # lazily. On calling of one of the magic methods it will force