Exemple #1
0
 def __init__(self, **kwargs):
     self.max_length = kwargs.pop("max_length", None)
     super().__init__(**kwargs)
     if self.max_length is not None:
         message = lazy_format(self.error_messages["max_length"],
                               max_length=self.max_length)
         self.validators.append(
             MaxLengthValidator(self.max_length, message=message))
Exemple #2
0
 def test_it_formats_lazily(self):
     message = mock.Mock(wraps='message')
     formatted = lazy_format(message)
     assert message.format.call_count == 0
     str(formatted)
     assert message.format.call_count == 1
     str(formatted)
     assert message.format.call_count == 1
Exemple #3
0
 def __str__(self):
     return lazy_format(_('Profile: {email}, {name}'), email=self.email, name=self.name)
Exemple #4
0
 def test_it_formats_correctly(self):
     formatted = lazy_format('Does {} work? {answer}: %s', 'it', answer='Yes')
     assert str(formatted) == 'Does it work? Yes: %s'
     assert formatted % 'it does' == 'Does it work? Yes: it does'
Exemple #5
0
 def __str__(self):
     return lazy_format(_('User: {email}'), email=self.email)