diff --git a/lms/djangoapps/discussion/views.py b/lms/djangoapps/discussion/views.py index cce8360d4fa74dbda5acf0245544b56fb73baa18..0a1313faa03a74a92cd90dc33aa5d6a994ee575c 100644 --- a/lms/djangoapps/discussion/views.py +++ b/lms/djangoapps/discussion/views.py @@ -39,7 +39,6 @@ from django_comment_client.utils import ( get_group_id_for_user, get_group_names_by_id, is_commentable_divided, - merge_dict, strip_none ) from django_comment_common.utils import ThreadContext, get_course_discussion_settings, set_course_discussion_settings @@ -129,8 +128,8 @@ def get_threads(request, course, user_info, discussion_id=None, per_page=THREADS #is user a moderator #did the user request a group - query_params = merge_dict( - default_query_params, + query_params = default_query_params.copy() + query_params.update( strip_none( extract( request.GET, @@ -581,14 +580,12 @@ def followed_threads(request, course_key, user_id): try: profiled_user = cc.User(id=user_id, course_id=course_key) - default_query_params = { + query_params = { 'page': 1, 'per_page': THREADS_PER_PAGE, # more than threads_per_page to show more activities 'sort_key': 'date', } - - query_params = merge_dict( - default_query_params, + query_params.update( strip_none( extract( request.GET, diff --git a/lms/djangoapps/django_comment_client/tests/test_utils.py b/lms/djangoapps/django_comment_client/tests/test_utils.py index 65a0b613be6003b84d3e7b6d66cc367272e0550b..bc68cd97073e51c80e3efc604ae69ca06bedd413 100644 --- a/lms/djangoapps/django_comment_client/tests/test_utils.py +++ b/lms/djangoapps/django_comment_client/tests/test_utils.py @@ -66,12 +66,6 @@ class DictionaryTestCase(TestCase): expected = {'cats': 'meow', 'dogs': 'woof'} self.assertEqual(utils.strip_blank(d), expected) - def test_merge_dict(self): - d1 = {'cats': 'meow', 'dogs': 'woof'} - d2 = {'lions': 'roar', 'ducks': 'quack'} - expected = {'cats': 'meow', 'dogs': 'woof', 'lions': 'roar', 'ducks': 'quack'} - self.assertEqual(utils.merge_dict(d1, d2), expected) - @attr(shard=1) @pytest.mark.django111_expected_failure diff --git a/lms/djangoapps/django_comment_client/utils.py b/lms/djangoapps/django_comment_client/utils.py index edfba0b0d145422c2f16af4fe1bf7600d0a674e0..3fbc4f6a321d0d1705b46359afe726dd459800da 100644 --- a/lms/djangoapps/django_comment_client/utils.py +++ b/lms/djangoapps/django_comment_client/utils.py @@ -60,13 +60,6 @@ def strip_blank(dic): # TODO should we be checking if d1 and d2 have the same keys with different values? -def merge_dict(dic1, dic2): - """ - Combines the keys from the two provided dictionaries - """ - return dict(dic1.items() + dic2.items()) - - def get_role_ids(course_id): """ Returns a dictionary having role names as keys and a list of users as values @@ -647,7 +640,9 @@ def get_metadata_for_threads(course_id, threads, user, user_info): def infogetter(thread): return get_annotated_content_infos(course_id, thread, user, user_info) - metadata = reduce(merge_dict, map(infogetter, threads), {}) + metadata = {} + for thread in threads: + metadata.update(infogetter(thread)) return metadata @@ -684,7 +679,8 @@ def extend_content(content): 'roles': roles, 'updated': content['created_at'] != content['updated_at'], } - return merge_dict(content, content_info) + content.update(content_info) + return content def add_courseware_context(content_list, course, user, id_map=None): diff --git a/lms/lib/comment_client/thread.py b/lms/lib/comment_client/thread.py index 2e9aa717eea87a122ed95bf353510f8d38e05437..a73c6f5ec792c162925b93024031e8deaafcbb13 100644 --- a/lms/lib/comment_client/thread.py +++ b/lms/lib/comment_client/thread.py @@ -50,10 +50,14 @@ class Thread(models.Model): # either the 'search' or 'get_all' actions below. Both already use # with_responses=False internally in the comment service, so no additional # optimization is required. - default_params = {'page': 1, - 'per_page': 20, - 'course_id': query_params['course_id']} - params = utils.merge_dict(default_params, utils.strip_blank(utils.strip_none(query_params))) + params = { + 'page': 1, + 'per_page': 20, + 'course_id': query_params['course_id'], + } + params.update( + utils.strip_blank(utils.strip_none(query_params)) + ) if query_params.get('text'): url = cls.url(action='search') diff --git a/lms/lib/comment_client/user.py b/lms/lib/comment_client/user.py index c58092128f685c062fc60afa718ba20caaca493f..d358f09c4068a066a5683a8ca9ccf7434599ea23 100644 --- a/lms/lib/comment_client/user.py +++ b/lms/lib/comment_client/user.py @@ -103,7 +103,7 @@ class User(models.Model): raise utils.CommentClientRequestError("Must provide course_id when retrieving active threads for the user") url = _url_for_user_active_threads(self.id) params = {'course_id': text_type(self.course_id)} - params = utils.merge_dict(params, query_params) + params.update(query_params) response = utils.perform_request( 'get', url, @@ -119,7 +119,7 @@ class User(models.Model): raise utils.CommentClientRequestError("Must provide course_id when retrieving subscribed threads for the user") url = _url_for_user_subscribed_threads(self.id) params = {'course_id': text_type(self.course_id)} - params = utils.merge_dict(params, query_params) + params.update(query_params) response = utils.perform_request( 'get', url, diff --git a/lms/lib/comment_client/utils.py b/lms/lib/comment_client/utils.py index 062989c7d28688f53994a14414508a4b78e44398..a1efde620d9ff25b257be19d65c004dce0f05e7e 100644 --- a/lms/lib/comment_client/utils.py +++ b/lms/lib/comment_client/utils.py @@ -30,10 +30,6 @@ def extract(dic, keys): return strip_none({k: dic.get(k) for k in keys}) -def merge_dict(dic1, dic2): - return dict(dic1.items() + dic2.items()) - - @contextmanager def request_timer(request_id, method, url, tags=None): start = time() @@ -83,7 +79,8 @@ def perform_request(method, url, data_or_params=None, raw=False, params = request_id_dict else: data = None - params = merge_dict(data_or_params, request_id_dict) + params = data_or_params.copy() + params.update(request_id_dict) with request_timer(request_id, method, url, metric_tags): response = requests.request( method,