{"action":"created","comment":{"url":"https://api.github.com/repos/edx/edx-submissions/pulls/comments/31820057","id":31820057,"diff_hunk":"@@ -373,6 +375,44 @@ def get_submissions(student_item_dict, limit=None):\n     return SubmissionSerializer(submission_models, many=True).data\n \n \n+def get_all_submissions(course_id, item_id, item_type, read_replica=True):\n+    \"\"\"For the given item, get the most recent submission for every student who has submitted.\n+\n+    This may return a very large result set! It is implemented as a generator for efficiency.\n+\n+    Args:\n+        course_id, item_id, item_type (string): The values of the respective student_item fields\n+            to filter the submissions by.\n+        read_replica (bool): If true, attempt to use the read replica database.\n+            If no read replica is available, use the default database.\n+\n+    Yields:\n+        Dicts representing the submissions with the following fields:\n+            student_item\n+            attempt_number\n+            submitted_at\n+            created_at\n+            answer\n+\n+    Raises:\n+        Cannot fail unless there's a database error, but may return an empty iterable.\n+    \"\"\"\n+    submission_qs = Submission.objects\n+    if read_replica:\n+        submission_qs = _use_read_replica(submission_qs)\n+    query = submission_qs.select_related('student_item').filter(\n+        student_item__course_id=course_id,\n+        student_item__item_id=item_id,\n+        student_item__item_type=item_type,\n+    ).order_by('student_item__student_id', '-created_at').iterator()","path":"submissions/api.py","position":44,"original_position":43,"commit_id":"b32d34f7e3dbf7b5d2668d201034f1f332454b73","original_commit_id":"25c09c03d5e3e9efaaa14e8e45eb34f0eb082ba3","user":{"login":"smarnach","id":249196,"avatar_url":"https://avatars.githubusercontent.com/u/249196?v=3","gravatar_id":"","url":"https://api.github.com/users/smarnach","html_url":"https://github.com/smarnach","followers_url":"https://api.github.com/users/smarnach/followers","following_url":"https://api.github.com/users/smarnach/following{/other_user}","gists_url":"https://api.github.com/users/smarnach/gists{/gist_id}","starred_url":"https://api.github.com/users/smarnach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smarnach/subscriptions","organizations_url":"https://api.github.com/users/smarnach/orgs","repos_url":"https://api.github.com/users/smarnach/repos","events_url":"https://api.github.com/users/smarnach/events{/privacy}","received_events_url":"https://api.github.com/users/smarnach/received_events","type":"User","site_admin":false},"body":"Thanks.  I changed the ordering to\r\n\r\n   order_by('student_item__student_id', '-submitted_at', '-id')\r\n\r\nThe default ordering on the model is by `'-submitted_at', '-id'`, so i used this over `created_at`.","created_at":"2015-06-05T15:03:27Z","updated_at":"2015-06-05T15:03:27Z","html_url":"https://github.com/edx/edx-submissions/pull/14#discussion_r31820057","pull_request_url":"https://api.github.com/repos/edx/edx-submissions/pulls/14","_links":{"self":{"href":"https://api.github.com/repos/edx/edx-submissions/pulls/comments/31820057"},"html":{"href":"https://github.com/edx/edx-submissions/pull/14#discussion_r31820057"},"pull_request":{"href":"https://api.github.com/repos/edx/edx-submissions/pulls/14"}}},"pull_request":{"url":"https://api.github.com/repos/edx/edx-submissions/pulls/14","id":34098926,"html_url":"https://github.com/edx/edx-submissions/pull/14","diff_url":"https://github.com/edx/edx-submissions/pull/14.diff","patch_url":"https://github.com/edx/edx-submissions/pull/14.patch","issue_url":"https://api.github.com/repos/edx/edx-submissions/issues/14","number":14,"state":"open","locked":false,"title":"Add get_all_submissions method to the API","user":{"login":"bradenmacdonald","id":945577,"avatar_url":"https://avatars.githubusercontent.com/u/945577?v=3","gravatar_id":"","url":"https://api.github.com/users/bradenmacdonald","html_url":"https://github.com/bradenmacdonald","followers_url":"https://api.github.com/users/bradenmacdonald/followers","following_url":"https://api.github.com/users/bradenmacdonald/following{/other_user}","gists_url":"https://api.github.com/users/bradenmacdonald/gists{/gist_id}","starred_url":"https://api.github.com/users/bradenmacdonald/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bradenmacdonald/subscriptions","organizations_url":"https://api.github.com/users/bradenmacdonald/orgs","repos_url":"https://api.github.com/users/bradenmacdonald/repos","events_url":"https://api.github.com/users/bradenmacdonald/events{/privacy}","received_events_url":"https://api.github.com/users/bradenmacdonald/received_events","type":"User","site_admin":false},"body":"This adds a new API method to edx-submissions:\r\n```python\r\nget_all_submissions(course_id, item_id, item_type, read_replica=True)\r\n```\r\n\r\nThis method can be used to fetch all student answers to a particular courseware item, e.g. for CSV export.","created_at":"2015-04-25T02:21:19Z","updated_at":"2015-06-05T15:03:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c610f134c6e384e3a92f416cab3902a98a31a9eb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/edx-submissions/pulls/14/commits","review_comments_url":"https://api.github.com/repos/edx/edx-submissions/pulls/14/comments","review_comment_url":"https://api.github.com/repos/edx/edx-submissions/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/edx-submissions/issues/14/comments","statuses_url":"https://api.github.com/repos/edx/edx-submissions/statuses/b32d34f7e3dbf7b5d2668d201034f1f332454b73","head":{"label":"open-craft:data-export","ref":"data-export","sha":"b32d34f7e3dbf7b5d2668d201034f1f332454b73","user":{"login":"open-craft","id":7414786,"avatar_url":"https://avatars.githubusercontent.com/u/7414786?v=3","gravatar_id":"","url":"https://api.github.com/users/open-craft","html_url":"https://github.com/open-craft","followers_url":"https://api.github.com/users/open-craft/followers","following_url":"https://api.github.com/users/open-craft/following{/other_user}","gists_url":"https://api.github.com/users/open-craft/gists{/gist_id}","starred_url":"https://api.github.com/users/open-craft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/open-craft/subscriptions","organizations_url":"https://api.github.com/users/open-craft/orgs","repos_url":"https://api.github.com/users/open-craft/repos","events_url":"https://api.github.com/users/open-craft/events{/privacy}","received_events_url":"https://api.github.com/users/open-craft/received_events","type":"Organization","site_admin":false},"repo":{"id":34551305,"name":"edx-submissions","full_name":"open-craft/edx-submissions","owner":{"login":"open-craft","id":7414786,"avatar_url":"https://avatars.githubusercontent.com/u/7414786?v=3","gravatar_id":"","url":"https://api.github.com/users/open-craft","html_url":"https://github.com/open-craft","followers_url":"https://api.github.com/users/open-craft/followers","following_url":"https://api.github.com/users/open-craft/following{/other_user}","gists_url":"https://api.github.com/users/open-craft/gists{/gist_id}","starred_url":"https://api.github.com/users/open-craft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/open-craft/subscriptions","organizations_url":"https://api.github.com/users/open-craft/orgs","repos_url":"https://api.github.com/users/open-craft/repos","events_url":"https://api.github.com/users/open-craft/events{/privacy}","received_events_url":"https://api.github.com/users/open-craft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/open-craft/edx-submissions","description":"API for creating submissions and scores","fork":true,"url":"https://api.github.com/repos/open-craft/edx-submissions","forks_url":"https://api.github.com/repos/open-craft/edx-submissions/forks","keys_url":"https://api.github.com/repos/open-craft/edx-submissions/keys{/key_id}","collaborators_url":"https://api.github.com/repos/open-craft/edx-submissions/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/open-craft/edx-submissions/teams","hooks_url":"https://api.github.com/repos/open-craft/edx-submissions/hooks","issue_events_url":"https://api.github.com/repos/open-craft/edx-submissions/issues/events{/number}","events_url":"https://api.github.com/repos/open-craft/edx-submissions/events","assignees_url":"https://api.github.com/repos/open-craft/edx-submissions/assignees{/user}","branches_url":"https://api.github.com/repos/open-craft/edx-submissions/branches{/branch}","tags_url":"https://api.github.com/repos/open-craft/edx-submissions/tags","blobs_url":"https://api.github.com/repos/open-craft/edx-submissions/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/open-craft/edx-submissions/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/open-craft/edx-submissions/git/refs{/sha}","trees_url":"https://api.github.com/repos/open-craft/edx-submissions/git/trees{/sha}","statuses_url":"https://api.github.com/repos/open-craft/edx-submissions/statuses/{sha}","languages_url":"https://api.github.com/repos/open-craft/edx-submissions/languages","stargazers_url":"https://api.github.com/repos/open-craft/edx-submissions/stargazers","contributors_url":"https://api.github.com/repos/open-craft/edx-submissions/contributors","subscribers_url":"https://api.github.com/repos/open-craft/edx-submissions/subscribers","subscription_url":"https://api.github.com/repos/open-craft/edx-submissions/subscription","commits_url":"https://api.github.com/repos/open-craft/edx-submissions/commits{/sha}","git_commits_url":"https://api.github.com/repos/open-craft/edx-submissions/git/commits{/sha}","comments_url":"https://api.github.com/repos/open-craft/edx-submissions/comments{/number}","issue_comment_url":"https://api.github.com/repos/open-craft/edx-submissions/issues/comments{/number}","contents_url":"https://api.github.com/repos/open-craft/edx-submissions/contents/{+path}","compare_url":"https://api.github.com/repos/open-craft/edx-submissions/compare/{base}...{head}","merges_url":"https://api.github.com/repos/open-craft/edx-submissions/merges","archive_url":"https://api.github.com/repos/open-craft/edx-submissions/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/open-craft/edx-submissions/downloads","issues_url":"https://api.github.com/repos/open-craft/edx-submissions/issues{/number}","pulls_url":"https://api.github.com/repos/open-craft/edx-submissions/pulls{/number}","milestones_url":"https://api.github.com/repos/open-craft/edx-submissions/milestones{/number}","notifications_url":"https://api.github.com/repos/open-craft/edx-submissions/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/open-craft/edx-submissions/labels{/name}","releases_url":"https://api.github.com/repos/open-craft/edx-submissions/releases{/id}","created_at":"2015-04-25T02:11:22Z","updated_at":"2015-04-25T02:11:23Z","pushed_at":"2015-06-03T20:55:26Z","git_url":"git://github.com/open-craft/edx-submissions.git","ssh_url":"git@github.com:open-craft/edx-submissions.git","clone_url":"https://github.com/open-craft/edx-submissions.git","svn_url":"https://github.com/open-craft/edx-submissions","homepage":null,"size":175,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"e2361932b9bce061a018a31bb3929e9cade80f49","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":20536064,"name":"edx-submissions","full_name":"edx/edx-submissions","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-submissions","description":"API for creating submissions and scores","fork":false,"url":"https://api.github.com/repos/edx/edx-submissions","forks_url":"https://api.github.com/repos/edx/edx-submissions/forks","keys_url":"https://api.github.com/repos/edx/edx-submissions/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-submissions/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-submissions/teams","hooks_url":"https://api.github.com/repos/edx/edx-submissions/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-submissions/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-submissions/events","assignees_url":"https://api.github.com/repos/edx/edx-submissions/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-submissions/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-submissions/tags","blobs_url":"https://api.github.com/repos/edx/edx-submissions/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-submissions/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-submissions/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-submissions/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-submissions/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-submissions/languages","stargazers_url":"https://api.github.com/repos/edx/edx-submissions/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-submissions/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-submissions/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-submissions/subscription","commits_url":"https://api.github.com/repos/edx/edx-submissions/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-submissions/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-submissions/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-submissions/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-submissions/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-submissions/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-submissions/merges","archive_url":"https://api.github.com/repos/edx/edx-submissions/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-submissions/downloads","issues_url":"https://api.github.com/repos/edx/edx-submissions/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-submissions/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-submissions/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-submissions/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-submissions/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-submissions/releases{/id}","created_at":"2014-06-05T18:19:35Z","updated_at":"2015-04-27T16:13:22Z","pushed_at":"2015-06-03T20:55:26Z","git_url":"git://github.com/edx/edx-submissions.git","ssh_url":"git@github.com:edx/edx-submissions.git","clone_url":"https://github.com/edx/edx-submissions.git","svn_url":"https://github.com/edx/edx-submissions","homepage":null,"size":689,"stargazers_count":4,"watchers_count":4,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":17,"mirror_url":null,"open_issues_count":2,"forks":17,"open_issues":2,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/edx-submissions/pulls/14"},"html":{"href":"https://github.com/edx/edx-submissions/pull/14"},"issue":{"href":"https://api.github.com/repos/edx/edx-submissions/issues/14"},"comments":{"href":"https://api.github.com/repos/edx/edx-submissions/issues/14/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/edx-submissions/pulls/14/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/edx-submissions/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/edx-submissions/pulls/14/commits"},"statuses":{"href":"https://api.github.com/repos/edx/edx-submissions/statuses/b32d34f7e3dbf7b5d2668d201034f1f332454b73"}}}}