Django

Code

Changeset 5489

Show
Ignore:
Timestamp:
06/17/07 21:23:24 (1 year ago)
Author:
mtredinnick
Message:

unicode: Implemented comparisons between *_lazy() objects. comparing
ugettext_lazy() instances to each other now works, for example.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/unicode/django/utils/functional.py

    r5420 r5489  
    6565                return Promise.__str__(self) 
    6666 
     67        def __cmp__(self, rhs): 
     68            if self._delegate_str: 
     69                s = str(self.__func(*self.__args, **self.__kw)) 
     70            elif self._delegate_unicode: 
     71                s = unicode(self.__func(*self.__args, **self.__kw)) 
     72            else: 
     73                s = self.__func(*self.__args, **self.__kw) 
     74            if isinstance(rhs, Promise): 
     75                return -cmp(rhs, s) 
     76            else: 
     77                return cmp(s, rhs) 
     78 
    6779        def __mod__(self, rhs): 
    6880            if self._delegate_str: 
  • django/branches/unicode/tests/regressiontests/i18n/tests.py

    r5420 r5489  
    22 
    33ur""" 
    4 >>> from django.utils.translation import ugettext_lazy, activate, deactivate 
     4Format string interpolation should work with *_lazy objects. 
     5 
     6>>> from django.utils.translation import ugettext_lazy, activate, deactivate, gettext_lazy 
    57>>> s = ugettext_lazy('Add %(name)s') 
    68>>> d = {'name': 'Ringo'} 
     
    1517>>> deactivate() 
    1618 
     19It should be possible to compare *_lazy objects. 
     20 
     21>>> s1 = ugettext_lazy('Add %(name)s') 
     22>>> s == s1 
     23True 
     24>>> s2 = gettext_lazy('Add %(name)s') 
     25>>> s3 = gettext_lazy('Add %(name)s') 
     26>>> s2 == s3 
     27True 
     28>>> s == s2 
     29True 
     30>>> s4 = ugettext_lazy('Some other string') 
     31>>> s == s4 
     32False 
    1733"""