summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHonza Král <honza.kral@gmail.com>2009-08-05 01:28:39 +0000
committerHonza Král <honza.kral@gmail.com>2009-08-05 01:28:39 +0000
commitb7e064207c27fcdd1b97617c18c0d3331b34d2c8 (patch)
treeb4e172201c5a64148f35a5c9f8ffdcd14c80f586
parenta604fc39d0ae834622103ac0559a8acddeb6105a (diff)
[soc2009/model-validation] remove lazily translated strings for pickling of db fields
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@11399 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/db/models/fields/__init__.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index 2f974974f0..8b53cd95c3 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -112,6 +112,35 @@ class Field(object):
messages.update(error_messages or {})
self.error_messages = messages
+ def __getstate__(self):
+ """
+ Pickling support.
+ """
+ from django.utils.functional import Promise
+ obj_dict = self.__dict__.copy()
+ items = []
+ translated_keys = []
+ for k, v in self.error_messages.items():
+ if isinstance(v, Promise):
+ args = getattr(v, '_proxy____args', None)
+ if args:
+ translated_keys.append(k)
+ v = args[0]
+ items.append((k,v))
+ obj_dict['_translated_keys'] = translated_keys
+ obj_dict['error_messages'] = dict(items)
+ return obj_dict
+
+ def __setstate__(self, obj_dict):
+ """
+ Unpickling support.
+ """
+ translated_keys = obj_dict.pop('_translated_keys')
+ self.__dict__.update(obj_dict)
+ for k in translated_keys:
+ self.error_messages[k] = _(self.error_messages[k])
+
+
def __cmp__(self, other):
# This is needed because bisect does not take a comparison function.
return cmp(self.creation_counter, other.creation_counter)