diff --git a/common/djangoapps/util/cache.py b/common/djangoapps/util/cache.py index 5987d704e4..9dee55828f 100644 --- a/common/djangoapps/util/cache.py +++ b/common/djangoapps/util/cache.py @@ -76,7 +76,14 @@ def cache_if_anonymous(*get_parameters): }) response = cache.get(cache_key) # pylint: disable=maybe-no-member - if not response: + + if response: + # A hack to ensure that the response data is a valid text type for both Python 2 and 3. + response_content = list(response._container) # pylint: disable=protected-member + response.content = b'' + for item in response_content: + response.write(item) + else: response = view_func(request, *args, **kwargs) cache.set(cache_key, response, 60 * 3) # pylint: disable=maybe-no-member diff --git a/common/lib/xmodule/xmodule/video_module/transcripts_utils.py b/common/lib/xmodule/xmodule/video_module/transcripts_utils.py index 5009feb497..89e68c362f 100644 --- a/common/lib/xmodule/xmodule/video_module/transcripts_utils.py +++ b/common/lib/xmodule/xmodule/video_module/transcripts_utils.py @@ -661,9 +661,11 @@ class Transcript(object): try: # With error handling (set to 'ERROR_RAISE'), we will be getting # the exception if something went wrong in parsing the transcript. + if isinstance(content, text_type): + content = content.encode('utf-8') srt_subs = SubRipFile.from_string( # Skip byte order mark(BOM) character - content.encode('utf-8').decode('utf-8-sig'), + content.decode('utf-8-sig'), error_handling=SubRipFile.ERROR_RAISE ) except Error as ex: # Base exception from pysrt diff --git a/common/lib/xmodule/xmodule/x_module.py b/common/lib/xmodule/xmodule/x_module.py index 26eeb4cc2a..051e9cd6e6 100644 --- a/common/lib/xmodule/xmodule/x_module.py +++ b/common/lib/xmodule/xmodule/x_module.py @@ -1259,10 +1259,21 @@ class XModuleDescriptor(XModuleDescriptorToXBlockMixin, HTMLSnippet, ResourceTem """ return (hasattr(other, 'scope_ids') and self.scope_ids == other.scope_ids and - list(self.fields.keys()) == list(other.fields.keys()) and + set(self.fields.keys()) == set(other.fields.keys()) and all(getattr(self, field.name) == getattr(other, field.name) for field in self.fields.values())) + def __hash__(self): # pylint: disable=useless-super-delegation + """ + This isn't technically appropriate since descriptors are actually mutable, + but in practice we rarely modify them after creation or instantiate two + equivalent descriptors in the same process. And we perform graph + operations on large collections of XBlocks that have simply unacceptable + performance if we have to rely on lists and equality rather than sets, + dictionaries, and identity-based hash functions. + """ + return super(XModuleDescriptor, self).__hash__() + def __repr__(self): return ( "{0.__class__.__name__}(" diff --git a/lms/djangoapps/branding/views.py b/lms/djangoapps/branding/views.py index 5d262ae0df..585a0d74c8 100644 --- a/lms/djangoapps/branding/views.py +++ b/lms/djangoapps/branding/views.py @@ -43,7 +43,7 @@ def index(request): if configuration_helpers.get_value( 'ALWAYS_REDIRECT_HOMEPAGE_TO_DASHBOARD_FOR_AUTHENTICATED_USER', settings.FEATURES.get('ALWAYS_REDIRECT_HOMEPAGE_TO_DASHBOARD_FOR_AUTHENTICATED_USER', True)): - return redirect(reverse('dashboard')) + return redirect('dashboard') enable_mktg_site = configuration_helpers.get_value( 'ENABLE_MKTG_SITE', @@ -62,7 +62,7 @@ def index(request): # keep specialized logic for Edge until we can migrate over Edge to fully use # configuration. if domain and 'edge.edx.org' in domain: - return redirect(reverse("signin_user")) + return redirect("signin_user") # we do not expect this case to be reached in cases where # marketing and edge are enabled diff --git a/lms/djangoapps/courseware/views/views.py b/lms/djangoapps/courseware/views/views.py index e4bdba694e..e933980f03 100644 --- a/lms/djangoapps/courseware/views/views.py +++ b/lms/djangoapps/courseware/views/views.py @@ -294,9 +294,9 @@ def yt_video_metadata(request): status_code = res.status_code if res.status_code == 200: try: - res = res.json() - if res.get('items', []): - response = res + res_json = res.json() + if res_json.get('items', []): + response = res_json else: logging.warning(u'Unable to find the items in response. Following response ' u'was received: {res}'.format(res=res.text)) diff --git a/lms/djangoapps/mobile_api/middleware.py b/lms/djangoapps/mobile_api/middleware.py index a38f4044dc..0a87057970 100644 --- a/lms/djangoapps/mobile_api/middleware.py +++ b/lms/djangoapps/mobile_api/middleware.py @@ -9,6 +9,7 @@ from django.conf import settings from django.core.cache import cache from django.http import HttpResponse from pytz import UTC +import six from mobile_api.mobile_platform import MobilePlatform from mobile_api.models import AppVersionConfig @@ -104,13 +105,13 @@ class AppVersionUpgrade(object): cached_data = cache.get_many([last_supported_date_cache_key, latest_version_cache_key]) last_supported_date = cached_data.get(last_supported_date_cache_key) - if not last_supported_date: + if last_supported_date != self.NO_LAST_SUPPORTED_DATE and not isinstance(last_supported_date, datetime): last_supported_date = self._get_last_supported_date(platform.NAME, platform.version) cache.set(last_supported_date_cache_key, last_supported_date, self.CACHE_TIMEOUT) request_cache_dict[self.LAST_SUPPORTED_DATE_HEADER] = last_supported_date latest_version = cached_data.get(latest_version_cache_key) - if not latest_version: + if not (latest_version and isinstance(latest_version, six.text_type)): latest_version = self._get_latest_version(platform.NAME) cache.set(latest_version_cache_key, latest_version, self.CACHE_TIMEOUT) request_cache_dict[self.LATEST_VERSION_HEADER] = latest_version diff --git a/lms/envs/common.py b/lms/envs/common.py index 7c2274edb4..bf5aa8a7d4 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -1443,6 +1443,7 @@ MIDDLEWARE_CLASSES = [ 'openedx.core.djangoapps.header_control.middleware.HeaderControlMiddleware', 'lms.djangoapps.discussion.django_comment_client.middleware.AjaxExceptionMiddleware', 'django.middleware.common.CommonMiddleware', + 'django.contrib.sites.middleware.CurrentSiteMiddleware', 'edx_rest_framework_extensions.auth.jwt.middleware.JwtAuthCookieMiddleware', diff --git a/requirements/edx/base.txt b/requirements/edx/base.txt index 4ab31d76b2..c6be133cf1 100644 --- a/requirements/edx/base.txt +++ b/requirements/edx/base.txt @@ -6,7 +6,7 @@ # -e git+https://github.com/edx/acid-block.git@98aecba94ecbfa934e2d00262741c0ea9f557fc9#egg=acid-xblock -e common/lib/capa --e git+https://github.com/edx/codejail.git@33758da2609bd72c2c18efc2d4bdb93596523d5e#egg=codejail +-e git+https://github.com/edx/codejail.git@6bc47025359a4d6ecf2b6b5776ff99959094d2cc#egg=codejail -e git+https://github.com/edx/django-wiki.git@v0.0.23#egg=django-wiki -e git+https://github.com/edx/DoneXBlock.git@2.0.1#egg=done-xblock -e git+https://github.com/jazkarta/edx-jsme.git@690dbf75441fa91c7c4899df0b83d77f7deb5458#egg=edx-jsme @@ -112,7 +112,7 @@ edx-oauth2-provider==1.3.1 edx-opaque-keys[django]==2.0.1 edx-organizations==2.1.1 edx-proctoring-proctortrack==1.0.5 -edx-proctoring==2.1.6 +edx-proctoring==2.1.7 edx-rbac==1.0.3 # via edx-enterprise edx-rest-api-client==1.9.2 edx-search==1.2.2 @@ -151,7 +151,7 @@ lazy==1.1 lepl==5.1.3 # via rfc6266-parser libsass==0.10.0 loremipsum==1.0.5 -git+https://github.com/edx/xblock-lti-consumer.git@v1.2.1#egg=lti_consumer-xblock==1.2.1 +git+https://github.com/edx/xblock-lti-consumer.git@v1.2.3#egg=lti_consumer-xblock==1.2.3 lxml==3.8.0 mailsnake==1.6.4 mako==1.0.2 @@ -251,7 +251,7 @@ webencodings==0.5.1 # via html5lib webob==1.8.5 # via xblock wrapt==1.10.5 git+https://github.com/edx-solutions/xblock-drag-and-drop-v2@v2.2.6#egg=xblock-drag-and-drop-v2==2.2.6 -git+https://github.com/open-craft/xblock-poll@add89e14558c30f3c8dc7431e5cd6536fff6d941#egg=xblock-poll==1.5.1 +git+https://github.com/jmbowman/xblock-poll@8e78663fdd3c1d79571eb753d1c601729e9a9325#egg=xblock-poll==1.9.0 xblock-utils==1.2.3 xblock==1.2.9 xmlsec==1.3.3 # via python3-saml diff --git a/requirements/edx/development.txt b/requirements/edx/development.txt index 9007b65d3f..4f53edfe96 100644 --- a/requirements/edx/development.txt +++ b/requirements/edx/development.txt @@ -6,7 +6,7 @@ # -e git+https://github.com/edx/acid-block.git@98aecba94ecbfa934e2d00262741c0ea9f557fc9#egg=acid-xblock -e common/lib/capa --e git+https://github.com/edx/codejail.git@33758da2609bd72c2c18efc2d4bdb93596523d5e#egg=codejail +-e git+https://github.com/edx/codejail.git@6bc47025359a4d6ecf2b6b5776ff99959094d2cc#egg=codejail -e git+https://github.com/edx/django-wiki.git@v0.0.23#egg=django-wiki -e git+https://github.com/edx/DoneXBlock.git@2.0.1#egg=done-xblock -e git+https://github.com/jazkarta/edx-jsme.git@690dbf75441fa91c7c4899df0b83d77f7deb5458#egg=edx-jsme @@ -135,7 +135,7 @@ edx-oauth2-provider==1.3.1 edx-opaque-keys[django]==2.0.1 edx-organizations==2.1.1 edx-proctoring-proctortrack==1.0.5 -edx-proctoring==2.1.6 +edx-proctoring==2.1.7 edx-rbac==1.0.3 edx-rest-api-client==1.9.2 edx-search==1.2.2 @@ -194,7 +194,7 @@ lazy==1.1 lepl==5.1.3 libsass==0.10.0 loremipsum==1.0.5 -git+https://github.com/edx/xblock-lti-consumer.git@v1.2.1#egg=lti_consumer-xblock==1.2.1 +git+https://github.com/edx/xblock-lti-consumer.git@v1.2.3#egg=lti_consumer-xblock==1.2.3 lxml==3.8.0 m2r==0.2.1 mailsnake==1.6.4 @@ -344,7 +344,7 @@ websocket-client==0.56.0 werkzeug==0.16.0 wrapt==1.10.5 git+https://github.com/edx-solutions/xblock-drag-and-drop-v2@v2.2.6#egg=xblock-drag-and-drop-v2==2.2.6 -git+https://github.com/open-craft/xblock-poll@add89e14558c30f3c8dc7431e5cd6536fff6d941#egg=xblock-poll==1.5.1 +git+https://github.com/jmbowman/xblock-poll@8e78663fdd3c1d79571eb753d1c601729e9a9325#egg=xblock-poll==1.9.0 xblock-utils==1.2.3 xblock==1.2.9 xmlsec==1.3.3 diff --git a/requirements/edx/github.in b/requirements/edx/github.in index b4f485fba7..d0f8c3f19b 100644 --- a/requirements/edx/github.in +++ b/requirements/edx/github.in @@ -79,18 +79,18 @@ git+https://github.com/edx/django-celery.git@756cb57aad765cb2b0d37372c1855b8f5f3 git+https://github.com/edx/bridgekeeper.git@4e34894e4ac5d0467ed1901811a81fd87ee01937#egg=bridgekeeper==0.0 # Our libraries: --e git+https://github.com/edx/codejail.git@33758da2609bd72c2c18efc2d4bdb93596523d5e#egg=codejail +-e git+https://github.com/edx/codejail.git@6bc47025359a4d6ecf2b6b5776ff99959094d2cc#egg=codejail -e git+https://github.com/edx/acid-block.git@98aecba94ecbfa934e2d00262741c0ea9f557fc9#egg=acid-xblock git+https://github.com/edx/edx-ora2.git@2.4.7#egg=ora2==2.4.7 git+https://github.com/edx/crowdsourcehinter.git@a7ffc85b134b7d8909bf1fefd23dbdb8eb28e467#egg=crowdsourcehinter-xblock==0.2 -e git+https://github.com/edx/RateXBlock.git@2.0#egg=rate-xblock -e git+https://github.com/edx/DoneXBlock.git@2.0.1#egg=done-xblock -e git+https://github.com/edx-solutions/xblock-google-drive.git@2d176468e33c0713c911b563f8f65f7cf232f5b6#egg=xblock-google-drive -git+https://github.com/edx/xblock-lti-consumer.git@v1.2.1#egg=lti_consumer-xblock==1.2.1 +git+https://github.com/edx/xblock-lti-consumer.git@v1.2.3#egg=lti_consumer-xblock==1.2.3 # Third Party XBlocks git+https://github.com/joestump/python-oauth2.git@b94f69b1ad195513547924e380d9265133e995fa#egg=oauth2 -git+https://github.com/open-craft/xblock-poll@add89e14558c30f3c8dc7431e5cd6536fff6d941#egg=xblock-poll==1.5.1 +git+https://github.com/jmbowman/xblock-poll@8e78663fdd3c1d79571eb753d1c601729e9a9325#egg=xblock-poll==1.9.0 git+https://github.com/edx-solutions/xblock-drag-and-drop-v2@v2.2.6#egg=xblock-drag-and-drop-v2==2.2.6 diff --git a/requirements/edx/testing.txt b/requirements/edx/testing.txt index 70e3d991eb..143ef3b58e 100644 --- a/requirements/edx/testing.txt +++ b/requirements/edx/testing.txt @@ -6,7 +6,7 @@ # -e git+https://github.com/edx/acid-block.git@98aecba94ecbfa934e2d00262741c0ea9f557fc9#egg=acid-xblock -e common/lib/capa --e git+https://github.com/edx/codejail.git@33758da2609bd72c2c18efc2d4bdb93596523d5e#egg=codejail +-e git+https://github.com/edx/codejail.git@6bc47025359a4d6ecf2b6b5776ff99959094d2cc#egg=codejail -e git+https://github.com/edx/django-wiki.git@v0.0.23#egg=django-wiki -e git+https://github.com/edx/DoneXBlock.git@2.0.1#egg=done-xblock -e git+https://github.com/jazkarta/edx-jsme.git@690dbf75441fa91c7c4899df0b83d77f7deb5458#egg=edx-jsme @@ -132,7 +132,7 @@ edx-oauth2-provider==1.3.1 edx-opaque-keys[django]==2.0.1 edx-organizations==2.1.1 edx-proctoring-proctortrack==1.0.5 -edx-proctoring==2.1.6 +edx-proctoring==2.1.7 edx-rbac==1.0.3 edx-rest-api-client==1.9.2 edx-search==1.2.2 @@ -188,7 +188,7 @@ lazy==1.1 lepl==5.1.3 libsass==0.10.0 loremipsum==1.0.5 -git+https://github.com/edx/xblock-lti-consumer.git@v1.2.1#egg=lti_consumer-xblock==1.2.1 +git+https://github.com/edx/xblock-lti-consumer.git@v1.2.3#egg=lti_consumer-xblock==1.2.3 lxml==3.8.0 mailsnake==1.6.4 mako==1.0.2 @@ -326,7 +326,7 @@ websocket-client==0.56.0 # via docker werkzeug==0.16.0 # via moto wrapt==1.10.5 git+https://github.com/edx-solutions/xblock-drag-and-drop-v2@v2.2.6#egg=xblock-drag-and-drop-v2==2.2.6 -git+https://github.com/open-craft/xblock-poll@add89e14558c30f3c8dc7431e5cd6536fff6d941#egg=xblock-poll==1.5.1 +git+https://github.com/jmbowman/xblock-poll@8e78663fdd3c1d79571eb753d1c601729e9a9325#egg=xblock-poll==1.9.0 xblock-utils==1.2.3 xblock==1.2.9 xmlsec==1.3.3