Fixing python3. Hashvalues were saving with b prefix in db. Decoded them before insertion.
This commit is contained in:
arbisoft
2019-08-27 19:34:25 +05:00
committed by Awais Qureshi
parent 75e38fc4fd
commit 3fb5db43ea
4 changed files with 10 additions and 5 deletions

View File

@@ -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:

View File

@@ -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.
"""

View File

@@ -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)

View File

@@ -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):