From 4ef53135aebe3a03dc7dfee2e9259c51115eb11c Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Tue, 3 Mar 2015 14:14:32 -0500 Subject: [PATCH] Add and clean up __repr__ and __str__ for XModule-related things --- .../xmodule/xmodule/modulestore/mongo/base.py | 16 ++++++++++++++++ common/lib/xmodule/xmodule/x_module.py | 9 +++++++-- lms/djangoapps/lms_xblock/field_data.py | 3 +++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/common/lib/xmodule/xmodule/modulestore/mongo/base.py b/common/lib/xmodule/xmodule/modulestore/mongo/base.py index 60ed23cbe5..abd2bba9ba 100644 --- a/common/lib/xmodule/xmodule/modulestore/mongo/base.py +++ b/common/lib/xmodule/xmodule/modulestore/mongo/base.py @@ -151,12 +151,28 @@ class MongoKeyValueStore(InheritanceKeyValueStore): else: return False + def __repr__(self): + return "MongoKeyValueStore{!r}<{!r}, {!r}>".format( + (self._data, self._parent, self._children, self._metadata), + self._fields, + self.inherited_settings + ) + class CachingDescriptorSystem(MakoDescriptorSystem, EditInfoRuntimeMixin): """ A system that has a cache of module json that it will use to load modules from, with a backup of calling to the underlying modulestore for more data """ + def __repr__(self): + return "CachingDescriptorSystem{!r}".format(( + self.modulestore, + unicode(self.course_id), + [unicode(key) for key in self.module_data.keys()], + self.default_class, + [unicode(key) for key in self.cached_metadata.keys()], + )) + def __init__(self, modulestore, course_key, module_data, default_class, cached_metadata, **kwargs): """ modulestore: the module store that can be used to retrieve additional modules diff --git a/common/lib/xmodule/xmodule/x_module.py b/common/lib/xmodule/xmodule/x_module.py index 9270e735cf..92b22a74e8 100644 --- a/common/lib/xmodule/xmodule/x_module.py +++ b/common/lib/xmodule/xmodule/x_module.py @@ -1596,8 +1596,13 @@ class ModuleSystem(MetricsMixin, ConfigurableFragmentWrapper, Runtime): # pylin """provide uniform access to attributes (like etree)""" self.__dict__[attr] = val - def __str__(self): - return str(self.__dict__) + def __repr__(self): + kwargs = self.__dict__.copy() + + # Remove value set transiently by XBlock + kwargs.pop('_view_name') + + return "{}{}".format(self.__class__.__name__, kwargs) @property def ajax_url(self): diff --git a/lms/djangoapps/lms_xblock/field_data.py b/lms/djangoapps/lms_xblock/field_data.py index c8d4e0ea90..4e41f2be49 100644 --- a/lms/djangoapps/lms_xblock/field_data.py +++ b/lms/djangoapps/lms_xblock/field_data.py @@ -33,3 +33,6 @@ class LmsFieldData(SplitFieldData): Scope.user_info: student_data, Scope.preferences: student_data, }) + + def __repr__(self): + return "LmsFieldData{!r}".format((self._authored_data, self._student_data))