Merge pull request #20814 from amitvadhel/INCR-477
INCR-477: Make compatible with Python 3.x
This commit is contained in:
@@ -4,10 +4,12 @@ Discussion Application Configuration
|
|||||||
Signal handlers are connected here.
|
Signal handlers are connected here.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
|
|
||||||
from openedx.core.constants import COURSE_ID_PATTERN
|
from openedx.core.constants import COURSE_ID_PATTERN
|
||||||
from openedx.core.djangoapps.plugins.constants import ProjectType, SettingsType, PluginURLs, PluginSettings
|
from openedx.core.djangoapps.plugins.constants import PluginSettings, PluginURLs, ProjectType, SettingsType
|
||||||
|
|
||||||
|
|
||||||
class DiscussionConfig(AppConfig):
|
class DiscussionConfig(AppConfig):
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
# pylint: disable=missing-docstring
|
# pylint: disable=missing-docstring
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|||||||
@@ -3,16 +3,20 @@
|
|||||||
Module for checking permissions with the comment_client backend
|
Module for checking permissions with the comment_client backend
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from types import NoneType
|
from types import NoneType
|
||||||
|
|
||||||
|
import six
|
||||||
from edx_django_utils.cache import DEFAULT_REQUEST_CACHE
|
from edx_django_utils.cache import DEFAULT_REQUEST_CACHE
|
||||||
from opaque_keys.edx.keys import CourseKey
|
from opaque_keys.edx.keys import CourseKey
|
||||||
|
|
||||||
from lms.djangoapps.teams.models import CourseTeam
|
from lms.djangoapps.teams.models import CourseTeam
|
||||||
from openedx.core.djangoapps.django_comment_common.comment_client import Thread
|
from openedx.core.djangoapps.django_comment_common.comment_client import Thread
|
||||||
from openedx.core.djangoapps.django_comment_common.models import (
|
from openedx.core.djangoapps.django_comment_common.models import (
|
||||||
CourseDiscussionSettings, all_permissions_for_user_in_course,
|
CourseDiscussionSettings,
|
||||||
|
all_permissions_for_user_in_course
|
||||||
)
|
)
|
||||||
from openedx.core.djangoapps.django_comment_common.utils import get_course_discussion_settings
|
from openedx.core.djangoapps.django_comment_common.utils import get_course_discussion_settings
|
||||||
from openedx.core.lib.cache_utils import request_cached
|
from openedx.core.lib.cache_utils import request_cached
|
||||||
@@ -137,7 +141,7 @@ def _check_conditions_permissions(user, permissions, course_id, content, user_gr
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def test(user, per, operator="or"):
|
def test(user, per, operator="or"):
|
||||||
if isinstance(per, basestring):
|
if isinstance(per, six.string_types):
|
||||||
if per in CONDITIONS:
|
if per in CONDITIONS:
|
||||||
return _check_condition(user, per, content)
|
return _check_condition(user, per, content)
|
||||||
if 'group_' in per:
|
if 'group_' in per:
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
"""
|
"""
|
||||||
Urls for the django_comment_client.
|
Urls for the django_comment_client.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
from django.conf.urls import include, url
|
from django.conf.urls import include, url
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
|||||||
@@ -1,35 +1,41 @@
|
|||||||
# pylint: skip-file
|
# pylint: skip-file
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
import six
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.urls import reverse
|
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from pytz import UTC
|
from django.urls import reverse
|
||||||
from opaque_keys.edx.keys import CourseKey, UsageKey
|
from opaque_keys.edx.keys import CourseKey, UsageKey
|
||||||
from opaque_keys.edx.locations import i4xEncoder
|
from opaque_keys.edx.locations import i4xEncoder
|
||||||
|
from pytz import UTC
|
||||||
from six import text_type
|
from six import text_type
|
||||||
|
from six.moves import map
|
||||||
|
|
||||||
from courseware import courses
|
from courseware import courses
|
||||||
from courseware.access import has_access
|
from courseware.access import has_access
|
||||||
from lms.djangoapps.discussion.django_comment_client.constants import TYPE_ENTRY, TYPE_SUBCATEGORY
|
from lms.djangoapps.discussion.django_comment_client.constants import TYPE_ENTRY, TYPE_SUBCATEGORY
|
||||||
from lms.djangoapps.discussion.django_comment_client.permissions import (
|
from lms.djangoapps.discussion.django_comment_client.permissions import (
|
||||||
check_permissions_by_view, get_team, has_permission,
|
check_permissions_by_view,
|
||||||
|
get_team,
|
||||||
|
has_permission
|
||||||
)
|
)
|
||||||
from lms.djangoapps.discussion.django_comment_client.settings import MAX_COMMENT_DEPTH
|
from lms.djangoapps.discussion.django_comment_client.settings import MAX_COMMENT_DEPTH
|
||||||
|
from openedx.core.djangoapps.course_groups.cohorts import get_cohort_id, get_cohort_names, is_course_cohorted
|
||||||
from openedx.core.djangoapps.django_comment_common.models import (
|
from openedx.core.djangoapps.django_comment_common.models import (
|
||||||
FORUM_ROLE_STUDENT,
|
|
||||||
FORUM_ROLE_COMMUNITY_TA,
|
FORUM_ROLE_COMMUNITY_TA,
|
||||||
|
FORUM_ROLE_STUDENT,
|
||||||
CourseDiscussionSettings,
|
CourseDiscussionSettings,
|
||||||
DiscussionsIdMapping,
|
DiscussionsIdMapping,
|
||||||
Role
|
Role
|
||||||
)
|
)
|
||||||
from openedx.core.djangoapps.django_comment_common.utils import get_course_discussion_settings
|
from openedx.core.djangoapps.django_comment_common.utils import get_course_discussion_settings
|
||||||
from openedx.core.djangoapps.course_groups.cohorts import get_cohort_id, get_cohort_names, is_course_cohorted
|
|
||||||
from openedx.core.lib.cache_utils import request_cached
|
from openedx.core.lib.cache_utils import request_cached
|
||||||
from student.models import get_user_by_username_or_email
|
from student.models import get_user_by_username_or_email
|
||||||
from student.roles import GlobalStaff
|
from student.roles import GlobalStaff
|
||||||
@@ -51,7 +57,7 @@ def strip_none(dic):
|
|||||||
"""
|
"""
|
||||||
Returns a dictionary stripped of any keys having values of None
|
Returns a dictionary stripped of any keys having values of None
|
||||||
"""
|
"""
|
||||||
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 strip_blank(dic):
|
||||||
@@ -63,7 +69,7 @@ def strip_blank(dic):
|
|||||||
Determines if the provided value contains no information
|
Determines if the provided value contains no information
|
||||||
"""
|
"""
|
||||||
return isinstance(v, str) and len(v.strip()) == 0
|
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)])
|
||||||
|
|
||||||
# TODO should we be checking if d1 and d2 have the same keys with different values?
|
# TODO should we be checking if d1 and d2 have the same keys with different values?
|
||||||
|
|
||||||
@@ -236,7 +242,7 @@ def get_discussion_id_map_by_course_id(course_id, user):
|
|||||||
by discussion_id.
|
by discussion_id.
|
||||||
"""
|
"""
|
||||||
xblocks = get_accessible_discussion_xblocks_by_course_id(course_id, user)
|
xblocks = get_accessible_discussion_xblocks_by_course_id(course_id, user)
|
||||||
return dict(map(get_discussion_id_map_entry, xblocks))
|
return dict(list(map(get_discussion_id_map_entry, xblocks)))
|
||||||
|
|
||||||
|
|
||||||
@request_cached()
|
@request_cached()
|
||||||
@@ -501,7 +507,7 @@ class JsonError(HttpResponse):
|
|||||||
"""
|
"""
|
||||||
Object constructor, returns an error response containing the provided exception messages
|
Object constructor, returns an error response containing the provided exception messages
|
||||||
"""
|
"""
|
||||||
if isinstance(error_messages, basestring):
|
if isinstance(error_messages, six.string_types):
|
||||||
error_messages = [error_messages]
|
error_messages = [error_messages]
|
||||||
content = json.dumps({'errors': error_messages}, indent=2, ensure_ascii=False)
|
content = json.dumps({'errors': error_messages}, indent=2, ensure_ascii=False)
|
||||||
super(JsonError, self).__init__(content,
|
super(JsonError, self).__init__(content,
|
||||||
|
|||||||
@@ -2,33 +2,35 @@
|
|||||||
Defines asynchronous celery task for sending email notification (through edx-ace)
|
Defines asynchronous celery task for sending email notification (through edx-ace)
|
||||||
pertaining to new discussion forum comments.
|
pertaining to new discussion forum comments.
|
||||||
"""
|
"""
|
||||||
import logging
|
from __future__ import absolute_import
|
||||||
from urlparse import urljoin
|
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
import six
|
||||||
from celery import task
|
from celery import task
|
||||||
|
from celery_utils.logged_task import LoggedTask
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
|
|
||||||
from celery_utils.logged_task import LoggedTask
|
|
||||||
from edx_ace import ace
|
from edx_ace import ace
|
||||||
from edx_ace.utils import date
|
|
||||||
from edx_ace.recipient import Recipient
|
from edx_ace.recipient import Recipient
|
||||||
|
from edx_ace.utils import date
|
||||||
from eventtracking import tracker
|
from eventtracking import tracker
|
||||||
from lms.djangoapps.discussion.django_comment_client.utils import (
|
|
||||||
permalink, get_accessible_discussion_xblocks_by_course_id,
|
|
||||||
)
|
|
||||||
from opaque_keys.edx.keys import CourseKey
|
from opaque_keys.edx.keys import CourseKey
|
||||||
|
from six.moves.urllib.parse import urljoin # pylint: disable=import-error
|
||||||
|
|
||||||
from openedx.core.djangoapps.ace_common.template_context import get_base_template_context
|
|
||||||
from openedx.core.djangoapps.ace_common.message import BaseMessageType
|
|
||||||
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
|
|
||||||
import openedx.core.djangoapps.django_comment_common.comment_client as cc
|
import openedx.core.djangoapps.django_comment_common.comment_client as cc
|
||||||
|
from lms.djangoapps.discussion.django_comment_client.utils import (
|
||||||
|
get_accessible_discussion_xblocks_by_course_id,
|
||||||
|
permalink
|
||||||
|
)
|
||||||
|
from openedx.core.djangoapps.ace_common.message import BaseMessageType
|
||||||
|
from openedx.core.djangoapps.ace_common.template_context import get_base_template_context
|
||||||
|
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
|
||||||
from openedx.core.djangoapps.django_comment_common.models import DiscussionsIdMapping
|
from openedx.core.djangoapps.django_comment_common.models import DiscussionsIdMapping
|
||||||
from openedx.core.lib.celery.task_utils import emulate_http_request
|
from openedx.core.lib.celery.task_utils import emulate_http_request
|
||||||
from track import segment
|
from track import segment
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -48,7 +50,7 @@ def update_discussions_map(context):
|
|||||||
course_key = CourseKey.from_string(context['course_id'])
|
course_key = CourseKey.from_string(context['course_id'])
|
||||||
discussion_blocks = get_accessible_discussion_xblocks_by_course_id(course_key, include_all=True)
|
discussion_blocks = get_accessible_discussion_xblocks_by_course_id(course_key, include_all=True)
|
||||||
discussions_id_map = {
|
discussions_id_map = {
|
||||||
discussion_block.discussion_id: unicode(discussion_block.location)
|
discussion_block.discussion_id: six.text_type(discussion_block.location)
|
||||||
for discussion_block in discussion_blocks
|
for discussion_block in discussion_blocks
|
||||||
}
|
}
|
||||||
DiscussionsIdMapping.update_mapping(course_key, discussions_id_map)
|
DiscussionsIdMapping.update_mapping(course_key, discussions_id_map)
|
||||||
@@ -85,10 +87,10 @@ def _track_notification_sent(message, context):
|
|||||||
'app_label': 'discussion',
|
'app_label': 'discussion',
|
||||||
'name': 'responsenotification', # This is 'Campaign' in GA
|
'name': 'responsenotification', # This is 'Campaign' in GA
|
||||||
'language': message.language,
|
'language': message.language,
|
||||||
'uuid': unicode(message.uuid),
|
'uuid': six.text_type(message.uuid),
|
||||||
'send_uuid': unicode(message.send_uuid),
|
'send_uuid': six.text_type(message.send_uuid),
|
||||||
'thread_id': context['thread_id'],
|
'thread_id': context['thread_id'],
|
||||||
'course_id': unicode(context['course_id']),
|
'course_id': six.text_type(context['course_id']),
|
||||||
'thread_created_at': date.deserialize(context['thread_created_at']),
|
'thread_created_at': date.deserialize(context['thread_created_at']),
|
||||||
'nonInteraction': 1,
|
'nonInteraction': 1,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
"""
|
"""
|
||||||
Forum urls for the django_comment_client.
|
Forum urls for the django_comment_client.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from discussion import views
|
from discussion import views
|
||||||
|
|||||||
Reference in New Issue
Block a user