diff --git a/openedx/core/djangoapps/django_comment_common/admin.py b/openedx/core/djangoapps/django_comment_common/admin.py index 57e30eb147..0b7af445e7 100644 --- a/openedx/core/djangoapps/django_comment_common/admin.py +++ b/openedx/core/djangoapps/django_comment_common/admin.py @@ -1,6 +1,8 @@ """ Admin for managing the connection to the Forums backend service. """ +from __future__ import absolute_import + from django.contrib import admin from .models import ForumsConfig diff --git a/openedx/core/djangoapps/django_comment_common/comment_client/__init__.py b/openedx/core/djangoapps/django_comment_common/comment_client/__init__.py index 6f0222e54d..3f856f063d 100644 --- a/openedx/core/djangoapps/django_comment_common/comment_client/__init__.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/__init__.py @@ -1,6 +1,3 @@ # pylint: disable=missing-docstring,wildcard-import from .comment_client import * -from .utils import ( - CommentClientError, CommentClientRequestError, - CommentClient500Error, CommentClientMaintenanceError -) +from .utils import CommentClient500Error, CommentClientError, CommentClientMaintenanceError, CommentClientRequestError diff --git a/openedx/core/djangoapps/django_comment_common/comment_client/comment.py b/openedx/core/djangoapps/django_comment_common/comment_client/comment.py index 4dd5bb58e0..27537ffbd6 100644 --- a/openedx/core/djangoapps/django_comment_common/comment_client/comment.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/comment.py @@ -1,4 +1,6 @@ # pylint: disable=missing-docstring,protected-access +from __future__ import absolute_import + from openedx.core.djangoapps.django_comment_common.comment_client import models, settings from .thread import Thread, _url_for_flag_abuse_thread, _url_for_unflag_abuse_thread diff --git a/openedx/core/djangoapps/django_comment_common/comment_client/commentable.py b/openedx/core/djangoapps/django_comment_common/comment_client/commentable.py index 76ef5d23c0..8586b5d9a1 100644 --- a/openedx/core/djangoapps/django_comment_common/comment_client/commentable.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/commentable.py @@ -1,5 +1,7 @@ # pylint: disable=missing-docstring """Provides base Commentable model class""" +from __future__ import absolute_import + from openedx.core.djangoapps.django_comment_common.comment_client import models, settings diff --git a/openedx/core/djangoapps/django_comment_common/comment_client/models.py b/openedx/core/djangoapps/django_comment_common/comment_client/models.py index 7b0d2e2cd9..5ddf1d5559 100644 --- a/openedx/core/djangoapps/django_comment_common/comment_client/models.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/models.py @@ -1,4 +1,6 @@ # pylint: disable=missing-docstring,unused-argument +from __future__ import absolute_import + import logging from .utils import CommentClientRequestError, extract, perform_request diff --git a/openedx/core/djangoapps/django_comment_common/comment_client/settings.py b/openedx/core/djangoapps/django_comment_common/comment_client/settings.py index 1d3f224b41..7ed582b99c 100644 --- a/openedx/core/djangoapps/django_comment_common/comment_client/settings.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/settings.py @@ -1,4 +1,6 @@ # pylint: disable=missing-docstring +from __future__ import absolute_import + from django.conf import settings if hasattr(settings, "COMMENTS_SERVICE_URL"): diff --git a/openedx/core/djangoapps/django_comment_common/comment_client/thread.py b/openedx/core/djangoapps/django_comment_common/comment_client/thread.py index d45a385f9e..aaa8c7efb9 100644 --- a/openedx/core/djangoapps/django_comment_common/comment_client/thread.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/thread.py @@ -1,11 +1,11 @@ # pylint: disable=missing-docstring,protected-access +from __future__ import absolute_import + import logging from eventtracking import tracker -from . import models -from . import settings -from . import utils +from . import models, settings, utils log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/django_comment_common/comment_client/user.py b/openedx/core/djangoapps/django_comment_common/comment_client/user.py index d6b6891454..52ace88003 100644 --- a/openedx/core/djangoapps/django_comment_common/comment_client/user.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/user.py @@ -1,10 +1,10 @@ # pylint: disable=missing-docstring,protected-access """ User model wrapper for comment service""" +from __future__ import absolute_import + from six import text_type -from . import models -from . import settings -from . import utils +from . import models, settings, utils class User(models.Model): diff --git a/openedx/core/djangoapps/django_comment_common/comment_client/utils.py b/openedx/core/djangoapps/django_comment_common/comment_client/utils.py index dfa4712c8c..d598ade307 100644 --- a/openedx/core/djangoapps/django_comment_common/comment_client/utils.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/utils.py @@ -1,9 +1,12 @@ # pylint: disable=missing-docstring,unused-argument,broad-except """" Common utilities for comment client wrapper """ +from __future__ import absolute_import + import logging from uuid import uuid4 import requests +import six from django.utils.translation import get_language from .settings import SERVICE_HOST as COMMENTS_SERVICE @@ -12,13 +15,13 @@ log = logging.getLogger(__name__) def strip_none(dic): - return dict([(k, v) for k, v in dic.iteritems() if v is not None]) + return dict([(k, v) for k, v in six.iteritems(dic) if v is not None]) def strip_blank(dic): def _is_blank(v): return isinstance(v, str) and len(v.strip()) == 0 - return dict([(k, v) for k, v in dic.iteritems() if not _is_blank(v)]) + return dict([(k, v) for k, v in six.iteritems(dic) if not _is_blank(v)]) def extract(dic, keys): @@ -151,4 +154,4 @@ def check_forum_heartbeat(): else: return 'forum', False, res.get('check', 'Forum heartbeat failed') except Exception as fail: - return 'forum', False, unicode(fail) + return 'forum', False, six.text_type(fail) diff --git a/openedx/core/djangoapps/django_comment_common/models.py b/openedx/core/djangoapps/django_comment_common/models.py index 9d3e347ef9..46688ef9eb 100644 --- a/openedx/core/djangoapps/django_comment_common/models.py +++ b/openedx/core/djangoapps/django_comment_common/models.py @@ -1,4 +1,6 @@ # pylint: disable=missing-docstring,unused-argument,model-missing-unicode +from __future__ import absolute_import + import json import logging diff --git a/openedx/core/djangoapps/django_comment_common/signals.py b/openedx/core/djangoapps/django_comment_common/signals.py index e8ae64e2ba..0e7543b1e5 100644 --- a/openedx/core/djangoapps/django_comment_common/signals.py +++ b/openedx/core/djangoapps/django_comment_common/signals.py @@ -1,6 +1,8 @@ # pylint: disable=invalid-name """Signals related to the comments service.""" +from __future__ import absolute_import + from django.dispatch import Signal thread_created = Signal(providing_args=['user', 'post']) diff --git a/openedx/core/djangoapps/django_comment_common/tests.py b/openedx/core/djangoapps/django_comment_common/tests.py index a951d5b584..3935d7e623 100644 --- a/openedx/core/djangoapps/django_comment_common/tests.py +++ b/openedx/core/djangoapps/django_comment_common/tests.py @@ -1,12 +1,17 @@ # pylint: disable=missing-docstring +from __future__ import absolute_import + +import six +from contracts import new_contract from django.test import TestCase from opaque_keys.edx.locator import CourseLocator from six import text_type from openedx.core.djangoapps.course_groups.cohorts import CourseCohortsSettings -from openedx.core.djangoapps.django_comment_common.models import Role, CourseDiscussionSettings +from openedx.core.djangoapps.django_comment_common.models import CourseDiscussionSettings, Role from openedx.core.djangoapps.django_comment_common.utils import ( - get_course_discussion_settings, set_course_discussion_settings, + get_course_discussion_settings, + set_course_discussion_settings ) from student.models import CourseEnrollment, User from xmodule.modulestore import ModuleStoreEnum @@ -14,6 +19,8 @@ from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory +new_contract('basestring', six.string_types[0]) + class RoleAssignmentTest(TestCase): """ diff --git a/openedx/core/djangoapps/django_comment_common/utils.py b/openedx/core/djangoapps/django_comment_common/utils.py index 552ab4d0c5..fd05b19b7e 100644 --- a/openedx/core/djangoapps/django_comment_common/utils.py +++ b/openedx/core/djangoapps/django_comment_common/utils.py @@ -3,18 +3,25 @@ Common comment client utility functions. """ +from __future__ import absolute_import + +import six +from contracts import new_contract + +from openedx.core.djangoapps.course_groups.cohorts import get_legacy_discussion_settings from openedx.core.djangoapps.django_comment_common.models import ( - CourseDiscussionSettings, FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_GROUP_MODERATOR, FORUM_ROLE_MODERATOR, FORUM_ROLE_STUDENT, + CourseDiscussionSettings, Role ) -from openedx.core.djangoapps.course_groups.cohorts import get_legacy_discussion_settings from openedx.core.lib.cache_utils import request_cached +new_contract('basestring', six.string_types[0]) + class ThreadContext(object): """ An enumeration that represents the context of a thread. Used primarily by the comments service. """