{"action":"created","comment":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/comments/45348352","id":45348352,"diff_hunk":"@@ -2,52 +2,122 @@\n Course API Views\n \"\"\"\n \n-from rest_framework.views import APIView\n-from rest_framework.response import Response\n-from rest_framework.reverse import reverse\n+from rest_framework.exceptions import NotFound, PermissionDenied\n+from rest_framework.views import APIView, Response\n \n+from opaque_keys import InvalidKeyError\n from opaque_keys.edx.keys import CourseKey\n+\n+\n from openedx.core.lib.api.view_utils import view_auth_classes\n-from xmodule.modulestore.django import modulestore\n+\n+from .api import course_detail, list_courses\n \n \n @view_auth_classes()\n-class CourseView(APIView):\n+class CourseDetailView(APIView):\n     \"\"\"\n-    Course API view\n+    View class to describe a course\n     \"\"\"\n \n     def get(self, request, course_key_string):\n         \"\"\"\n         Request information on a course specified by `course_key_string`.\n-            Body consists of a `blocks_url` that can be used to fetch the\n-            blocks for the requested course.\n+\n+        Body consists of the following fields:\n+            * `blocks_url`: can be used to fetch the blocks\n+            * `course_image`:\n+            * `description`:\n+            * `end`: Date the course ends\n+            * `enrollment_end`: Date enrollment ends\n+            * `enrollment_start`: Date enrollment begins\n+            * `id`: Course key\n+            * `name`: Name of the course\n+            * `number`: Catalog number of the course\n+            * `org`: Name of the organization that owns the course\n+            * `start`: Date the course begins\n+            * `start_display`: Readably formatted start of the course\n+            * `start_type`: Hint describing how `start_display` is set. One of:\n+                  - `\"string\"`: manually set\n+                  - `\"timestamp\"`: generated form `start` timestamp\n+                  - `\"empty\"`: the start date should not be shown\n \n         Arguments:\n-            request (HttpRequest)\n-            course_key_string\n+            request: (HttpRequest)\n+            course_key_string: (string) Key for the desired course\n+\n+        Parameters:\n+            username (optional):\n+                The username of the specified user whose visible courses we\n+                want to see.  Defaults to the current user.\n \n         Returns:\n             HttpResponse: 200 on success\n \n-\n         Example Usage:\n-\n             GET /api/courses/v1/[course_key_string]\n             200 OK\n \n         Example response:\n+            {\n+                \"blocks_url\": \"/api/courses/v1/blocks/?course_id=edX%2Ftoy%2F2012_Fall\",\n+                \"course_image\": \"/c4x/edX/toy/asset/just_a_test.jpg\",\n+                \"description\": \"A course about toys.\",\n+                \"end\": \"2015-09-19T18:00:00Z\",\n+                \"enrollment_end\": \"2015-07-15T00:00:00Z\",\n+                \"enrollment_start\": \"2015-06-15T00:00:00Z\",\n+                \"id\": \"edX/toy/2012_Fall\",\n+                \"name\": \"Toy Course\",\n+                \"number\": \"toy\",\n+                \"org\": \"edX\",\n+                \"start\": \"2015-07-17T12:00:00Z\",\n+                \"start_display\": \"July 17, 2015\",\n+                \"start_type\": \"timestamp\"\n+            }\n+        \"\"\"\n+        username = request.query_params.get('username', request.user.username)\n+        try:\n+            course_key = CourseKey.from_string(course_key_string)\n+        except InvalidKeyError:\n+            raise NotFound()\n+        try:\n+            content = course_detail(self.request.user, username, course_key, request)\n+        except PermissionDenied:\n+            raise NotFound()\n+        return Response(content.data)\n+\n \n-            {\"blocks_url\": \"https://server/api/courses/v1/blocks/[usage_key]\"}\n+class CourseListView(APIView):\n+    \"\"\"\n+    View class to list multiple courses\n+    \"\"\"\n+\n+    def get(self, request):\n         \"\"\"\n+        Request information on all courses visible to the specified user.\n+\n+        Body consists of a list of objects as returned by `CourseDetailView`.\n+\n+        Arguments:\n+            request (HttpRequest)\n \n-        course_key = CourseKey.from_string(course_key_string)\n-        course_usage_key = modulestore().make_course_usage_key(course_key)\n+        Parameters:\n+            username (optional):\n+                The username of the specified user whose visible courses we\n+                want to see.  Defaults to the current user.\n \n-        blocks_url = reverse(\n-            'blocks_in_block_tree',\n-            kwargs={'usage_key_string': unicode(course_usage_key)},\n-            request=request,\n-        )\n+        Returns:\n+            - A 404 response, if the specified user does not exist, or the\n+              requesting user does not have permission to view their\n+              courses.\n+\n+            - A 200 response, if the request is successful, with a list of\n+              course discovery objects as returned by `CourseDetailView`.","path":"lms/djangoapps/course_api/views.py","position":134,"original_position":134,"commit_id":"9359715d31c789b2e90043713e746e5c14796677","original_commit_id":"9359715d31c789b2e90043713e746e5c14796677","user":{"login":"BenjiLee","id":7101723,"avatar_url":"https://avatars.githubusercontent.com/u/7101723?v=3","gravatar_id":"","url":"https://api.github.com/users/BenjiLee","html_url":"https://github.com/BenjiLee","followers_url":"https://api.github.com/users/BenjiLee/followers","following_url":"https://api.github.com/users/BenjiLee/following{/other_user}","gists_url":"https://api.github.com/users/BenjiLee/gists{/gist_id}","starred_url":"https://api.github.com/users/BenjiLee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BenjiLee/subscriptions","organizations_url":"https://api.github.com/users/BenjiLee/orgs","repos_url":"https://api.github.com/users/BenjiLee/repos","events_url":"https://api.github.com/users/BenjiLee/events{/privacy}","received_events_url":"https://api.github.com/users/BenjiLee/received_events","type":"User","site_admin":false},"body":"nit: Add \"Raises\" doc","created_at":"2015-11-19T14:43:53Z","updated_at":"2015-11-19T14:43:53Z","html_url":"https://github.com/edx/edx-platform/pull/10576#discussion_r45348352","pull_request_url":"https://api.github.com/repos/edx/edx-platform/pulls/10576","_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/comments/45348352"},"html":{"href":"https://github.com/edx/edx-platform/pull/10576#discussion_r45348352"},"pull_request":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/10576"}}},"pull_request":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/10576","id":50303431,"html_url":"https://github.com/edx/edx-platform/pull/10576","diff_url":"https://github.com/edx/edx-platform/pull/10576.diff","patch_url":"https://github.com/edx/edx-platform/pull/10576.patch","issue_url":"https://api.github.com/repos/edx/edx-platform/issues/10576","number":10576,"state":"open","locked":false,"title":"Added new Course List API and refactored into an api.py","user":{"login":"jcdyer","id":77486,"avatar_url":"https://avatars.githubusercontent.com/u/77486?v=3","gravatar_id":"","url":"https://api.github.com/users/jcdyer","html_url":"https://github.com/jcdyer","followers_url":"https://api.github.com/users/jcdyer/followers","following_url":"https://api.github.com/users/jcdyer/following{/other_user}","gists_url":"https://api.github.com/users/jcdyer/gists{/gist_id}","starred_url":"https://api.github.com/users/jcdyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcdyer/subscriptions","organizations_url":"https://api.github.com/users/jcdyer/orgs","repos_url":"https://api.github.com/users/jcdyer/repos","events_url":"https://api.github.com/users/jcdyer/events{/privacy}","received_events_url":"https://api.github.com/users/jcdyer/received_events","type":"User","site_admin":false},"body":"Created from #10310 because I was having trouble finding the branch.  Rebased onto latest origin/master\r\n\r\n* Pagination is still to be done (on a separate PR).\r\n* Excluding expensive fields from list view will be handled in a separate PR.\r\n* Field naming is open for debate. \r\n\r\nhttps://openedx.atlassian.net/browse/MA-1625\r\n\r\nPlease review @cpennington @nasthagiri @BenjiLee \r\nFYI @aleffert @mjfrey @mattdrayer \r\n\r\n","created_at":"2015-11-10T20:02:28Z","updated_at":"2015-11-19T14:43:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bbba5152ee1a6fb8635badeca323d9140fe6efcd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/edx-platform/pulls/10576/commits","review_comments_url":"https://api.github.com/repos/edx/edx-platform/pulls/10576/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/10576/comments","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/9359715d31c789b2e90043713e746e5c14796677","head":{"label":"edx:cdyer/course-list-api","ref":"cdyer/course-list-api","sha":"9359715d31c789b2e90043713e746e5c14796677","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}","created_at":"2013-05-30T20:20:38Z","updated_at":"2015-11-19T06:03:41Z","pushed_at":"2015-11-19T14:43:16Z","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":622689,"stargazers_count":2244,"watchers_count":2244,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1372,"mirror_url":null,"open_issues_count":168,"forks":1372,"open_issues":168,"watchers":2244,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"ce99ca63fa9376386bfe073c8380964488df11c7","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}","created_at":"2013-05-30T20:20:38Z","updated_at":"2015-11-19T06:03:41Z","pushed_at":"2015-11-19T14:43:16Z","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":622689,"stargazers_count":2244,"watchers_count":2244,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1372,"mirror_url":null,"open_issues_count":168,"forks":1372,"open_issues":168,"watchers":2244,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/10576"},"html":{"href":"https://github.com/edx/edx-platform/pull/10576"},"issue":{"href":"https://api.github.com/repos/edx/edx-platform/issues/10576"},"comments":{"href":"https://api.github.com/repos/edx/edx-platform/issues/10576/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/10576/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/10576/commits"},"statuses":{"href":"https://api.github.com/repos/edx/edx-platform/statuses/9359715d31c789b2e90043713e746e5c14796677"}}}}