From df949d6de10e1cdbde6459b5f569a2eb427b96ff Mon Sep 17 00:00:00 2001 From: Amit <43564590+amitvadhel@users.noreply.github.com> Date: Thu, 20 Jun 2019 23:20:49 +0300 Subject: [PATCH] INCR-480: Make compatible with Python 3.x and fixed line over length limit (#20833) --- lms/djangoapps/teams/__init__.py | 3 ++- lms/djangoapps/teams/plugins.py | 2 ++ lms/djangoapps/teams/search_indexes.py | 2 ++ lms/djangoapps/teams/serializers.py | 7 +++++-- lms/djangoapps/teams/views.py | 12 +++++++++--- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lms/djangoapps/teams/__init__.py b/lms/djangoapps/teams/__init__.py index 4bd41fb2fd..b272e23460 100644 --- a/lms/djangoapps/teams/__init__.py +++ b/lms/djangoapps/teams/__init__.py @@ -2,8 +2,9 @@ Defines common methods shared by Teams classes """ -from django.conf import settings +from __future__ import absolute_import +from django.conf import settings TEAM_DISCUSSION_CONTEXT = 'standalone' diff --git a/lms/djangoapps/teams/plugins.py b/lms/djangoapps/teams/plugins.py index e0cc852277..15ca141de6 100644 --- a/lms/djangoapps/teams/plugins.py +++ b/lms/djangoapps/teams/plugins.py @@ -1,6 +1,8 @@ """ Definition of the course team feature. """ +from __future__ import absolute_import + from django.utils.translation import ugettext_noop from courseware.tabs import EnrolledTab diff --git a/lms/djangoapps/teams/search_indexes.py b/lms/djangoapps/teams/search_indexes.py index a94a4b9792..70914f42e9 100644 --- a/lms/djangoapps/teams/search_indexes.py +++ b/lms/djangoapps/teams/search_indexes.py @@ -1,5 +1,7 @@ """ Search index used to load data into elasticsearch""" +from __future__ import absolute_import + import logging from functools import wraps diff --git a/lms/djangoapps/teams/serializers.py b/lms/djangoapps/teams/serializers.py index 5343b82ce8..150f58e5ef 100644 --- a/lms/djangoapps/teams/serializers.py +++ b/lms/djangoapps/teams/serializers.py @@ -1,6 +1,9 @@ """Defines serializers used by the Team API.""" +from __future__ import absolute_import + from copy import deepcopy +import six from django.conf import settings from django.contrib.auth.models import User from django.db.models import Count @@ -18,13 +21,13 @@ class CountryField(serializers.Field): Field to serialize a country code. """ - COUNTRY_CODES = dict(countries).keys() + COUNTRY_CODES = list(dict(countries).keys()) def to_representation(self, obj): """ Represent the country as a 2-character unicode identifier. """ - return unicode(obj) + return six.text_type(obj) def to_internal_value(self, data): """ diff --git a/lms/djangoapps/teams/views.py b/lms/djangoapps/teams/views.py index c03eb76d83..95668815f7 100644 --- a/lms/djangoapps/teams/views.py +++ b/lms/djangoapps/teams/views.py @@ -1,7 +1,10 @@ """HTTP endpoints for the Teams API.""" +from __future__ import absolute_import + import logging +import six from django.conf import settings from django.contrib.auth.models import User from django.db.models.signals import post_save @@ -11,6 +14,7 @@ from django.shortcuts import get_object_or_404, render_to_response from django.utils.translation import ugettext as _ from django.utils.translation import ugettext_noop from django_countries import countries +from edx_rest_framework_extensions.paginators import DefaultPagination, paginate_search_results from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey from rest_framework import permissions, status @@ -24,7 +28,6 @@ from rest_framework_oauth.authentication import OAuth2Authentication from courseware.courses import get_course_with_access, has_access from lms.djangoapps.discussion.django_comment_client.utils import has_discussion_privileges from lms.djangoapps.teams.models import CourseTeam, CourseTeamMembership -from edx_rest_framework_extensions.paginators import DefaultPagination, paginate_search_results from openedx.core.lib.api.parsers import MergePatchParser from openedx.core.lib.api.permissions import IsStaffOrReadOnly from openedx.core.lib.api.view_utils import ( @@ -66,7 +69,10 @@ def team_post_save_callback(sender, instance, **kwargs): # pylint: disable=unus if not kwargs['created']: for field in changed_fields: if field not in instance.FIELD_BLACKLIST: - truncated_fields = truncate_fields(unicode(changed_fields[field]), unicode(getattr(instance, field))) + truncated_fields = truncate_fields( + six.text_type(changed_fields[field]), + six.text_type(getattr(instance, field)) + ) truncated_fields['team_id'] = instance.team_id truncated_fields['field'] = field @@ -499,7 +505,7 @@ class TeamsListView(ExpandableFieldViewMixin, GenericAPIView): return Response(status=status.HTTP_403_FORBIDDEN) data = request.data.copy() - data['course_id'] = unicode(course_key) + data['course_id'] = six.text_type(course_key) serializer = CourseTeamCreationSerializer(data=data) add_serializer_errors(serializer, data, field_errors)