{"action":"created","comment":{"url":"https://api.github.com/repos/CuriousLearner/nexus/pulls/comments/214384266","pull_request_review_id":151435357,"id":214384266,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxNDM4NDI2Ng==","diff_hunk":"@@ -0,0 +1,65 @@\n+from django.utils import timezone\n+\n+# Third Party Stuff\n+from rest_framework import viewsets\n+from rest_framework import mixins\n+from rest_framework.decorators import action, parser_classes\n+from rest_framework.parsers import FormParser, MultiPartParser\n+from rest_framework.permissions import IsAdminUser, IsAuthenticated\n+\n+from nexus.base import response\n+from . import models, serializers, permissions\n+\n+\n+class PostViewSet(mixins.ListModelMixin, mixins.CreateModelMixin,\n+                  mixins.UpdateModelMixin, mixins.RetrieveModelMixin,\n+                  mixins.DestroyModelMixin, viewsets.GenericViewSet):\n+    queryset = models.Post.objects.all()\n+    permission_classes = (IsAuthenticated, permissions.IsAdminOrAuthorOfPost)\n+\n+    def get_serializer_class(self):\n+        if self.action in ['approve', 'posted']:\n+            return serializers.AdminPostSerializer\n+        return serializers.PostSerializer\n+\n+    @action(methods=['PATCH'], detail=True, permission_classes=[IsAdminUser])\n+    def approve(self, request, pk=None):\n+        instance = self.get_object()\n+        update = {'is_approved': True, 'approved_time': timezone.now()}\n+        return self.update_post_status(instance, update)\n+\n+    @action(methods=['PATCH'], detail=True, permission_classes=[IsAdminUser])\n+    def posted(self, request, pk=None):\n+        instance = self.get_object()\n+        update = {'is_posted': True, 'posted_time': timezone.now()}\n+        return self.update_post_status(instance, update)\n+\n+    @action(methods=['POST', 'PUT', 'DELETE'], detail=True)\n+    @parser_classes((FormParser, MultiPartParser))\n+    def image(self, request, pk=None):\n+        instance = self.get_object()\n+        if request.method == 'DELETE':\n+            if instance.image == '':\n+                    return response.BadRequest({'error_message': 'Image is not present'})\n+            instance.image.delete(save=True)\n+            return self.update_post_status(instance)\n+        if request.FILES:\n+            if request.method == 'POST':\n+                if not instance.image == '':\n+                        return response.BadRequest({'error_message': 'Image already present'})","path":"nexus/posts/api.py","position":49,"original_position":49,"commit_id":"9327a65dc1dd092ad93ab1382d5cf31de95e4782","original_commit_id":"9327a65dc1dd092ad93ab1382d5cf31de95e4782","user":{"login":"CuriousLearner","id":8039608,"node_id":"MDQ6VXNlcjgwMzk2MDg=","avatar_url":"https://avatars3.githubusercontent.com/u/8039608?v=4","gravatar_id":"","url":"https://api.github.com/users/CuriousLearner","html_url":"https://github.com/CuriousLearner","followers_url":"https://api.github.com/users/CuriousLearner/followers","following_url":"https://api.github.com/users/CuriousLearner/following{/other_user}","gists_url":"https://api.github.com/users/CuriousLearner/gists{/gist_id}","starred_url":"https://api.github.com/users/CuriousLearner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CuriousLearner/subscriptions","organizations_url":"https://api.github.com/users/CuriousLearner/orgs","repos_url":"https://api.github.com/users/CuriousLearner/repos","events_url":"https://api.github.com/users/CuriousLearner/events{/privacy}","received_events_url":"https://api.github.com/users/CuriousLearner/received_events","type":"User","site_admin":false},"body":"indentation looks a bit off here.","created_at":"2018-08-31T15:06:24Z","updated_at":"2018-08-31T15:06:24Z","html_url":"https://github.com/CuriousLearner/nexus/pull/5#discussion_r214384266","pull_request_url":"https://api.github.com/repos/CuriousLearner/nexus/pulls/5","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/CuriousLearner/nexus/pulls/comments/214384266"},"html":{"href":"https://github.com/CuriousLearner/nexus/pull/5#discussion_r214384266"},"pull_request":{"href":"https://api.github.com/repos/CuriousLearner/nexus/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/CuriousLearner/nexus/pulls/5","id":205675411,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA1Njc1NDEx","html_url":"https://github.com/CuriousLearner/nexus/pull/5","diff_url":"https://github.com/CuriousLearner/nexus/pull/5.diff","patch_url":"https://github.com/CuriousLearner/nexus/pull/5.patch","issue_url":"https://api.github.com/repos/CuriousLearner/nexus/issues/5","number":5,"state":"open","locked":false,"title":"Implements Posts API","user":{"login":"realslimshanky","id":10004530,"node_id":"MDQ6VXNlcjEwMDA0NTMw","avatar_url":"https://avatars0.githubusercontent.com/u/10004530?v=4","gravatar_id":"","url":"https://api.github.com/users/realslimshanky","html_url":"https://github.com/realslimshanky","followers_url":"https://api.github.com/users/realslimshanky/followers","following_url":"https://api.github.com/users/realslimshanky/following{/other_user}","gists_url":"https://api.github.com/users/realslimshanky/gists{/gist_id}","starred_url":"https://api.github.com/users/realslimshanky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realslimshanky/subscriptions","organizations_url":"https://api.github.com/users/realslimshanky/orgs","repos_url":"https://api.github.com/users/realslimshanky/repos","events_url":"https://api.github.com/users/realslimshanky/events{/privacy}","received_events_url":"https://api.github.com/users/realslimshanky/received_events","type":"User","site_admin":false},"body":"This pull request incorporated the following features\r\n\r\n| URL | METHOD | ACTION |\r\n| ----- | ------------- | ---------- |\r\n| /posts | GET | Get list of all posts |\r\n| /posts | POST | Add new post |\r\n| /posts/:post_id | GET | Get post detail |\r\n| /posts/:post_id | PUT | Update post |\r\n| /posts/:post_id | PATCH | Partial update post |\r\n| /posts/:post_id | DELETE | Delete post |\r\n| /posts/:post_id/approve | PATCH | Approve post |\r\n| /posts/:post_id/approve | PATCH | Posted |\r\n| /posts/:post_id/image | POST | Add new post image |\r\n| /posts/:post_id/image | PUT | Update post image |\r\n| /posts/:post_id/image | DELETE | Delete post image |","created_at":"2018-08-02T09:41:24Z","updated_at":"2018-08-31T15:06:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3155d48508bb22669e3cde27389d79dc23a2facd","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/CuriousLearner/nexus/pulls/5/commits","review_comments_url":"https://api.github.com/repos/CuriousLearner/nexus/pulls/5/comments","review_comment_url":"https://api.github.com/repos/CuriousLearner/nexus/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CuriousLearner/nexus/issues/5/comments","statuses_url":"https://api.github.com/repos/CuriousLearner/nexus/statuses/9327a65dc1dd092ad93ab1382d5cf31de95e4782","head":{"label":"realslimshanky:post-endpoint","ref":"post-endpoint","sha":"9327a65dc1dd092ad93ab1382d5cf31de95e4782","user":{"login":"realslimshanky","id":10004530,"node_id":"MDQ6VXNlcjEwMDA0NTMw","avatar_url":"https://avatars0.githubusercontent.com/u/10004530?v=4","gravatar_id":"","url":"https://api.github.com/users/realslimshanky","html_url":"https://github.com/realslimshanky","followers_url":"https://api.github.com/users/realslimshanky/followers","following_url":"https://api.github.com/users/realslimshanky/following{/other_user}","gists_url":"https://api.github.com/users/realslimshanky/gists{/gist_id}","starred_url":"https://api.github.com/users/realslimshanky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realslimshanky/subscriptions","organizations_url":"https://api.github.com/users/realslimshanky/orgs","repos_url":"https://api.github.com/users/realslimshanky/repos","events_url":"https://api.github.com/users/realslimshanky/events{/privacy}","received_events_url":"https://api.github.com/users/realslimshanky/received_events","type":"User","site_admin":false},"repo":{"id":142855862,"node_id":"MDEwOlJlcG9zaXRvcnkxNDI4NTU4NjI=","name":"nexus","full_name":"realslimshanky/nexus","owner":{"login":"realslimshanky","id":10004530,"node_id":"MDQ6VXNlcjEwMDA0NTMw","avatar_url":"https://avatars0.githubusercontent.com/u/10004530?v=4","gravatar_id":"","url":"https://api.github.com/users/realslimshanky","html_url":"https://github.com/realslimshanky","followers_url":"https://api.github.com/users/realslimshanky/followers","following_url":"https://api.github.com/users/realslimshanky/following{/other_user}","gists_url":"https://api.github.com/users/realslimshanky/gists{/gist_id}","starred_url":"https://api.github.com/users/realslimshanky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realslimshanky/subscriptions","organizations_url":"https://api.github.com/users/realslimshanky/orgs","repos_url":"https://api.github.com/users/realslimshanky/repos","events_url":"https://api.github.com/users/realslimshanky/events{/privacy}","received_events_url":"https://api.github.com/users/realslimshanky/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/realslimshanky/nexus","description":"Streamline & automate the boring parts","fork":true,"url":"https://api.github.com/repos/realslimshanky/nexus","forks_url":"https://api.github.com/repos/realslimshanky/nexus/forks","keys_url":"https://api.github.com/repos/realslimshanky/nexus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/realslimshanky/nexus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/realslimshanky/nexus/teams","hooks_url":"https://api.github.com/repos/realslimshanky/nexus/hooks","issue_events_url":"https://api.github.com/repos/realslimshanky/nexus/issues/events{/number}","events_url":"https://api.github.com/repos/realslimshanky/nexus/events","assignees_url":"https://api.github.com/repos/realslimshanky/nexus/assignees{/user}","branches_url":"https://api.github.com/repos/realslimshanky/nexus/branches{/branch}","tags_url":"https://api.github.com/repos/realslimshanky/nexus/tags","blobs_url":"https://api.github.com/repos/realslimshanky/nexus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/realslimshanky/nexus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/realslimshanky/nexus/git/refs{/sha}","trees_url":"https://api.github.com/repos/realslimshanky/nexus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/realslimshanky/nexus/statuses/{sha}","languages_url":"https://api.github.com/repos/realslimshanky/nexus/languages","stargazers_url":"https://api.github.com/repos/realslimshanky/nexus/stargazers","contributors_url":"https://api.github.com/repos/realslimshanky/nexus/contributors","subscribers_url":"https://api.github.com/repos/realslimshanky/nexus/subscribers","subscription_url":"https://api.github.com/repos/realslimshanky/nexus/subscription","commits_url":"https://api.github.com/repos/realslimshanky/nexus/commits{/sha}","git_commits_url":"https://api.github.com/repos/realslimshanky/nexus/git/commits{/sha}","comments_url":"https://api.github.com/repos/realslimshanky/nexus/comments{/number}","issue_comment_url":"https://api.github.com/repos/realslimshanky/nexus/issues/comments{/number}","contents_url":"https://api.github.com/repos/realslimshanky/nexus/contents/{+path}","compare_url":"https://api.github.com/repos/realslimshanky/nexus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/realslimshanky/nexus/merges","archive_url":"https://api.github.com/repos/realslimshanky/nexus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/realslimshanky/nexus/downloads","issues_url":"https://api.github.com/repos/realslimshanky/nexus/issues{/number}","pulls_url":"https://api.github.com/repos/realslimshanky/nexus/pulls{/number}","milestones_url":"https://api.github.com/repos/realslimshanky/nexus/milestones{/number}","notifications_url":"https://api.github.com/repos/realslimshanky/nexus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/realslimshanky/nexus/labels{/name}","releases_url":"https://api.github.com/repos/realslimshanky/nexus/releases{/id}","deployments_url":"https://api.github.com/repos/realslimshanky/nexus/deployments","created_at":"2018-07-30T09:41:10Z","updated_at":"2018-07-30T09:41:12Z","pushed_at":"2018-08-24T20:06:26Z","git_url":"git://github.com/realslimshanky/nexus.git","ssh_url":"git@github.com:realslimshanky/nexus.git","clone_url":"https://github.com/realslimshanky/nexus.git","svn_url":"https://github.com/realslimshanky/nexus","homepage":null,"size":97,"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":"master"}},"base":{"label":"CuriousLearner:master","ref":"master","sha":"bf76a66c035b78c0aef4826db5a4e31e76b40576","user":{"login":"CuriousLearner","id":8039608,"node_id":"MDQ6VXNlcjgwMzk2MDg=","avatar_url":"https://avatars3.githubusercontent.com/u/8039608?v=4","gravatar_id":"","url":"https://api.github.com/users/CuriousLearner","html_url":"https://github.com/CuriousLearner","followers_url":"https://api.github.com/users/CuriousLearner/followers","following_url":"https://api.github.com/users/CuriousLearner/following{/other_user}","gists_url":"https://api.github.com/users/CuriousLearner/gists{/gist_id}","starred_url":"https://api.github.com/users/CuriousLearner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CuriousLearner/subscriptions","organizations_url":"https://api.github.com/users/CuriousLearner/orgs","repos_url":"https://api.github.com/users/CuriousLearner/repos","events_url":"https://api.github.com/users/CuriousLearner/events{/privacy}","received_events_url":"https://api.github.com/users/CuriousLearner/received_events","type":"User","site_admin":false},"repo":{"id":141326507,"node_id":"MDEwOlJlcG9zaXRvcnkxNDEzMjY1MDc=","name":"nexus","full_name":"CuriousLearner/nexus","owner":{"login":"CuriousLearner","id":8039608,"node_id":"MDQ6VXNlcjgwMzk2MDg=","avatar_url":"https://avatars3.githubusercontent.com/u/8039608?v=4","gravatar_id":"","url":"https://api.github.com/users/CuriousLearner","html_url":"https://github.com/CuriousLearner","followers_url":"https://api.github.com/users/CuriousLearner/followers","following_url":"https://api.github.com/users/CuriousLearner/following{/other_user}","gists_url":"https://api.github.com/users/CuriousLearner/gists{/gist_id}","starred_url":"https://api.github.com/users/CuriousLearner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CuriousLearner/subscriptions","organizations_url":"https://api.github.com/users/CuriousLearner/orgs","repos_url":"https://api.github.com/users/CuriousLearner/repos","events_url":"https://api.github.com/users/CuriousLearner/events{/privacy}","received_events_url":"https://api.github.com/users/CuriousLearner/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/CuriousLearner/nexus","description":"Streamline & automate the boring parts","fork":false,"url":"https://api.github.com/repos/CuriousLearner/nexus","forks_url":"https://api.github.com/repos/CuriousLearner/nexus/forks","keys_url":"https://api.github.com/repos/CuriousLearner/nexus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CuriousLearner/nexus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CuriousLearner/nexus/teams","hooks_url":"https://api.github.com/repos/CuriousLearner/nexus/hooks","issue_events_url":"https://api.github.com/repos/CuriousLearner/nexus/issues/events{/number}","events_url":"https://api.github.com/repos/CuriousLearner/nexus/events","assignees_url":"https://api.github.com/repos/CuriousLearner/nexus/assignees{/user}","branches_url":"https://api.github.com/repos/CuriousLearner/nexus/branches{/branch}","tags_url":"https://api.github.com/repos/CuriousLearner/nexus/tags","blobs_url":"https://api.github.com/repos/CuriousLearner/nexus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CuriousLearner/nexus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CuriousLearner/nexus/git/refs{/sha}","trees_url":"https://api.github.com/repos/CuriousLearner/nexus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CuriousLearner/nexus/statuses/{sha}","languages_url":"https://api.github.com/repos/CuriousLearner/nexus/languages","stargazers_url":"https://api.github.com/repos/CuriousLearner/nexus/stargazers","contributors_url":"https://api.github.com/repos/CuriousLearner/nexus/contributors","subscribers_url":"https://api.github.com/repos/CuriousLearner/nexus/subscribers","subscription_url":"https://api.github.com/repos/CuriousLearner/nexus/subscription","commits_url":"https://api.github.com/repos/CuriousLearner/nexus/commits{/sha}","git_commits_url":"https://api.github.com/repos/CuriousLearner/nexus/git/commits{/sha}","comments_url":"https://api.github.com/repos/CuriousLearner/nexus/comments{/number}","issue_comment_url":"https://api.github.com/repos/CuriousLearner/nexus/issues/comments{/number}","contents_url":"https://api.github.com/repos/CuriousLearner/nexus/contents/{+path}","compare_url":"https://api.github.com/repos/CuriousLearner/nexus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CuriousLearner/nexus/merges","archive_url":"https://api.github.com/repos/CuriousLearner/nexus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CuriousLearner/nexus/downloads","issues_url":"https://api.github.com/repos/CuriousLearner/nexus/issues{/number}","pulls_url":"https://api.github.com/repos/CuriousLearner/nexus/pulls{/number}","milestones_url":"https://api.github.com/repos/CuriousLearner/nexus/milestones{/number}","notifications_url":"https://api.github.com/repos/CuriousLearner/nexus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CuriousLearner/nexus/labels{/name}","releases_url":"https://api.github.com/repos/CuriousLearner/nexus/releases{/id}","deployments_url":"https://api.github.com/repos/CuriousLearner/nexus/deployments","created_at":"2018-07-17T18:10:47Z","updated_at":"2018-08-24T13:19:18Z","pushed_at":"2018-08-24T20:06:27Z","git_url":"git://github.com/CuriousLearner/nexus.git","ssh_url":"git@github.com:CuriousLearner/nexus.git","clone_url":"https://github.com/CuriousLearner/nexus.git","svn_url":"https://github.com/CuriousLearner/nexus","homepage":null,"size":91,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"archived":false,"open_issues_count":4,"license":null,"forks":5,"open_issues":4,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/CuriousLearner/nexus/pulls/5"},"html":{"href":"https://github.com/CuriousLearner/nexus/pull/5"},"issue":{"href":"https://api.github.com/repos/CuriousLearner/nexus/issues/5"},"comments":{"href":"https://api.github.com/repos/CuriousLearner/nexus/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/CuriousLearner/nexus/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/CuriousLearner/nexus/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CuriousLearner/nexus/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/CuriousLearner/nexus/statuses/9327a65dc1dd092ad93ab1382d5cf31de95e4782"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"CuriousLearner"}}