* INCR-233: Run python-modernize and isort on openedx/core/djangoapps/django_comment_common

* INCR-233: Fixes for basestring type as the six.string_types is tuple

* INCR-233: Grouped absolute_import and unicode_literals imports

* INCR-233: Grouped absolute_import and unicode_literals imports for migrations
This commit is contained in:
Amit
2019-05-15 19:12:46 +03:00
committed by Michael Youngstrom
parent 0948b5b96a
commit b5725b9f29
13 changed files with 45 additions and 17 deletions

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,4 +1,6 @@
# pylint: disable=missing-docstring,unused-argument
from __future__ import absolute_import
import logging
from .utils import CommentClientRequestError, extract, perform_request

View File

@@ -1,4 +1,6 @@
# pylint: disable=missing-docstring
from __future__ import absolute_import
from django.conf import settings
if hasattr(settings, "COMMENTS_SERVICE_URL"):

View File

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

View File

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

View File

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

View File

@@ -1,4 +1,6 @@
# pylint: disable=missing-docstring,unused-argument,model-missing-unicode
from __future__ import absolute_import
import json
import logging

View File

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

View File

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

View File

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