{"action":"created","comment":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/comments/52675129","id":52675129,"diff_hunk":"@@ -156,9 +158,47 @@ def get_valid_input(request_data, ignore_missing=False):\n             field_errors['max_students_allowed'] = {'error_code': 'invalid_max_students_allowed'}\n     elif 'max_students_allowed' in request_data:\n         field_errors['max_students_allowed'] = {'error_code': 'null_field_max_students_allowed'}\n+\n+    course_modules = request_data.get('course_modules')\n+    if course_modules is not None:\n+        if isinstance(course_modules, list):\n+            for course_module_id in course_modules:\n+                try:\n+                    UsageKey.from_string(course_module_id)\n+                except InvalidKeyError:\n+                    field_errors['course_modules'] = {'error_code': 'invalid_course_module_keys'}\n+                    break\n+            else:\n+                valid_input['course_modules'] = course_modules\n+        else:\n+            field_errors['course_modules'] = {'error_code': 'invalid_course_module_list'}\n+    elif 'course_modules' in request_data:\n+        # case if the user actually passed null as input\n+        valid_input['course_modules'] = None\n+\n     return valid_input, field_errors\n \n \n+def valid_course_modules(course_module_list, master_course_key):\n+    \"\"\"\n+    Function to validate that each element in the course_module_list belongs\n+    to the master course structure.\n+    Args:\n+        course_module_list (list): A list of strings representing Block Usage Keys\n+        master_course_key (CourseKey): An object representing the master course key id\n+\n+    Returns:\n+        bool: whether or not all the course module strings belong to the master course\n+    \"\"\"\n+    try:\n+        course_structure_obj = CourseStructure.objects.get(course_id=master_course_key)\n+    except CourseStructure.DoesNotExist:\n+        return False\n+    course_structure = course_structure_obj.structure\n+    course_chapters = course_structure['blocks'][course_structure['root']].get('children', [])","path":"lms/djangoapps/ccx/api/v0/views.py","position":60,"original_position":60,"commit_id":"0e3e56e42ae2330b171c8a5a8bc4a680652d4663","original_commit_id":"0e3e56e42ae2330b171c8a5a8bc4a680652d4663","user":{"login":"doctoryes","id":7285237,"avatar_url":"https://avatars.githubusercontent.com/u/7285237?v=3","gravatar_id":"","url":"https://api.github.com/users/doctoryes","html_url":"https://github.com/doctoryes","followers_url":"https://api.github.com/users/doctoryes/followers","following_url":"https://api.github.com/users/doctoryes/following{/other_user}","gists_url":"https://api.github.com/users/doctoryes/gists{/gist_id}","starred_url":"https://api.github.com/users/doctoryes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/doctoryes/subscriptions","organizations_url":"https://api.github.com/users/doctoryes/orgs","repos_url":"https://api.github.com/users/doctoryes/repos","events_url":"https://api.github.com/users/doctoryes/events{/privacy}","received_events_url":"https://api.github.com/users/doctoryes/received_events","type":"User","site_admin":false},"body":"Since this logic is used in the test code as well *and* because logic defines the paid unit of a CCX course, it'd be nice to move it out into a well-defined method that both places use.","created_at":"2016-02-11T22:05:41Z","updated_at":"2016-02-11T22:05:41Z","html_url":"https://github.com/edx/edx-platform/pull/11356#discussion_r52675129","pull_request_url":"https://api.github.com/repos/edx/edx-platform/pulls/11356","_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/comments/52675129"},"html":{"href":"https://github.com/edx/edx-platform/pull/11356#discussion_r52675129"},"pull_request":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/11356"}}},"pull_request":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/11356","id":57402811,"html_url":"https://github.com/edx/edx-platform/pull/11356","diff_url":"https://github.com/edx/edx-platform/pull/11356.diff","patch_url":"https://github.com/edx/edx-platform/pull/11356.patch","issue_url":"https://api.github.com/repos/edx/edx-platform/issues/11356","number":11356,"state":"open","locked":false,"title":"Added extra field to CCX model for Course Models","user":{"login":"giocalitri","id":1005204,"avatar_url":"https://avatars.githubusercontent.com/u/1005204?v=3","gravatar_id":"","url":"https://api.github.com/users/giocalitri","html_url":"https://github.com/giocalitri","followers_url":"https://api.github.com/users/giocalitri/followers","following_url":"https://api.github.com/users/giocalitri/following{/other_user}","gists_url":"https://api.github.com/users/giocalitri/gists{/gist_id}","starred_url":"https://api.github.com/users/giocalitri/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/giocalitri/subscriptions","organizations_url":"https://api.github.com/users/giocalitri/orgs","repos_url":"https://api.github.com/users/giocalitri/repos","events_url":"https://api.github.com/users/giocalitri/events{/privacy}","received_events_url":"https://api.github.com/users/giocalitri/received_events","type":"User","site_admin":false},"body":"This PR extends the CCX model and the [CCX REST APIs](https://github.com/edx/edx-platform/pull/11166) to support the creation of CCX with a list of Course Modules stored in a JSON field.\r\n\r\nTo test this PR, please follow the instructions on the description of the [CCX REST APIs PR](https://github.com/edx/edx-platform/pull/11166).\r\n\r\nFor more info see https://github.com/mitocw/edx-platform/issues/170","created_at":"2016-01-27T18:35:45Z","updated_at":"2016-02-11T22:05:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"75894436d9326eb78fe67e333fe44c36d877d1b3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/edx-platform/pulls/11356/commits","review_comments_url":"https://api.github.com/repos/edx/edx-platform/pulls/11356/comments","review_comment_url":"https://api.github.com/repos/edx/edx-platform/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/edx-platform/issues/11356/comments","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/0e3e56e42ae2330b171c8a5a8bc4a680652d4663","head":{"label":"mitocw:gdm_ccx_course_modules_#170","ref":"gdm_ccx_course_modules_#170","sha":"0e3e56e42ae2330b171c8a5a8bc4a680652d4663","user":{"login":"mitocw","id":3009146,"avatar_url":"https://avatars.githubusercontent.com/u/3009146?v=3","gravatar_id":"","url":"https://api.github.com/users/mitocw","html_url":"https://github.com/mitocw","followers_url":"https://api.github.com/users/mitocw/followers","following_url":"https://api.github.com/users/mitocw/following{/other_user}","gists_url":"https://api.github.com/users/mitocw/gists{/gist_id}","starred_url":"https://api.github.com/users/mitocw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitocw/subscriptions","organizations_url":"https://api.github.com/users/mitocw/orgs","repos_url":"https://api.github.com/users/mitocw/repos","events_url":"https://api.github.com/users/mitocw/events{/privacy}","received_events_url":"https://api.github.com/users/mitocw/received_events","type":"Organization","site_admin":false},"repo":{"id":17842334,"name":"edx-platform","full_name":"mitocw/edx-platform","owner":{"login":"mitocw","id":3009146,"avatar_url":"https://avatars.githubusercontent.com/u/3009146?v=3","gravatar_id":"","url":"https://api.github.com/users/mitocw","html_url":"https://github.com/mitocw","followers_url":"https://api.github.com/users/mitocw/followers","following_url":"https://api.github.com/users/mitocw/following{/other_user}","gists_url":"https://api.github.com/users/mitocw/gists{/gist_id}","starred_url":"https://api.github.com/users/mitocw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitocw/subscriptions","organizations_url":"https://api.github.com/users/mitocw/orgs","repos_url":"https://api.github.com/users/mitocw/repos","events_url":"https://api.github.com/users/mitocw/events{/privacy}","received_events_url":"https://api.github.com/users/mitocw/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mitocw/edx-platform","description":"the edX learning management system (LMS) and course authoring tool, Studio","fork":true,"url":"https://api.github.com/repos/mitocw/edx-platform","forks_url":"https://api.github.com/repos/mitocw/edx-platform/forks","keys_url":"https://api.github.com/repos/mitocw/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mitocw/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mitocw/edx-platform/teams","hooks_url":"https://api.github.com/repos/mitocw/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/mitocw/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/mitocw/edx-platform/events","assignees_url":"https://api.github.com/repos/mitocw/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/mitocw/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/mitocw/edx-platform/tags","blobs_url":"https://api.github.com/repos/mitocw/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mitocw/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mitocw/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/mitocw/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mitocw/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/mitocw/edx-platform/languages","stargazers_url":"https://api.github.com/repos/mitocw/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/mitocw/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/mitocw/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/mitocw/edx-platform/subscription","commits_url":"https://api.github.com/repos/mitocw/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/mitocw/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/mitocw/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/mitocw/edx-platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/mitocw/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/mitocw/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mitocw/edx-platform/merges","archive_url":"https://api.github.com/repos/mitocw/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mitocw/edx-platform/downloads","issues_url":"https://api.github.com/repos/mitocw/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/mitocw/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/mitocw/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/mitocw/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mitocw/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/mitocw/edx-platform/releases{/id}","deployments_url":"https://api.github.com/repos/mitocw/edx-platform/deployments","created_at":"2014-03-17T20:32:05Z","updated_at":"2016-01-11T19:42:28Z","pushed_at":"2016-02-11T20:44:23Z","git_url":"git://github.com/mitocw/edx-platform.git","ssh_url":"git@github.com:mitocw/edx-platform.git","clone_url":"https://github.com/mitocw/edx-platform.git","svn_url":"https://github.com/mitocw/edx-platform","homepage":"http://code.edx.org/","size":593391,"stargazers_count":3,"watchers_count":3,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":88,"forks":1,"open_issues":88,"watchers":3,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"806048d4bba9a390dfcad050ac5c8df33a5ba85a","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":10391073,"name":"edx-platform","full_name":"edx/edx-platform","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-platform","description":"The Open edX platform, the software that powers edX!","fork":false,"url":"https://api.github.com/repos/edx/edx-platform","forks_url":"https://api.github.com/repos/edx/edx-platform/forks","keys_url":"https://api.github.com/repos/edx/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-platform/teams","hooks_url":"https://api.github.com/repos/edx/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-platform/events","assignees_url":"https://api.github.com/repos/edx/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-platform/tags","blobs_url":"https://api.github.com/repos/edx/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-platform/languages","stargazers_url":"https://api.github.com/repos/edx/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-platform/subscription","commits_url":"https://api.github.com/repos/edx/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-platform/merges","archive_url":"https://api.github.com/repos/edx/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-platform/downloads","issues_url":"https://api.github.com/repos/edx/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-platform/releases{/id}","deployments_url":"https://api.github.com/repos/edx/edx-platform/deployments","created_at":"2013-05-30T20:20:38Z","updated_at":"2016-02-11T12:24:28Z","pushed_at":"2016-02-11T22:01:14Z","git_url":"git://github.com/edx/edx-platform.git","ssh_url":"git@github.com:edx/edx-platform.git","clone_url":"https://github.com/edx/edx-platform.git","svn_url":"https://github.com/edx/edx-platform","homepage":"http://open.edx.org/","size":685485,"stargazers_count":2382,"watchers_count":2382,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1453,"mirror_url":null,"open_issues_count":155,"forks":1453,"open_issues":155,"watchers":2382,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/11356"},"html":{"href":"https://github.com/edx/edx-platform/pull/11356"},"issue":{"href":"https://api.github.com/repos/edx/edx-platform/issues/11356"},"comments":{"href":"https://api.github.com/repos/edx/edx-platform/issues/11356/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/11356/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/11356/commits"},"statuses":{"href":"https://api.github.com/repos/edx/edx-platform/statuses/0e3e56e42ae2330b171c8a5a8bc4a680652d4663"}}}}