Ticket #1987: django-utf8string.patch
File django-utf8string.patch, 2.5 KB (added by , 18 years ago) |
---|
-
django/db/models/base.py
110 110 if kwargs: 111 111 raise TypeError, "'%s' is an invalid keyword argument for this function" % kwargs.keys()[0] 112 112 for i, arg in enumerate(args): 113 setattr(self, self._meta.fields[i].attname, arg) 113 f = self._meta.fields[i] 114 setattr(self, f.attname, f.get_db_post_load(arg)) 114 115 dispatcher.send(signal=signals.post_init, sender=self.__class__, instance=self) 115 116 116 117 def add_to_class(cls, name, value): -
django/db/models/fields/__init__.py
156 156 "Returns field's value just before saving." 157 157 return value 158 158 159 def get_db_post_load(self, value): 160 "Returns field's value after loading from a database onto memory." 161 return value 162 159 163 def get_db_prep_save(self, value): 160 164 "Returns field's value prepared for saving into a database." 161 165 return value … … 385 389 raise validators.ValidationError, gettext_lazy("This field cannot be null.") 386 390 return str(value) 387 391 392 # for handling of "utf-8" encoding (hironobu@nerv.or.jp,20060524) 393 class UTF8StringField(CharField): 394 def get_manipulator_field_objs(self): 395 return [forms.TextField] 396 397 def get_internal_type(self): 398 return "CharField" 399 400 def get_db_post_load(self, value): 401 if value is not None: 402 value = value.decode('utf-8') 403 return Field.get_db_post_load(self, value) 404 405 def get_db_prep_lookup(self, lookup_type, value): 406 if value is not None: 407 value = value.decode('utf-8') 408 return Field.get_db_prep_lookup(self, lookup_type, value) 409 410 def to_python(self, value): 411 if isinstance(value, basestring): 412 return value.decode('utf-8') 413 if value is None: 414 if self.null: 415 return value 416 else: 417 raise validators.ValidationError, gettext_lazy("This field cannot be null.") 418 return value.decode('utf-8') 419 388 420 # TODO: Maybe move this into contrib, because it's specialized. 389 421 class CommaSeparatedIntegerField(CharField): 390 422 def get_manipulator_field_objs(self):