diff --git a/lms/djangoapps/grades/course_data.py b/lms/djangoapps/grades/course_data.py index 56e462c247..4d2aad6774 100644 --- a/lms/djangoapps/grades/course_data.py +++ b/lms/djangoapps/grades/course_data.py @@ -106,7 +106,10 @@ class CourseData(object): return getattr(course_block, 'subtree_edited_on', None) def __str__(self): - return 'Course: course_key: {}'.format(self.course_key) + """ + Return human-readable string representation. + """ + return u'Course: course_key: {}'.format(self.course_key) def full_string(self): if self.effective_structure: diff --git a/lms/djangoapps/grades/models.py b/lms/djangoapps/grades/models.py index d415261e28..a887833ad3 100644 --- a/lms/djangoapps/grades/models.py +++ b/lms/djangoapps/grades/models.py @@ -20,6 +20,7 @@ import six from django.apps import apps from django.contrib.auth.models import User from django.db import models +from django.utils.encoding import python_2_unicode_compatible from django.utils.timezone import now from lazy import lazy from model_utils.models import TimeStampedModel @@ -79,7 +80,7 @@ class BlockRecordList(object): supported by adding a label indicated which algorithm was used, e.g., "sha256$j0NDRmSPa5bfid2pAcUXaxCm2Dlh3TwayItZstwyeqQ=". """ - return b64encode(sha1(self.json_value.encode('utf-8')).digest()) + return b64encode(sha1(self.json_value.encode('utf-8')).digest()).decode('utf-8') @lazy def json_value(self): @@ -128,6 +129,7 @@ class BlockRecordList(object): return cls(blocks, course_key) +@python_2_unicode_compatible class VisibleBlocks(models.Model): """ A django model used to track the state of a set of visible blocks under a @@ -148,7 +150,7 @@ class VisibleBlocks(models.Model): class Meta(object): app_label = "grades" - def __unicode__(self): + def __str__(self): """ String representation of this model. """ diff --git a/lms/djangoapps/grades/tests/test_models.py b/lms/djangoapps/grades/tests/test_models.py index 7eda48c32a..a9e718755b 100644 --- a/lms/djangoapps/grades/tests/test_models.py +++ b/lms/djangoapps/grades/tests/test_models.py @@ -166,7 +166,7 @@ class VisibleBlocksTest(GradesModelTestCase): 'version': BLOCK_RECORD_LIST_VERSION, } expected_json = json.dumps(expected_data, separators=(',', ':'), sort_keys=True) - expected_hash = b64encode(sha1(expected_json).digest()) + expected_hash = b64encode(sha1(expected_json.encode('utf-8')).digest()).decode('utf-8') self.assertEqual(expected_data, json.loads(vblocks.blocks_json)) self.assertEqual(expected_json, vblocks.blocks_json) self.assertEqual(expected_hash, vblocks.hashed) diff --git a/lms/djangoapps/grades/transformer.py b/lms/djangoapps/grades/transformer.py index 7470c8ac91..c1028c0590 100644 --- a/lms/djangoapps/grades/transformer.py +++ b/lms/djangoapps/grades/transformer.py @@ -93,7 +93,7 @@ class GradesTransformer(BlockStructureTransformer): separators=(',', ':'), # Remove spaces from separators for more compact representation sort_keys=True, ) - return b64encode(sha1(ordered_policy.encode('utf-8')).digest()) + return b64encode(sha1(ordered_policy.encode('utf-8')).digest()).decode('utf-8') @classmethod def _collect_explicit_graded(cls, block_structure):