Ticket #4152: 4152.cumulative.diff
File 4152.cumulative.diff, 16.7 KB (added by , 18 years ago) |
---|
-
django/db/models/fields/__init__.py
8 8 from django.utils.functional import curry 9 9 from django.utils.itercompat import tee 10 10 from django.utils.text import capfirst 11 from django.utils.translation import gettext,gettext_lazy11 from django.utils.translation import ugettext, ugettext_lazy 12 12 import datetime, os, time 13 13 14 14 class NOT_PROVIDED: … … 39 39 return 40 40 if getattr(self, 'original_object', None) and self.original_object._get_pk_val() == old_obj._get_pk_val(): 41 41 return 42 raise validators.ValidationError, gettext("%(optname)s with this %(fieldname)s already exists.") % {'optname': capfirst(opts.verbose_name), 'fieldname': f.verbose_name}42 raise validators.ValidationError, ugettext("%(optname)s with this %(fieldname)s already exists.") % {'optname': capfirst(opts.verbose_name), 'fieldname': f.verbose_name} 43 43 44 44 # A guide to Field parameters: 45 45 # … … 114 114 Subclasses should implement validate(), not validate_full(). 115 115 """ 116 116 if not self.blank and not field_data: 117 return [ gettext_lazy('This field is required.')]117 return [ugettext_lazy('This field is required.')] 118 118 try: 119 119 self.validate(field_data, all_data) 120 120 except validators.ValidationError, e: … … 271 271 core_field_names.extend(f.get_manipulator_field_names(name_prefix)) 272 272 # Now, if there are any, add the validator to this FormField. 273 273 if core_field_names: 274 params['validator_list'].append(validators.RequiredIfOtherFieldsGiven(core_field_names, gettext_lazy("This field is required.")))274 params['validator_list'].append(validators.RequiredIfOtherFieldsGiven(core_field_names, ugettext_lazy("This field is required."))) 275 275 276 276 # Finally, add the field_names. 277 277 field_names = self.get_manipulator_field_names(name_prefix) … … 364 364 try: 365 365 return int(value) 366 366 except (TypeError, ValueError): 367 raise validators.ValidationError, gettext("This value must be an integer.")367 raise validators.ValidationError, ugettext("This value must be an integer.") 368 368 369 369 def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False, follow=True): 370 370 if not rel: … … 399 399 if value in (True, False): return value 400 400 if value in ('t', 'True', '1'): return True 401 401 if value in ('f', 'False', '0'): return False 402 raise validators.ValidationError, gettext("This value must be either True or False.")402 raise validators.ValidationError, ugettext("This value must be either True or False.") 403 403 404 404 def get_manipulator_field_objs(self): 405 405 return [oldforms.CheckboxField] … … 420 420 if self.null: 421 421 return value 422 422 else: 423 raise validators.ValidationError, gettext_lazy("This field cannot be null.")423 raise validators.ValidationError, ugettext_lazy("This field cannot be null.") 424 424 return str(value) 425 425 426 426 def formfield(self, **kwargs): … … 454 454 try: 455 455 return datetime.date(*time.strptime(value, '%Y-%m-%d')[:3]) 456 456 except ValueError: 457 raise validators.ValidationError, gettext('Enter a valid date in YYYY-MM-DD format.')457 raise validators.ValidationError, ugettext('Enter a valid date in YYYY-MM-DD format.') 458 458 459 459 def get_db_prep_lookup(self, lookup_type, value): 460 460 if lookup_type == 'range': … … 523 523 try: 524 524 return datetime.datetime(*time.strptime(value, '%Y-%m-%d')[:3]) 525 525 except ValueError: 526 raise validators.ValidationError, gettext('Enter a valid date/time in YYYY-MM-DD HH:MM format.')526 raise validators.ValidationError, ugettext('Enter a valid date/time in YYYY-MM-DD HH:MM format.') 527 527 528 528 def get_db_prep_save(self, value): 529 529 # Casts dates into string format for entry into database. … … 607 607 self.always_test = True 608 608 def __call__(self, field_data, all_data): 609 609 if not all_data.get(self.other_file_field_name, False): 610 c = validators.RequiredIfOtherFieldsGiven(self.other_field_names, gettext_lazy("This field is required."))610 c = validators.RequiredIfOtherFieldsGiven(self.other_field_names, ugettext_lazy("This field is required.")) 611 611 c(field_data, all_data) 612 612 # First, get the core fields, if any. 613 613 core_field_names = [] … … 618 618 if core_field_names: 619 619 field_list[0].validator_list.append(RequiredFileField(core_field_names, field_list[1].field_name)) 620 620 else: 621 v = validators.RequiredIfOtherFieldNotGiven(field_list[1].field_name, gettext_lazy("This field is required."))621 v = validators.RequiredIfOtherFieldNotGiven(field_list[1].field_name, ugettext_lazy("This field is required.")) 622 622 v.always_test = True 623 623 field_list[0].validator_list.append(v) 624 624 field_list[0].is_required = field_list[1].is_required = False … … 748 748 if value in ('None'): return None 749 749 if value in ('t', 'True', '1'): return True 750 750 if value in ('f', 'False', '0'): return False 751 raise validators.ValidationError, gettext("This value must be either None, True or False.")751 raise validators.ValidationError, ugettext("This value must be either None, True or False.") 752 752 753 753 def get_manipulator_field_objs(self): 754 754 return [oldforms.NullBooleanField] -
django/templatetags/i18n.py
40 40 if self.noop: 41 41 return value 42 42 else: 43 return translation. gettext(value)43 return translation.ugettext(value) 44 44 45 45 class BlockTranslateNode(Node): 46 46 def __init__(self, extra_context, singular, plural=None, countervar=None, counter=None): … … 68 68 count = self.counter.resolve(context) 69 69 context[self.countervar] = count 70 70 plural = self.render_token_list(self.plural) 71 result = translation. ngettext(singular, plural, count) % context71 result = translation.ungettext(singular, plural, count) % context 72 72 else: 73 result = translation. gettext(singular) % context73 result = translation.ugettext(singular) % context 74 74 context.pop() 75 75 return result 76 76 -
django/newforms/fields.py
2 2 Field classes 3 3 """ 4 4 5 from django.utils.translation import gettext5 from django.utils.translation import ugettext 6 6 from django.utils.encoding import smart_unicode 7 7 from util import ErrorList, ValidationError 8 8 from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple … … 77 77 Raises ValidationError for any errors. 78 78 """ 79 79 if self.required and value in EMPTY_VALUES: 80 raise ValidationError( gettext(u'This field is required.'))80 raise ValidationError(ugettext(u'This field is required.')) 81 81 return value 82 82 83 83 def widget_attrs(self, widget): … … 100 100 return u'' 101 101 value = smart_unicode(value) 102 102 if self.max_length is not None and len(value) > self.max_length: 103 raise ValidationError( gettext(u'Ensure this value has at most %d characters.') % self.max_length)103 raise ValidationError(ugettext(u'Ensure this value has at most %d characters.') % self.max_length) 104 104 if self.min_length is not None and len(value) < self.min_length: 105 raise ValidationError( gettext(u'Ensure this value has at least %d characters.') % self.min_length)105 raise ValidationError(ugettext(u'Ensure this value has at least %d characters.') % self.min_length) 106 106 return value 107 107 108 108 def widget_attrs(self, widget): … … 125 125 try: 126 126 value = int(value) 127 127 except (ValueError, TypeError): 128 raise ValidationError( gettext(u'Enter a whole number.'))128 raise ValidationError(ugettext(u'Enter a whole number.')) 129 129 if self.max_value is not None and value > self.max_value: 130 raise ValidationError( gettext(u'Ensure this value is less than or equal to %s.') % self.max_value)130 raise ValidationError(ugettext(u'Ensure this value is less than or equal to %s.') % self.max_value) 131 131 if self.min_value is not None and value < self.min_value: 132 raise ValidationError( gettext(u'Ensure this value is greater than or equal to %s.') % self.min_value)132 raise ValidationError(ugettext(u'Ensure this value is greater than or equal to %s.') % self.min_value) 133 133 return value 134 134 135 135 DEFAULT_DATE_INPUT_FORMATS = ( … … 162 162 return datetime.date(*time.strptime(value, format)[:3]) 163 163 except ValueError: 164 164 continue 165 raise ValidationError( gettext(u'Enter a valid date.'))165 raise ValidationError(ugettext(u'Enter a valid date.')) 166 166 167 167 DEFAULT_TIME_INPUT_FORMATS = ( 168 168 '%H:%M:%S', # '14:30:59' … … 189 189 return datetime.time(*time.strptime(value, format)[3:6]) 190 190 except ValueError: 191 191 continue 192 raise ValidationError( gettext(u'Enter a valid time.'))192 raise ValidationError(ugettext(u'Enter a valid time.')) 193 193 194 194 DEFAULT_DATETIME_INPUT_FORMATS = ( 195 195 '%Y-%m-%d %H:%M:%S', # '2006-10-25 14:30:59' … … 225 225 return datetime.datetime(*time.strptime(value, format)[:6]) 226 226 except ValueError: 227 227 continue 228 raise ValidationError( gettext(u'Enter a valid date/time.'))228 raise ValidationError(ugettext(u'Enter a valid date/time.')) 229 229 230 230 class RegexField(Field): 231 231 def __init__(self, regex, max_length=None, min_length=None, error_message=None, *args, **kwargs): … … 239 239 regex = re.compile(regex) 240 240 self.regex = regex 241 241 self.max_length, self.min_length = max_length, min_length 242 self.error_message = error_message or gettext(u'Enter a valid value.')242 self.error_message = error_message or ugettext(u'Enter a valid value.') 243 243 244 244 def clean(self, value): 245 245 """ … … 253 253 if value == u'': 254 254 return value 255 255 if self.max_length is not None and len(value) > self.max_length: 256 raise ValidationError( gettext(u'Ensure this value has at most %d characters.') % self.max_length)256 raise ValidationError(ugettext(u'Ensure this value has at most %d characters.') % self.max_length) 257 257 if self.min_length is not None and len(value) < self.min_length: 258 raise ValidationError( gettext(u'Ensure this value has at least %d characters.') % self.min_length)258 raise ValidationError(ugettext(u'Ensure this value has at least %d characters.') % self.min_length) 259 259 if not self.regex.search(value): 260 260 raise ValidationError(self.error_message) 261 261 return value … … 268 268 class EmailField(RegexField): 269 269 def __init__(self, max_length=None, min_length=None, *args, **kwargs): 270 270 RegexField.__init__(self, email_re, max_length, min_length, 271 gettext(u'Enter a valid e-mail address.'), *args, **kwargs)271 ugettext(u'Enter a valid e-mail address.'), *args, **kwargs) 272 272 273 273 url_re = re.compile( 274 274 r'^https?://' # http:// or https:// … … 286 286 class URLField(RegexField): 287 287 def __init__(self, max_length=None, min_length=None, verify_exists=False, 288 288 validator_user_agent=URL_VALIDATOR_USER_AGENT, *args, **kwargs): 289 super(URLField, self).__init__(url_re, max_length, min_length, gettext(u'Enter a valid URL.'), *args, **kwargs)289 super(URLField, self).__init__(url_re, max_length, min_length, ugettext(u'Enter a valid URL.'), *args, **kwargs) 290 290 self.verify_exists = verify_exists 291 291 self.user_agent = validator_user_agent 292 292 … … 308 308 req = urllib2.Request(value, None, headers) 309 309 u = urllib2.urlopen(req) 310 310 except ValueError: 311 raise ValidationError( gettext(u'Enter a valid URL.'))311 raise ValidationError(ugettext(u'Enter a valid URL.')) 312 312 except: # urllib2.URLError, httplib.InvalidURL, etc. 313 raise ValidationError( gettext(u'This URL appears to be a broken link.'))313 raise ValidationError(ugettext(u'This URL appears to be a broken link.')) 314 314 return value 315 315 316 316 class BooleanField(Field): … … 361 361 return value 362 362 valid_values = set([str(k) for k, v in self.choices]) 363 363 if value not in valid_values: 364 raise ValidationError( gettext(u'Select a valid choice. That choice is not one of the available choices.'))364 raise ValidationError(ugettext(u'Select a valid choice. That choice is not one of the available choices.')) 365 365 return value 366 366 367 367 class MultipleChoiceField(ChoiceField): … … 373 373 Validates that the input is a list or tuple. 374 374 """ 375 375 if self.required and not value: 376 raise ValidationError( gettext(u'This field is required.'))376 raise ValidationError(ugettext(u'This field is required.')) 377 377 elif not self.required and not value: 378 378 return [] 379 379 if not isinstance(value, (list, tuple)): 380 raise ValidationError( gettext(u'Enter a list of values.'))380 raise ValidationError(ugettext(u'Enter a list of values.')) 381 381 new_value = [] 382 382 for val in value: 383 383 val = smart_unicode(val) … … 386 386 valid_values = set([smart_unicode(k) for k, v in self.choices]) 387 387 for val in new_value: 388 388 if val not in valid_values: 389 raise ValidationError( gettext(u'Select a valid choice. %s is not one of the available choices.') % val)389 raise ValidationError(ugettext(u'Select a valid choice. %s is not one of the available choices.') % val) 390 390 return new_value 391 391 392 392 class ComboField(Field): … … 449 449 clean_data = [] 450 450 errors = ErrorList() 451 451 if self.required and not value: 452 raise ValidationError( gettext(u'This field is required.'))452 raise ValidationError(ugettext(u'This field is required.')) 453 453 elif not self.required and not value: 454 454 return self.compress([]) 455 455 if not isinstance(value, (list, tuple)): 456 raise ValidationError( gettext(u'Enter a list of values.'))456 raise ValidationError(ugettext(u'Enter a list of values.')) 457 457 for i, field in enumerate(self.fields): 458 458 try: 459 459 field_value = value[i] 460 460 except KeyError: 461 461 field_value = None 462 462 if self.required and field_value in EMPTY_VALUES: 463 raise ValidationError( gettext(u'This field is required.'))463 raise ValidationError(ugettext(u'This field is required.')) 464 464 try: 465 465 clean_data.append(field.clean(field_value)) 466 466 except ValidationError, e: -
tests/modeltests/validation/models.py
42 42 43 43 >>> p = Person(**dict(valid_params, id='foo')) 44 44 >>> p.validate() 45 {'id': [ 'This value must be an integer.']}45 {'id': [u'This value must be an integer.']} 46 46 47 47 >>> p = Person(**dict(valid_params, id=None)) 48 48 >>> p.validate() … … 76 76 77 77 >>> p = Person(**dict(valid_params, is_child='foo')) 78 78 >>> p.validate() 79 {'is_child': [ 'This value must be either True or False.']}79 {'is_child': [u'This value must be either True or False.']} 80 80 81 81 >>> p = Person(**dict(valid_params, name=u'Jose')) 82 82 >>> p.validate() … … 148 148 149 149 # Make sure that Date and DateTime return validation errors and don't raise Python errors. 150 150 >>> Person(name='John Doe', is_child=True, email='abc@def.com').validate() 151 {'favorite_moment': [ 'This field is required.'], 'birthdate': ['This field is required.']}151 {'favorite_moment': [u'This field is required.'], 'birthdate': [u'This field is required.']} 152 152 153 153 """}