Ticket #16986: model-clean-errordict-2.diff
File model-clean-errordict-2.diff, 2.0 KB (added by , 13 years ago) |
---|
-
django/forms/models.py
330 330 try: 331 331 self.instance.clean() 332 332 except ValidationError, e: 333 self._update_errors({NON_FIELD_ERRORS: e.messages}) 333 if e.has_message_dict: 334 self._update_errors(e.message_dict) 335 else: 336 self._update_errors({NON_FIELD_ERRORS: e.messages}) 334 337 335 338 # Validate uniqueness if needed. 336 339 if self._validate_unique: -
django/core/exceptions.py
59 59 self.params = params 60 60 message = force_unicode(message) 61 61 self.messages = [message] 62 62 63 @property 64 def has_message_dict(self): 65 return hasattr(self, 'message_dict') 66 63 67 def __str__(self): 64 68 # This is needed because, without a __str__(), printing an exception 65 69 # instance would result in this: 66 70 # AttributeError: ValidationError instance has no attribute 'args' 67 71 # See http://www.python.org/doc/current/tut/node10.html#handling 68 if hasattr(self, 'message_dict'):72 if self.has_message_dict: 69 73 return repr(self.message_dict) 70 74 return repr(self.messages) 71 75 72 76 def __repr__(self): 73 if hasattr(self, 'message_dict'):77 if self.has_message_dict: 74 78 return 'ValidationError(%s)' % repr(self.message_dict) 75 79 return 'ValidationError(%s)' % repr(self.messages) 76 80 77 81 def update_error_dict(self, error_dict): 78 if hasattr(self, 'message_dict'):82 if self.has_message_dict: 79 83 if error_dict: 80 84 for k, v in self.message_dict.items(): 81 85 error_dict.setdefault(k, []).extend(v)