{"action":"created","comment":{"url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments/43762222","id":43762222,"diff_hunk":"@@ -144,7 +172,63 @@ def to_representation(self, value):\n             else:\n                 meta[key] = _rapply(self.meta[key], _url_val, obj=value, serializer=self.parent)\n \n-        return {'links': {self.link_type: {'href': url, 'meta': meta}}}\n+        return self.format_json_response(link_type=self.link_type, url=url, meta=meta)\n+\n+\n+class JSONAPIHyperlinkedRelatedField(ser.HyperlinkedRelatedField, HyperlinkedFieldMixin):\n+    \"\"\"\n+    HyperlinkedRelated field that returns a nested dict with url,\n+    optional meta information, and link_type.\n+\n+    Example:\n+\n+        branched_from = JSONAPIHyperlinkedRelatedField(view_name='nodes:node-detail', lookup_field='pk',\n+                                                    lookup_url_kwarg='node_id', read_only=True, link_type='related')\n+\n+    \"\"\"\n+    def __init__(self, view_name=None, **kwargs):\n+        self.meta = kwargs.pop('meta', {})\n+        self.link_type = kwargs.pop('link_type', 'url')\n+        super(JSONAPIHyperlinkedRelatedField, self).__init__(view_name=view_name, **kwargs)\n+\n+    def to_representation(self, value):\n+        \"\"\"\n+        Returns nested dictionary in format {'links': {'self.link_type': ... }\n+\n+        If no meta information, self.link_type is equal to a string containing link's URL.  Otherwise,\n+        the link is represented as a links object with 'href' and 'meta' members.\n+        \"\"\"\n+        url = super(JSONAPIHyperlinkedRelatedField, self).to_representation(value)\n+        meta = _rapply(self.meta, _url_val, obj=value, serializer=self.parent)\n+        return self.format_json_response(link_type=self.link_type, url=url, meta=meta)\n+\n+\n+class JSONAPIHyperlinkedGuidRelatedField(ser.Field, HyperlinkedFieldMixin):\n+    \"\"\"\n+    Field that returns a nested dict with the url (constructed based\n+    on the object's type), optional meta information, and link_type.\n+\n+    Example:\n+\n+        target = JSONAPIHyperlinkedGuidRelatedField(link_type='related', meta={'type': 'get_target_type'})\n+\n+    \"\"\"\n+    def __init__(self, **kwargs):\n+        self.meta = kwargs.pop('meta', {})\n+        self.link_type = kwargs.pop('link_type', 'url')\n+        super(JSONAPIHyperlinkedGuidRelatedField, self).__init__(read_only=True, **kwargs)\n+\n+    def to_representation(self, value):\n+        \"\"\"\n+        Returns nested dictionary in format {'links': {'self.link_type': ... }\n+\n+        If no meta information, self.link_type is equal to a string containing link's URL.  Otherwise,\n+        the link is represented as a links object with 'href' and 'meta' members.\n+        \"\"\"\n+        if value._name in self.parent.Meta.type_:","path":"api/base/serializers.py","position":117,"original_position":127,"commit_id":"446e0c6a1aaf01754a57f9efd5ead266e1fffa01","original_commit_id":"634e73eace3749faab9799a428a603fb5bc6912d","user":{"login":"samanehsan","id":6414394,"avatar_url":"https://avatars.githubusercontent.com/u/6414394?v=3","gravatar_id":"","url":"https://api.github.com/users/samanehsan","html_url":"https://github.com/samanehsan","followers_url":"https://api.github.com/users/samanehsan/followers","following_url":"https://api.github.com/users/samanehsan/following{/other_user}","gists_url":"https://api.github.com/users/samanehsan/gists{/gist_id}","starred_url":"https://api.github.com/users/samanehsan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samanehsan/subscriptions","organizations_url":"https://api.github.com/users/samanehsan/orgs","repos_url":"https://api.github.com/users/samanehsan/repos","events_url":"https://api.github.com/users/samanehsan/events{/privacy}","received_events_url":"https://api.github.com/users/samanehsan/received_events","type":"User","site_admin":false},"body":"Hmmm...now that I think about it, I think the target's link_type would always be `related`, right? If that's the case then I can pass it in to the constructor.","created_at":"2015-11-03T15:36:29Z","updated_at":"2015-11-03T15:36:29Z","html_url":"https://github.com/CenterForOpenScience/osf.io/pull/4419#discussion_r43762222","pull_request_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/4419","_links":{"self":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments/43762222"},"html":{"href":"https://github.com/CenterForOpenScience/osf.io/pull/4419#discussion_r43762222"},"pull_request":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/4419"}}},"pull_request":{"url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/4419","id":47073609,"html_url":"https://github.com/CenterForOpenScience/osf.io/pull/4419","diff_url":"https://github.com/CenterForOpenScience/osf.io/pull/4419.diff","patch_url":"https://github.com/CenterForOpenScience/osf.io/pull/4419.patch","issue_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/4419","number":4419,"state":"open","locked":false,"title":"[Ready for Review] Create API v2 routes for comments","user":{"login":"samanehsan","id":6414394,"avatar_url":"https://avatars.githubusercontent.com/u/6414394?v=3","gravatar_id":"","url":"https://api.github.com/users/samanehsan","html_url":"https://github.com/samanehsan","followers_url":"https://api.github.com/users/samanehsan/followers","following_url":"https://api.github.com/users/samanehsan/following{/other_user}","gists_url":"https://api.github.com/users/samanehsan/gists{/gist_id}","starred_url":"https://api.github.com/users/samanehsan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samanehsan/subscriptions","organizations_url":"https://api.github.com/users/samanehsan/orgs","repos_url":"https://api.github.com/users/samanehsan/repos","events_url":"https://api.github.com/users/samanehsan/events{/privacy}","received_events_url":"https://api.github.com/users/samanehsan/received_events","type":"User","site_admin":false},"body":"Add in endpoints to retrieve all of the comments on a project and to create/retrieve/update/delete comments. Specifically: \r\n\r\n- GET, POST /v2/nodes/{node_id}/comments/  (includes ability to filter on the `deleted` field)\r\n- GET, PUT /v2/comments/{cid}/\r\n- GET, POST /v2/comments/{cid}/replies/\r\n- GET, POST /v2/comments/{cid}/reports/\r\n- PUT, DELETE /v2/comments/{cid}/reports/{user_id}/\r\n\r\nI also added a linked field for comments to the node serializer, along with the number of unread comments.","created_at":"2015-10-07T19:52:42Z","updated_at":"2015-11-03T15:36:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"424347d48f27fc0556bac9c38d78c3e2507bd827","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/4419/commits","review_comments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/4419/comments","review_comment_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/4419/comments","statuses_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/446e0c6a1aaf01754a57f9efd5ead266e1fffa01","head":{"label":"samanehsan:feature/api-comments","ref":"feature/api-comments","sha":"446e0c6a1aaf01754a57f9efd5ead266e1fffa01","user":{"login":"samanehsan","id":6414394,"avatar_url":"https://avatars.githubusercontent.com/u/6414394?v=3","gravatar_id":"","url":"https://api.github.com/users/samanehsan","html_url":"https://github.com/samanehsan","followers_url":"https://api.github.com/users/samanehsan/followers","following_url":"https://api.github.com/users/samanehsan/following{/other_user}","gists_url":"https://api.github.com/users/samanehsan/gists{/gist_id}","starred_url":"https://api.github.com/users/samanehsan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samanehsan/subscriptions","organizations_url":"https://api.github.com/users/samanehsan/orgs","repos_url":"https://api.github.com/users/samanehsan/repos","events_url":"https://api.github.com/users/samanehsan/events{/privacy}","received_events_url":"https://api.github.com/users/samanehsan/received_events","type":"User","site_admin":false},"repo":{"id":26921095,"name":"osf.io","full_name":"samanehsan/osf.io","owner":{"login":"samanehsan","id":6414394,"avatar_url":"https://avatars.githubusercontent.com/u/6414394?v=3","gravatar_id":"","url":"https://api.github.com/users/samanehsan","html_url":"https://github.com/samanehsan","followers_url":"https://api.github.com/users/samanehsan/followers","following_url":"https://api.github.com/users/samanehsan/following{/other_user}","gists_url":"https://api.github.com/users/samanehsan/gists{/gist_id}","starred_url":"https://api.github.com/users/samanehsan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samanehsan/subscriptions","organizations_url":"https://api.github.com/users/samanehsan/orgs","repos_url":"https://api.github.com/users/samanehsan/repos","events_url":"https://api.github.com/users/samanehsan/events{/privacy}","received_events_url":"https://api.github.com/users/samanehsan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/samanehsan/osf.io","description":"Facilitating Open Science","fork":true,"url":"https://api.github.com/repos/samanehsan/osf.io","forks_url":"https://api.github.com/repos/samanehsan/osf.io/forks","keys_url":"https://api.github.com/repos/samanehsan/osf.io/keys{/key_id}","collaborators_url":"https://api.github.com/repos/samanehsan/osf.io/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/samanehsan/osf.io/teams","hooks_url":"https://api.github.com/repos/samanehsan/osf.io/hooks","issue_events_url":"https://api.github.com/repos/samanehsan/osf.io/issues/events{/number}","events_url":"https://api.github.com/repos/samanehsan/osf.io/events","assignees_url":"https://api.github.com/repos/samanehsan/osf.io/assignees{/user}","branches_url":"https://api.github.com/repos/samanehsan/osf.io/branches{/branch}","tags_url":"https://api.github.com/repos/samanehsan/osf.io/tags","blobs_url":"https://api.github.com/repos/samanehsan/osf.io/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/samanehsan/osf.io/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/samanehsan/osf.io/git/refs{/sha}","trees_url":"https://api.github.com/repos/samanehsan/osf.io/git/trees{/sha}","statuses_url":"https://api.github.com/repos/samanehsan/osf.io/statuses/{sha}","languages_url":"https://api.github.com/repos/samanehsan/osf.io/languages","stargazers_url":"https://api.github.com/repos/samanehsan/osf.io/stargazers","contributors_url":"https://api.github.com/repos/samanehsan/osf.io/contributors","subscribers_url":"https://api.github.com/repos/samanehsan/osf.io/subscribers","subscription_url":"https://api.github.com/repos/samanehsan/osf.io/subscription","commits_url":"https://api.github.com/repos/samanehsan/osf.io/commits{/sha}","git_commits_url":"https://api.github.com/repos/samanehsan/osf.io/git/commits{/sha}","comments_url":"https://api.github.com/repos/samanehsan/osf.io/comments{/number}","issue_comment_url":"https://api.github.com/repos/samanehsan/osf.io/issues/comments{/number}","contents_url":"https://api.github.com/repos/samanehsan/osf.io/contents/{+path}","compare_url":"https://api.github.com/repos/samanehsan/osf.io/compare/{base}...{head}","merges_url":"https://api.github.com/repos/samanehsan/osf.io/merges","archive_url":"https://api.github.com/repos/samanehsan/osf.io/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/samanehsan/osf.io/downloads","issues_url":"https://api.github.com/repos/samanehsan/osf.io/issues{/number}","pulls_url":"https://api.github.com/repos/samanehsan/osf.io/pulls{/number}","milestones_url":"https://api.github.com/repos/samanehsan/osf.io/milestones{/number}","notifications_url":"https://api.github.com/repos/samanehsan/osf.io/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/samanehsan/osf.io/labels{/name}","releases_url":"https://api.github.com/repos/samanehsan/osf.io/releases{/id}","created_at":"2014-11-20T16:27:37Z","updated_at":"2015-06-24T13:47:24Z","pushed_at":"2015-11-03T14:31:32Z","git_url":"git://github.com/samanehsan/osf.io.git","ssh_url":"git@github.com:samanehsan/osf.io.git","clone_url":"https://github.com/samanehsan/osf.io.git","svn_url":"https://github.com/samanehsan/osf.io","homepage":"http://osf.io","size":107078,"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":"develop"}},"base":{"label":"CenterForOpenScience:develop","ref":"develop","sha":"75694e2badb82d15eef9aca9d5760e4de55b4144","user":{"login":"CenterForOpenScience","id":3344584,"avatar_url":"https://avatars.githubusercontent.com/u/3344584?v=3","gravatar_id":"","url":"https://api.github.com/users/CenterForOpenScience","html_url":"https://github.com/CenterForOpenScience","followers_url":"https://api.github.com/users/CenterForOpenScience/followers","following_url":"https://api.github.com/users/CenterForOpenScience/following{/other_user}","gists_url":"https://api.github.com/users/CenterForOpenScience/gists{/gist_id}","starred_url":"https://api.github.com/users/CenterForOpenScience/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CenterForOpenScience/subscriptions","organizations_url":"https://api.github.com/users/CenterForOpenScience/orgs","repos_url":"https://api.github.com/users/CenterForOpenScience/repos","events_url":"https://api.github.com/users/CenterForOpenScience/events{/privacy}","received_events_url":"https://api.github.com/users/CenterForOpenScience/received_events","type":"Organization","site_admin":false},"repo":{"id":10199599,"name":"osf.io","full_name":"CenterForOpenScience/osf.io","owner":{"login":"CenterForOpenScience","id":3344584,"avatar_url":"https://avatars.githubusercontent.com/u/3344584?v=3","gravatar_id":"","url":"https://api.github.com/users/CenterForOpenScience","html_url":"https://github.com/CenterForOpenScience","followers_url":"https://api.github.com/users/CenterForOpenScience/followers","following_url":"https://api.github.com/users/CenterForOpenScience/following{/other_user}","gists_url":"https://api.github.com/users/CenterForOpenScience/gists{/gist_id}","starred_url":"https://api.github.com/users/CenterForOpenScience/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CenterForOpenScience/subscriptions","organizations_url":"https://api.github.com/users/CenterForOpenScience/orgs","repos_url":"https://api.github.com/users/CenterForOpenScience/repos","events_url":"https://api.github.com/users/CenterForOpenScience/events{/privacy}","received_events_url":"https://api.github.com/users/CenterForOpenScience/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CenterForOpenScience/osf.io","description":"Facilitating Open Science","fork":false,"url":"https://api.github.com/repos/CenterForOpenScience/osf.io","forks_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/forks","keys_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/teams","hooks_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/hooks","issue_events_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/events{/number}","events_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/events","assignees_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/assignees{/user}","branches_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/branches{/branch}","tags_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/tags","blobs_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/refs{/sha}","trees_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/{sha}","languages_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/languages","stargazers_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/stargazers","contributors_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/contributors","subscribers_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/subscribers","subscription_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/subscription","commits_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/commits{/sha}","git_commits_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/commits{/sha}","comments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/comments{/number}","issue_comment_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/comments{/number}","contents_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/contents/{+path}","compare_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/merges","archive_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/downloads","issues_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues{/number}","pulls_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls{/number}","milestones_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/milestones{/number}","notifications_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/labels{/name}","releases_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/releases{/id}","created_at":"2013-05-21T15:53:37Z","updated_at":"2015-11-01T21:33:13Z","pushed_at":"2015-11-03T15:21:31Z","git_url":"git://github.com/CenterForOpenScience/osf.io.git","ssh_url":"git@github.com:CenterForOpenScience/osf.io.git","clone_url":"https://github.com/CenterForOpenScience/osf.io.git","svn_url":"https://github.com/CenterForOpenScience/osf.io","homepage":"http://osf.io","size":242629,"stargazers_count":153,"watchers_count":153,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":130,"mirror_url":null,"open_issues_count":350,"forks":130,"open_issues":350,"watchers":153,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/4419"},"html":{"href":"https://github.com/CenterForOpenScience/osf.io/pull/4419"},"issue":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/4419"},"comments":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/4419/comments"},"review_comments":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/4419/comments"},"review_comment":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/4419/commits"},"statuses":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/446e0c6a1aaf01754a57f9efd5ead266e1fffa01"}}}}