Author: mtredinnick Date: 2010-09-10 14:24:24 -0500 (Fri, 10 Sep 2010) New Revision: 13721
Modified: django/trunk/AUTHORS django/trunk/django/utils/datastructures.py Log: Added more readable __str__ and __repr__ methods to MergeDict. Thanks, [email protected]. Fixed #3508. Modified: django/trunk/AUTHORS =================================================================== --- django/trunk/AUTHORS 2010-09-10 19:22:06 UTC (rev 13720) +++ django/trunk/AUTHORS 2010-09-10 19:24:24 UTC (rev 13721) @@ -238,6 +238,7 @@ [email protected] jdetaeye jhenry <[email protected]> + [email protected] Zak Johnson <[email protected]> Nis Jørgensen <[email protected]> Michael Josephson <http://www.sdjournal.com/> Modified: django/trunk/django/utils/datastructures.py =================================================================== --- django/trunk/django/utils/datastructures.py 2010-09-10 19:22:06 UTC (rev 13720) +++ django/trunk/django/utils/datastructures.py 2010-09-10 19:24:24 UTC (rev 13721) @@ -77,6 +77,27 @@ """Returns a copy of this object.""" return self.__copy__() + def __str__(self): + ''' + Returns something like + + "{'key1': 'val1', 'key2': 'val2', 'key3': 'val3'}" + + instead of the generic "<object meta-data>" inherited from object. + ''' + return str(dict(self.items())) + + def __repr__(self): + ''' + Returns something like + + MergeDict({'key1': 'val1', 'key2': 'val2'}, {'key3': 'val3'}) + + instead of generic "<object meta-data>" inherited from object. + ''' + dictreprs = ', '.join(repr(d) for d in self.dicts) + return '%s(%s)' % (self.__class__.__name__, dictreprs) + class SortedDict(dict): """ A dictionary that keeps its keys in the order in which they're inserted. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.
