{"action":"created","comment":{"url":"https://api.github.com/repos/harvard-lil/capstone/pulls/comments/171919644","pull_request_review_id":100853484,"id":171919644,"diff_hunk":"@@ -75,64 +76,38 @@ class CaseViewSet(BaseViewMixin, mixins.RetrieveModelMixin, mixins.ListModelMixi\n         'court',\n         'volume',\n         'reporter',\n-    ).prefetch_related('citations')\n+    ).prefetch_related('citation')\n     renderer_classes = (renderers.BrowsableAPIRenderer, renderers.JSONRenderer)\n     permission_classes = (permissions.IsAPIUser,)\n     filter_class = filters.CaseFilter\n-    lookup_field = 'slug'\n+    lookup_field = 'id'\n     order_by = 'decision_date'\n \n-    def download(self, **kwargs):\n-        if kwargs.get(self.lookup_field):\n-            try:\n-                case_list = [models.CaseMetadata.objects.get(**kwargs)]\n-            except models.CaseMetadata.DoesNotExist as e:\n-                return JsonResponse({\n-                    'message': 'Unable to find case with matching slug: %s' % e\n-                }, status=404, )\n-\n+    def get_serializer_class(self, *args, **kwargs):\n+        full_case = self.request.query_params.get('full_case', 'false').lower()\n+        if full_case == 'true':\n+            return serializers.CaseSerializerWithCasebody\n         else:\n-            cases = self.queryset.all()\n-            for backend in list(self.filter_backends):\n-                cases = backend().filter_queryset(self.request, cases, self)\n-\n-            # user is requesting a zip but there is nothing to zip, so 404 is the right response.\n-            # See https://stackoverflow.com/a/11760249/307769\n-            if not cases.exists():\n-                return JsonResponse({\n-                    'message': 'Request did not return any results.',\n-                }, status=404, )\n-\n-            case_list = self.paginate_queryset(cases)\n-\n-        blacklisted_case_count = len(list((case for case in case_list if not case.jurisdiction.whitelisted)))\n-\n-        try:\n-            # check user's case allowance against blacklisted\n-            user = serializers.UserSerializer().verify_case_allowance(self.request.user, blacklisted_case_count)\n-        except ValidationError as err:\n-            return JsonResponse(err.detail, status=403)\n-\n-        filename = resources.create_zip_filename(case_list)\n-\n-        case_response = serializers.CaseSerializerWithCasebody(case_list, many=True, context={'request': self.request})\n-        case_data = case_response.data\n-        response = resources.create_download_response(filename=filename, content=case_data)\n-        user.update_case_allowance(case_count=blacklisted_case_count)\n-\n-        return response\n+            return self.serializer_class\n \n     def list(self, *args, **kwargs):\n-        if not self.request.query_params.get('type') == 'download':\n-            return super(CaseViewSet, self).list(*args, **kwargs)\n-        else:\n-            return self.download(**kwargs)\n+        self.serializer_class = self.get_serializer_class(self, *args, **kwargs)","path":"capstone/capapi/views.py","position":91,"original_position":91,"commit_id":"c0fe6cff7aa08f8f736743740343f6a904c32a0c","original_commit_id":"c0fe6cff7aa08f8f736743740343f6a904c32a0c","user":{"login":"jcushman","id":376272,"avatar_url":"https://avatars3.githubusercontent.com/u/376272?v=4","gravatar_id":"","url":"https://api.github.com/users/jcushman","html_url":"https://github.com/jcushman","followers_url":"https://api.github.com/users/jcushman/followers","following_url":"https://api.github.com/users/jcushman/following{/other_user}","gists_url":"https://api.github.com/users/jcushman/gists{/gist_id}","starred_url":"https://api.github.com/users/jcushman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcushman/subscriptions","organizations_url":"https://api.github.com/users/jcushman/orgs","repos_url":"https://api.github.com/users/jcushman/repos","events_url":"https://api.github.com/users/jcushman/events{/privacy}","received_events_url":"https://api.github.com/users/jcushman/received_events","type":"User","site_admin":false},"body":"Don't think this line is necessary -- `self.get_serializer_class` is called automatically by `self.get_serializer`, which is called by `super`.","created_at":"2018-03-02T18:05:46Z","updated_at":"2018-03-02T19:03:33Z","html_url":"https://github.com/harvard-lil/capstone/pull/185#discussion_r171919644","pull_request_url":"https://api.github.com/repos/harvard-lil/capstone/pulls/185","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/harvard-lil/capstone/pulls/comments/171919644"},"html":{"href":"https://github.com/harvard-lil/capstone/pull/185#discussion_r171919644"},"pull_request":{"href":"https://api.github.com/repos/harvard-lil/capstone/pulls/185"}}},"pull_request":{"url":"https://api.github.com/repos/harvard-lil/capstone/pulls/185","id":172339999,"html_url":"https://github.com/harvard-lil/capstone/pull/185","diff_url":"https://github.com/harvard-lil/capstone/pull/185.diff","patch_url":"https://github.com/harvard-lil/capstone/pull/185.patch","issue_url":"https://api.github.com/repos/harvard-lil/capstone/issues/185","number":185,"state":"open","locked":false,"title":"Citation rearchitecture and serving up some casebody formats","user":{"login":"anastasia","id":1494102,"avatar_url":"https://avatars0.githubusercontent.com/u/1494102?v=4","gravatar_id":"","url":"https://api.github.com/users/anastasia","html_url":"https://github.com/anastasia","followers_url":"https://api.github.com/users/anastasia/followers","following_url":"https://api.github.com/users/anastasia/following{/other_user}","gists_url":"https://api.github.com/users/anastasia/gists{/gist_id}","starred_url":"https://api.github.com/users/anastasia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anastasia/subscriptions","organizations_url":"https://api.github.com/users/anastasia/orgs","repos_url":"https://api.github.com/users/anastasia/repos","events_url":"https://api.github.com/users/anastasia/events{/privacy}","received_events_url":"https://api.github.com/users/anastasia/received_events","type":"User","site_admin":false},"body":"- moved from the inconsistent `/cases/slugified-citation` to `/cases/id`\r\n- allowing users to use the shorthand `/cases/real-citation` and redirecting users to `/cases/?cite=real-citation` which returns a list of cases that match the citation\r\n- allowing users to use normalized cite in the same way: `/cases/normalized-cite` redirects to `/cases/?cite=real-citation`\r\n- restructured the way API permissions are done, see note in code\r\n- removed download functionality\r\n- allowing user to request full_case in browser if case is whitelisted with no api token\r\n- allowing user to get full_case if they have the proper credentials (in near future would be nice to allow passing apikey as param)\r\n- allowing casebody's body_format parameter to be set to xml and html (defaults to text) if `format` param is set to `json` or `api` or is missing (defaults to `api`)\r\n\r\nThis pull request includes migrations! Should discuss how best to handle them.\r\n\r\n\r\nThis pull request does not cover!\r\n- documentation - if we agree on these approaches I will absolutely rewrite the docs and add a lot more examples. Thought it best not to rewrite them before I know for sure this is correct.\r\n- A big sweep of format requests:\r\n  Not returning a full XML case yet (cases/id/?format=xml), just metadata + xml body. Need to spend a bit more time on this and didn't want to hold this up even more\r\n  Not returning a full HTML case yet (cases/id/?format=html), just metadata + html body. This should be a quick one because @ChefAndy did all the work. \r\n","created_at":"2018-03-01T20:07:59Z","updated_at":"2018-03-02T19:03:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7d11bd800534f5b7013c0b0ac7df630404af4bbf","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/harvard-lil/capstone/pulls/185/commits","review_comments_url":"https://api.github.com/repos/harvard-lil/capstone/pulls/185/comments","review_comment_url":"https://api.github.com/repos/harvard-lil/capstone/pulls/comments{/number}","comments_url":"https://api.github.com/repos/harvard-lil/capstone/issues/185/comments","statuses_url":"https://api.github.com/repos/harvard-lil/capstone/statuses/c0fe6cff7aa08f8f736743740343f6a904c32a0c","head":{"label":"anastasia:citations-and-casebody-renderers","ref":"citations-and-casebody-renderers","sha":"c0fe6cff7aa08f8f736743740343f6a904c32a0c","user":{"login":"anastasia","id":1494102,"avatar_url":"https://avatars0.githubusercontent.com/u/1494102?v=4","gravatar_id":"","url":"https://api.github.com/users/anastasia","html_url":"https://github.com/anastasia","followers_url":"https://api.github.com/users/anastasia/followers","following_url":"https://api.github.com/users/anastasia/following{/other_user}","gists_url":"https://api.github.com/users/anastasia/gists{/gist_id}","starred_url":"https://api.github.com/users/anastasia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anastasia/subscriptions","organizations_url":"https://api.github.com/users/anastasia/orgs","repos_url":"https://api.github.com/users/anastasia/repos","events_url":"https://api.github.com/users/anastasia/events{/privacy}","received_events_url":"https://api.github.com/users/anastasia/received_events","type":"User","site_admin":false},"repo":{"id":96358478,"name":"capstone","full_name":"anastasia/capstone","owner":{"login":"anastasia","id":1494102,"avatar_url":"https://avatars0.githubusercontent.com/u/1494102?v=4","gravatar_id":"","url":"https://api.github.com/users/anastasia","html_url":"https://github.com/anastasia","followers_url":"https://api.github.com/users/anastasia/followers","following_url":"https://api.github.com/users/anastasia/following{/other_user}","gists_url":"https://api.github.com/users/anastasia/gists{/gist_id}","starred_url":"https://api.github.com/users/anastasia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anastasia/subscriptions","organizations_url":"https://api.github.com/users/anastasia/orgs","repos_url":"https://api.github.com/users/anastasia/repos","events_url":"https://api.github.com/users/anastasia/events{/privacy}","received_events_url":"https://api.github.com/users/anastasia/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/anastasia/capstone","description":"CAP database scripts.","fork":true,"url":"https://api.github.com/repos/anastasia/capstone","forks_url":"https://api.github.com/repos/anastasia/capstone/forks","keys_url":"https://api.github.com/repos/anastasia/capstone/keys{/key_id}","collaborators_url":"https://api.github.com/repos/anastasia/capstone/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/anastasia/capstone/teams","hooks_url":"https://api.github.com/repos/anastasia/capstone/hooks","issue_events_url":"https://api.github.com/repos/anastasia/capstone/issues/events{/number}","events_url":"https://api.github.com/repos/anastasia/capstone/events","assignees_url":"https://api.github.com/repos/anastasia/capstone/assignees{/user}","branches_url":"https://api.github.com/repos/anastasia/capstone/branches{/branch}","tags_url":"https://api.github.com/repos/anastasia/capstone/tags","blobs_url":"https://api.github.com/repos/anastasia/capstone/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/anastasia/capstone/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/anastasia/capstone/git/refs{/sha}","trees_url":"https://api.github.com/repos/anastasia/capstone/git/trees{/sha}","statuses_url":"https://api.github.com/repos/anastasia/capstone/statuses/{sha}","languages_url":"https://api.github.com/repos/anastasia/capstone/languages","stargazers_url":"https://api.github.com/repos/anastasia/capstone/stargazers","contributors_url":"https://api.github.com/repos/anastasia/capstone/contributors","subscribers_url":"https://api.github.com/repos/anastasia/capstone/subscribers","subscription_url":"https://api.github.com/repos/anastasia/capstone/subscription","commits_url":"https://api.github.com/repos/anastasia/capstone/commits{/sha}","git_commits_url":"https://api.github.com/repos/anastasia/capstone/git/commits{/sha}","comments_url":"https://api.github.com/repos/anastasia/capstone/comments{/number}","issue_comment_url":"https://api.github.com/repos/anastasia/capstone/issues/comments{/number}","contents_url":"https://api.github.com/repos/anastasia/capstone/contents/{+path}","compare_url":"https://api.github.com/repos/anastasia/capstone/compare/{base}...{head}","merges_url":"https://api.github.com/repos/anastasia/capstone/merges","archive_url":"https://api.github.com/repos/anastasia/capstone/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/anastasia/capstone/downloads","issues_url":"https://api.github.com/repos/anastasia/capstone/issues{/number}","pulls_url":"https://api.github.com/repos/anastasia/capstone/pulls{/number}","milestones_url":"https://api.github.com/repos/anastasia/capstone/milestones{/number}","notifications_url":"https://api.github.com/repos/anastasia/capstone/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/anastasia/capstone/labels{/name}","releases_url":"https://api.github.com/repos/anastasia/capstone/releases{/id}","deployments_url":"https://api.github.com/repos/anastasia/capstone/deployments","created_at":"2017-07-05T20:27:05Z","updated_at":"2017-07-05T20:27:07Z","pushed_at":"2018-03-01T20:07:44Z","git_url":"git://github.com/anastasia/capstone.git","ssh_url":"git@github.com:anastasia/capstone.git","clone_url":"https://github.com/anastasia/capstone.git","svn_url":"https://github.com/anastasia/capstone","homepage":null,"size":26757,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"harvard-lil:develop","ref":"develop","sha":"1e61432a40b1fc65db8781802fd5053864461516","user":{"login":"harvard-lil","id":857200,"avatar_url":"https://avatars0.githubusercontent.com/u/857200?v=4","gravatar_id":"","url":"https://api.github.com/users/harvard-lil","html_url":"https://github.com/harvard-lil","followers_url":"https://api.github.com/users/harvard-lil/followers","following_url":"https://api.github.com/users/harvard-lil/following{/other_user}","gists_url":"https://api.github.com/users/harvard-lil/gists{/gist_id}","starred_url":"https://api.github.com/users/harvard-lil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harvard-lil/subscriptions","organizations_url":"https://api.github.com/users/harvard-lil/orgs","repos_url":"https://api.github.com/users/harvard-lil/repos","events_url":"https://api.github.com/users/harvard-lil/events{/privacy}","received_events_url":"https://api.github.com/users/harvard-lil/received_events","type":"Organization","site_admin":false},"repo":{"id":82964836,"name":"capstone","full_name":"harvard-lil/capstone","owner":{"login":"harvard-lil","id":857200,"avatar_url":"https://avatars0.githubusercontent.com/u/857200?v=4","gravatar_id":"","url":"https://api.github.com/users/harvard-lil","html_url":"https://github.com/harvard-lil","followers_url":"https://api.github.com/users/harvard-lil/followers","following_url":"https://api.github.com/users/harvard-lil/following{/other_user}","gists_url":"https://api.github.com/users/harvard-lil/gists{/gist_id}","starred_url":"https://api.github.com/users/harvard-lil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harvard-lil/subscriptions","organizations_url":"https://api.github.com/users/harvard-lil/orgs","repos_url":"https://api.github.com/users/harvard-lil/repos","events_url":"https://api.github.com/users/harvard-lil/events{/privacy}","received_events_url":"https://api.github.com/users/harvard-lil/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/harvard-lil/capstone","description":"CAP database scripts.","fork":false,"url":"https://api.github.com/repos/harvard-lil/capstone","forks_url":"https://api.github.com/repos/harvard-lil/capstone/forks","keys_url":"https://api.github.com/repos/harvard-lil/capstone/keys{/key_id}","collaborators_url":"https://api.github.com/repos/harvard-lil/capstone/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/harvard-lil/capstone/teams","hooks_url":"https://api.github.com/repos/harvard-lil/capstone/hooks","issue_events_url":"https://api.github.com/repos/harvard-lil/capstone/issues/events{/number}","events_url":"https://api.github.com/repos/harvard-lil/capstone/events","assignees_url":"https://api.github.com/repos/harvard-lil/capstone/assignees{/user}","branches_url":"https://api.github.com/repos/harvard-lil/capstone/branches{/branch}","tags_url":"https://api.github.com/repos/harvard-lil/capstone/tags","blobs_url":"https://api.github.com/repos/harvard-lil/capstone/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/harvard-lil/capstone/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/harvard-lil/capstone/git/refs{/sha}","trees_url":"https://api.github.com/repos/harvard-lil/capstone/git/trees{/sha}","statuses_url":"https://api.github.com/repos/harvard-lil/capstone/statuses/{sha}","languages_url":"https://api.github.com/repos/harvard-lil/capstone/languages","stargazers_url":"https://api.github.com/repos/harvard-lil/capstone/stargazers","contributors_url":"https://api.github.com/repos/harvard-lil/capstone/contributors","subscribers_url":"https://api.github.com/repos/harvard-lil/capstone/subscribers","subscription_url":"https://api.github.com/repos/harvard-lil/capstone/subscription","commits_url":"https://api.github.com/repos/harvard-lil/capstone/commits{/sha}","git_commits_url":"https://api.github.com/repos/harvard-lil/capstone/git/commits{/sha}","comments_url":"https://api.github.com/repos/harvard-lil/capstone/comments{/number}","issue_comment_url":"https://api.github.com/repos/harvard-lil/capstone/issues/comments{/number}","contents_url":"https://api.github.com/repos/harvard-lil/capstone/contents/{+path}","compare_url":"https://api.github.com/repos/harvard-lil/capstone/compare/{base}...{head}","merges_url":"https://api.github.com/repos/harvard-lil/capstone/merges","archive_url":"https://api.github.com/repos/harvard-lil/capstone/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/harvard-lil/capstone/downloads","issues_url":"https://api.github.com/repos/harvard-lil/capstone/issues{/number}","pulls_url":"https://api.github.com/repos/harvard-lil/capstone/pulls{/number}","milestones_url":"https://api.github.com/repos/harvard-lil/capstone/milestones{/number}","notifications_url":"https://api.github.com/repos/harvard-lil/capstone/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/harvard-lil/capstone/labels{/name}","releases_url":"https://api.github.com/repos/harvard-lil/capstone/releases{/id}","deployments_url":"https://api.github.com/repos/harvard-lil/capstone/deployments","created_at":"2017-02-23T19:44:44Z","updated_at":"2018-02-25T14:44:13Z","pushed_at":"2018-03-01T20:08:00Z","git_url":"git://github.com/harvard-lil/capstone.git","ssh_url":"git@github.com:harvard-lil/capstone.git","clone_url":"https://github.com/harvard-lil/capstone.git","svn_url":"https://github.com/harvard-lil/capstone","homepage":null,"size":25087,"stargazers_count":2,"watchers_count":2,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":3,"open_issues":1,"watchers":2,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/harvard-lil/capstone/pulls/185"},"html":{"href":"https://github.com/harvard-lil/capstone/pull/185"},"issue":{"href":"https://api.github.com/repos/harvard-lil/capstone/issues/185"},"comments":{"href":"https://api.github.com/repos/harvard-lil/capstone/issues/185/comments"},"review_comments":{"href":"https://api.github.com/repos/harvard-lil/capstone/pulls/185/comments"},"review_comment":{"href":"https://api.github.com/repos/harvard-lil/capstone/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/harvard-lil/capstone/pulls/185/commits"},"statuses":{"href":"https://api.github.com/repos/harvard-lil/capstone/statuses/c0fe6cff7aa08f8f736743740343f6a904c32a0c"}},"author_association":"OWNER"}}
{"actor":{"display_login":"jcushman"}}