Ticket #4152: 4152.cumulative.diff

File 4152.cumulative.diff, 16.7 KB (added by Ivan Sagalaev <Maniac@…>, 17 years ago)

Cumulative patch

  • django/db/models/fields/__init__.py

     
    88from django.utils.functional import curry
    99from django.utils.itercompat import tee
    1010from django.utils.text import capfirst
    11 from django.utils.translation import gettext, gettext_lazy
     11from django.utils.translation import ugettext, ugettext_lazy
    1212import datetime, os, time
    1313
    1414class NOT_PROVIDED:
     
    3939        return
    4040    if getattr(self, 'original_object', None) and self.original_object._get_pk_val() == old_obj._get_pk_val():
    4141        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}
    4343
    4444# A guide to Field parameters:
    4545#
     
    114114        Subclasses should implement validate(), not validate_full().
    115115        """
    116116        if not self.blank and not field_data:
    117             return [gettext_lazy('This field is required.')]
     117            return [ugettext_lazy('This field is required.')]
    118118        try:
    119119            self.validate(field_data, all_data)
    120120        except validators.ValidationError, e:
     
    271271                    core_field_names.extend(f.get_manipulator_field_names(name_prefix))
    272272            # Now, if there are any, add the validator to this FormField.
    273273            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.")))
    275275
    276276        # Finally, add the field_names.
    277277        field_names = self.get_manipulator_field_names(name_prefix)
     
    364364        try:
    365365            return int(value)
    366366        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.")
    368368
    369369    def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False, follow=True):
    370370        if not rel:
     
    399399        if value in (True, False): return value
    400400        if value in ('t', 'True', '1'): return True
    401401        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.")
    403403
    404404    def get_manipulator_field_objs(self):
    405405        return [oldforms.CheckboxField]
     
    420420            if self.null:
    421421                return value
    422422            else:
    423                 raise validators.ValidationError, gettext_lazy("This field cannot be null.")
     423                raise validators.ValidationError, ugettext_lazy("This field cannot be null.")
    424424        return str(value)
    425425
    426426    def formfield(self, **kwargs):
     
    454454        try:
    455455            return datetime.date(*time.strptime(value, '%Y-%m-%d')[:3])
    456456        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.')
    458458
    459459    def get_db_prep_lookup(self, lookup_type, value):
    460460        if lookup_type == 'range':
     
    523523                try:
    524524                    return datetime.datetime(*time.strptime(value, '%Y-%m-%d')[:3])
    525525                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.')
    527527
    528528    def get_db_prep_save(self, value):
    529529        # Casts dates into string format for entry into database.
     
    607607                        self.always_test = True
    608608                    def __call__(self, field_data, all_data):
    609609                        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."))
    611611                            c(field_data, all_data)
    612612                # First, get the core fields, if any.
    613613                core_field_names = []
     
    618618                if core_field_names:
    619619                    field_list[0].validator_list.append(RequiredFileField(core_field_names, field_list[1].field_name))
    620620            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."))
    622622                v.always_test = True
    623623                field_list[0].validator_list.append(v)
    624624                field_list[0].is_required = field_list[1].is_required = False
     
    748748        if value in ('None'): return None
    749749        if value in ('t', 'True', '1'): return True
    750750        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.")
    752752
    753753    def get_manipulator_field_objs(self):
    754754        return [oldforms.NullBooleanField]
  • django/templatetags/i18n.py

     
    4040        if self.noop:
    4141            return value
    4242        else:
    43             return translation.gettext(value)
     43            return translation.ugettext(value)
    4444
    4545class BlockTranslateNode(Node):
    4646    def __init__(self, extra_context, singular, plural=None, countervar=None, counter=None):
     
    6868            count = self.counter.resolve(context)
    6969            context[self.countervar] = count
    7070            plural = self.render_token_list(self.plural)
    71             result = translation.ngettext(singular, plural, count) % context
     71            result = translation.ungettext(singular, plural, count) % context
    7272        else:
    73             result = translation.gettext(singular) % context
     73            result = translation.ugettext(singular) % context
    7474        context.pop()
    7575        return result
    7676
  • django/newforms/fields.py

     
    22Field classes
    33"""
    44
    5 from django.utils.translation import gettext
     5from django.utils.translation import ugettext
    66from django.utils.encoding import smart_unicode
    77from util import ErrorList, ValidationError
    88from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple
     
    7777        Raises ValidationError for any errors.
    7878        """
    7979        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.'))
    8181        return value
    8282
    8383    def widget_attrs(self, widget):
     
    100100            return u''
    101101        value = smart_unicode(value)
    102102        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)
    104104        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)
    106106        return value
    107107
    108108    def widget_attrs(self, widget):
     
    125125        try:
    126126            value = int(value)
    127127        except (ValueError, TypeError):
    128             raise ValidationError(gettext(u'Enter a whole number.'))
     128            raise ValidationError(ugettext(u'Enter a whole number.'))
    129129        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)
    131131        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)
    133133        return value
    134134
    135135DEFAULT_DATE_INPUT_FORMATS = (
     
    162162                return datetime.date(*time.strptime(value, format)[:3])
    163163            except ValueError:
    164164                continue
    165         raise ValidationError(gettext(u'Enter a valid date.'))
     165        raise ValidationError(ugettext(u'Enter a valid date.'))
    166166
    167167DEFAULT_TIME_INPUT_FORMATS = (
    168168    '%H:%M:%S',     # '14:30:59'
     
    189189                return datetime.time(*time.strptime(value, format)[3:6])
    190190            except ValueError:
    191191                continue
    192         raise ValidationError(gettext(u'Enter a valid time.'))
     192        raise ValidationError(ugettext(u'Enter a valid time.'))
    193193
    194194DEFAULT_DATETIME_INPUT_FORMATS = (
    195195    '%Y-%m-%d %H:%M:%S',     # '2006-10-25 14:30:59'
     
    225225                return datetime.datetime(*time.strptime(value, format)[:6])
    226226            except ValueError:
    227227                continue
    228         raise ValidationError(gettext(u'Enter a valid date/time.'))
     228        raise ValidationError(ugettext(u'Enter a valid date/time.'))
    229229
    230230class RegexField(Field):
    231231    def __init__(self, regex, max_length=None, min_length=None, error_message=None, *args, **kwargs):
     
    239239            regex = re.compile(regex)
    240240        self.regex = regex
    241241        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.')
    243243
    244244    def clean(self, value):
    245245        """
     
    253253        if value == u'':
    254254            return value
    255255        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)
    257257        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)
    259259        if not self.regex.search(value):
    260260            raise ValidationError(self.error_message)
    261261        return value
     
    268268class EmailField(RegexField):
    269269    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    270270        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)
    272272
    273273url_re = re.compile(
    274274    r'^https?://' # http:// or https://
     
    286286class URLField(RegexField):
    287287    def __init__(self, max_length=None, min_length=None, verify_exists=False,
    288288            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)
    290290        self.verify_exists = verify_exists
    291291        self.user_agent = validator_user_agent
    292292
     
    308308                req = urllib2.Request(value, None, headers)
    309309                u = urllib2.urlopen(req)
    310310            except ValueError:
    311                 raise ValidationError(gettext(u'Enter a valid URL.'))
     311                raise ValidationError(ugettext(u'Enter a valid URL.'))
    312312            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.'))
    314314        return value
    315315
    316316class BooleanField(Field):
     
    361361            return value
    362362        valid_values = set([str(k) for k, v in self.choices])
    363363        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.'))
    365365        return value
    366366
    367367class MultipleChoiceField(ChoiceField):
     
    373373        Validates that the input is a list or tuple.
    374374        """
    375375        if self.required and not value:
    376             raise ValidationError(gettext(u'This field is required.'))
     376            raise ValidationError(ugettext(u'This field is required.'))
    377377        elif not self.required and not value:
    378378            return []
    379379        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.'))
    381381        new_value = []
    382382        for val in value:
    383383            val = smart_unicode(val)
     
    386386        valid_values = set([smart_unicode(k) for k, v in self.choices])
    387387        for val in new_value:
    388388            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)
    390390        return new_value
    391391
    392392class ComboField(Field):
     
    449449        clean_data = []
    450450        errors = ErrorList()
    451451        if self.required and not value:
    452             raise ValidationError(gettext(u'This field is required.'))
     452            raise ValidationError(ugettext(u'This field is required.'))
    453453        elif not self.required and not value:
    454454            return self.compress([])
    455455        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.'))
    457457        for i, field in enumerate(self.fields):
    458458            try:
    459459                field_value = value[i]
    460460            except KeyError:
    461461                field_value = None
    462462            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.'))
    464464            try:
    465465                clean_data.append(field.clean(field_value))
    466466            except ValidationError, e:
  • tests/modeltests/validation/models.py

     
    4242
    4343>>> p = Person(**dict(valid_params, id='foo'))
    4444>>> p.validate()
    45 {'id': ['This value must be an integer.']}
     45{'id': [u'This value must be an integer.']}
    4646
    4747>>> p = Person(**dict(valid_params, id=None))
    4848>>> p.validate()
     
    7676
    7777>>> p = Person(**dict(valid_params, is_child='foo'))
    7878>>> 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.']}
    8080
    8181>>> p = Person(**dict(valid_params, name=u'Jose'))
    8282>>> p.validate()
     
    148148
    149149# Make sure that Date and DateTime return validation errors and don't raise Python errors.
    150150>>> 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.']}
    152152
    153153"""}
Back to Top