{"action":"created","comment":{"url":"https://api.github.com/repos/mitodl/open-discussions/pulls/comments/206894411","pull_request_review_id":142394173,"id":206894411,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwNjg5NDQxMQ==","diff_hunk":"@@ -80,9 +82,45 @@ def get_membership_is_managed(self, channel):\n         \"\"\"\n         Get membership_is_managed from the associated Channel model\n         \"\"\"\n-        channel_obj = Channel.objects.get(name=channel.display_name)\n+        channel_obj = self._get_channel(name=channel.display_name)\n         return channel_obj.membership_is_managed\n \n+    def get_avatar(self, channel):\n+        \"\"\"Get the avatar image URL\"\"\"\n+        channel_obj = self._get_channel(name=channel.display_name)\n+        try:\n+            return channel_obj.avatar.url\n+        except ValueError:\n+            return None\n+\n+    def get_banner(self, channel):\n+        \"\"\"Get the banner image URL\"\"\"\n+        channel_obj = self._get_channel(name=channel.display_name)\n+        try:\n+            return channel_obj.banner.url\n+        except ValueError:\n+            return None\n+\n+    def validate_avatar(self, value):\n+        \"\"\"Empty validation function, but this is required for WriteableSerializerMethodField\"\"\"\n+        if not hasattr(value, 'name'):\n+            raise ValidationError(\"Expected avatar to be a file\")\n+        return {\"avatar\": value}\n+\n+    def validate_banner(self, value):\n+        \"\"\"Empty validation function, but this is required for WriteableSerializerMethodField\"\"\"\n+        if not hasattr(value, 'name'):\n+            raise ValidationError(\"Expected banner to be a file\")\n+        return {\"banner\": value}\n+\n+    def _get_channel(self, name):","path":"channels/serializers.py","position":45,"original_position":45,"commit_id":"e3e6f782dcae189bfd43c5b39fccf3addd2272c8","original_commit_id":"e3e6f782dcae189bfd43c5b39fccf3addd2272c8","user":{"login":"mbertrand","id":187676,"node_id":"MDQ6VXNlcjE4NzY3Ng==","avatar_url":"https://avatars2.githubusercontent.com/u/187676?v=4","gravatar_id":"","url":"https://api.github.com/users/mbertrand","html_url":"https://github.com/mbertrand","followers_url":"https://api.github.com/users/mbertrand/followers","following_url":"https://api.github.com/users/mbertrand/following{/other_user}","gists_url":"https://api.github.com/users/mbertrand/gists{/gist_id}","starred_url":"https://api.github.com/users/mbertrand/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbertrand/subscriptions","organizations_url":"https://api.github.com/users/mbertrand/orgs","repos_url":"https://api.github.com/users/mbertrand/repos","events_url":"https://api.github.com/users/mbertrand/events{/privacy}","received_events_url":"https://api.github.com/users/mbertrand/received_events","type":"User","site_admin":false},"body":"Related to other comment, what is the benefit of having `channels` in the context and trying to get the channel from there first instead of just calling `Channel.objects.get(name=name)`?","created_at":"2018-08-01T14:11:07Z","updated_at":"2018-08-01T14:15:32Z","html_url":"https://github.com/mitodl/open-discussions/pull/996#discussion_r206894411","pull_request_url":"https://api.github.com/repos/mitodl/open-discussions/pulls/996","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/mitodl/open-discussions/pulls/comments/206894411"},"html":{"href":"https://github.com/mitodl/open-discussions/pull/996#discussion_r206894411"},"pull_request":{"href":"https://api.github.com/repos/mitodl/open-discussions/pulls/996"}}},"pull_request":{"url":"https://api.github.com/repos/mitodl/open-discussions/pulls/996","id":204925691,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA0OTI1Njkx","html_url":"https://github.com/mitodl/open-discussions/pull/996","diff_url":"https://github.com/mitodl/open-discussions/pull/996.diff","patch_url":"https://github.com/mitodl/open-discussions/pull/996.patch","issue_url":"https://api.github.com/repos/mitodl/open-discussions/issues/996","number":996,"state":"open","locked":false,"title":"Add avatar and banner fields to serializer and models","user":{"login":"noisecapella","id":863262,"node_id":"MDQ6VXNlcjg2MzI2Mg==","avatar_url":"https://avatars2.githubusercontent.com/u/863262?v=4","gravatar_id":"","url":"https://api.github.com/users/noisecapella","html_url":"https://github.com/noisecapella","followers_url":"https://api.github.com/users/noisecapella/followers","following_url":"https://api.github.com/users/noisecapella/following{/other_user}","gists_url":"https://api.github.com/users/noisecapella/gists{/gist_id}","starred_url":"https://api.github.com/users/noisecapella/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/noisecapella/subscriptions","organizations_url":"https://api.github.com/users/noisecapella/orgs","repos_url":"https://api.github.com/users/noisecapella/repos","events_url":"https://api.github.com/users/noisecapella/events{/privacy}","received_events_url":"https://api.github.com/users/noisecapella/received_events","type":"User","site_admin":false},"body":"#### What are the relevant tickets?\r\nPart of #927 \r\n\r\n#### What's this PR do?\r\nAdd fields and REST API support for the avatar and banner images for channels\r\n\r\n#### How should this be manually tested?\r\nNo UI to test with","created_at":"2018-07-30T20:49:21Z","updated_at":"2018-08-01T14:15:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e67fdf6611330b4c47ff6ef3cf6edd1394ade1e8","assignee":{"login":"mbertrand","id":187676,"node_id":"MDQ6VXNlcjE4NzY3Ng==","avatar_url":"https://avatars2.githubusercontent.com/u/187676?v=4","gravatar_id":"","url":"https://api.github.com/users/mbertrand","html_url":"https://github.com/mbertrand","followers_url":"https://api.github.com/users/mbertrand/followers","following_url":"https://api.github.com/users/mbertrand/following{/other_user}","gists_url":"https://api.github.com/users/mbertrand/gists{/gist_id}","starred_url":"https://api.github.com/users/mbertrand/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbertrand/subscriptions","organizations_url":"https://api.github.com/users/mbertrand/orgs","repos_url":"https://api.github.com/users/mbertrand/repos","events_url":"https://api.github.com/users/mbertrand/events{/privacy}","received_events_url":"https://api.github.com/users/mbertrand/received_events","type":"User","site_admin":false},"assignees":[{"login":"mbertrand","id":187676,"node_id":"MDQ6VXNlcjE4NzY3Ng==","avatar_url":"https://avatars2.githubusercontent.com/u/187676?v=4","gravatar_id":"","url":"https://api.github.com/users/mbertrand","html_url":"https://github.com/mbertrand","followers_url":"https://api.github.com/users/mbertrand/followers","following_url":"https://api.github.com/users/mbertrand/following{/other_user}","gists_url":"https://api.github.com/users/mbertrand/gists{/gist_id}","starred_url":"https://api.github.com/users/mbertrand/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbertrand/subscriptions","organizations_url":"https://api.github.com/users/mbertrand/orgs","repos_url":"https://api.github.com/users/mbertrand/repos","events_url":"https://api.github.com/users/mbertrand/events{/privacy}","received_events_url":"https://api.github.com/users/mbertrand/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":627437808,"node_id":"MDU6TGFiZWw2Mjc0Mzc4MDg=","url":"https://api.github.com/repos/mitodl/open-discussions/labels/Needs%20Review","name":"Needs Review","color":"f9d0c4","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/mitodl/open-discussions/pulls/996/commits","review_comments_url":"https://api.github.com/repos/mitodl/open-discussions/pulls/996/comments","review_comment_url":"https://api.github.com/repos/mitodl/open-discussions/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mitodl/open-discussions/issues/996/comments","statuses_url":"https://api.github.com/repos/mitodl/open-discussions/statuses/e3e6f782dcae189bfd43c5b39fccf3addd2272c8","head":{"label":"mitodl:gs/channel_avatar_backend","ref":"gs/channel_avatar_backend","sha":"e3e6f782dcae189bfd43c5b39fccf3addd2272c8","user":{"login":"mitodl","id":7918516,"node_id":"MDEyOk9yZ2FuaXphdGlvbjc5MTg1MTY=","avatar_url":"https://avatars2.githubusercontent.com/u/7918516?v=4","gravatar_id":"","url":"https://api.github.com/users/mitodl","html_url":"https://github.com/mitodl","followers_url":"https://api.github.com/users/mitodl/followers","following_url":"https://api.github.com/users/mitodl/following{/other_user}","gists_url":"https://api.github.com/users/mitodl/gists{/gist_id}","starred_url":"https://api.github.com/users/mitodl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitodl/subscriptions","organizations_url":"https://api.github.com/users/mitodl/orgs","repos_url":"https://api.github.com/users/mitodl/repos","events_url":"https://api.github.com/users/mitodl/events{/privacy}","received_events_url":"https://api.github.com/users/mitodl/received_events","type":"Organization","site_admin":false},"repo":{"id":93760926,"node_id":"MDEwOlJlcG9zaXRvcnk5Mzc2MDkyNg==","name":"open-discussions","full_name":"mitodl/open-discussions","owner":{"login":"mitodl","id":7918516,"node_id":"MDEyOk9yZ2FuaXphdGlvbjc5MTg1MTY=","avatar_url":"https://avatars2.githubusercontent.com/u/7918516?v=4","gravatar_id":"","url":"https://api.github.com/users/mitodl","html_url":"https://github.com/mitodl","followers_url":"https://api.github.com/users/mitodl/followers","following_url":"https://api.github.com/users/mitodl/following{/other_user}","gists_url":"https://api.github.com/users/mitodl/gists{/gist_id}","starred_url":"https://api.github.com/users/mitodl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitodl/subscriptions","organizations_url":"https://api.github.com/users/mitodl/orgs","repos_url":"https://api.github.com/users/mitodl/repos","events_url":"https://api.github.com/users/mitodl/events{/privacy}","received_events_url":"https://api.github.com/users/mitodl/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mitodl/open-discussions","description":null,"fork":false,"url":"https://api.github.com/repos/mitodl/open-discussions","forks_url":"https://api.github.com/repos/mitodl/open-discussions/forks","keys_url":"https://api.github.com/repos/mitodl/open-discussions/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mitodl/open-discussions/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mitodl/open-discussions/teams","hooks_url":"https://api.github.com/repos/mitodl/open-discussions/hooks","issue_events_url":"https://api.github.com/repos/mitodl/open-discussions/issues/events{/number}","events_url":"https://api.github.com/repos/mitodl/open-discussions/events","assignees_url":"https://api.github.com/repos/mitodl/open-discussions/assignees{/user}","branches_url":"https://api.github.com/repos/mitodl/open-discussions/branches{/branch}","tags_url":"https://api.github.com/repos/mitodl/open-discussions/tags","blobs_url":"https://api.github.com/repos/mitodl/open-discussions/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mitodl/open-discussions/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mitodl/open-discussions/git/refs{/sha}","trees_url":"https://api.github.com/repos/mitodl/open-discussions/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mitodl/open-discussions/statuses/{sha}","languages_url":"https://api.github.com/repos/mitodl/open-discussions/languages","stargazers_url":"https://api.github.com/repos/mitodl/open-discussions/stargazers","contributors_url":"https://api.github.com/repos/mitodl/open-discussions/contributors","subscribers_url":"https://api.github.com/repos/mitodl/open-discussions/subscribers","subscription_url":"https://api.github.com/repos/mitodl/open-discussions/subscription","commits_url":"https://api.github.com/repos/mitodl/open-discussions/commits{/sha}","git_commits_url":"https://api.github.com/repos/mitodl/open-discussions/git/commits{/sha}","comments_url":"https://api.github.com/repos/mitodl/open-discussions/comments{/number}","issue_comment_url":"https://api.github.com/repos/mitodl/open-discussions/issues/comments{/number}","contents_url":"https://api.github.com/repos/mitodl/open-discussions/contents/{+path}","compare_url":"https://api.github.com/repos/mitodl/open-discussions/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mitodl/open-discussions/merges","archive_url":"https://api.github.com/repos/mitodl/open-discussions/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mitodl/open-discussions/downloads","issues_url":"https://api.github.com/repos/mitodl/open-discussions/issues{/number}","pulls_url":"https://api.github.com/repos/mitodl/open-discussions/pulls{/number}","milestones_url":"https://api.github.com/repos/mitodl/open-discussions/milestones{/number}","notifications_url":"https://api.github.com/repos/mitodl/open-discussions/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mitodl/open-discussions/labels{/name}","releases_url":"https://api.github.com/repos/mitodl/open-discussions/releases{/id}","deployments_url":"https://api.github.com/repos/mitodl/open-discussions/deployments","created_at":"2017-06-08T14:46:35Z","updated_at":"2018-07-31T20:02:25Z","pushed_at":"2018-07-31T21:28:44Z","git_url":"git://github.com/mitodl/open-discussions.git","ssh_url":"git@github.com:mitodl/open-discussions.git","clone_url":"https://github.com/mitodl/open-discussions.git","svn_url":"https://github.com/mitodl/open-discussions","homepage":null,"size":2604,"stargazers_count":3,"watchers_count":3,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":111,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":0,"open_issues":111,"watchers":3,"default_branch":"master"}},"base":{"label":"mitodl:master","ref":"master","sha":"5a2d24931613ffe8fc81d18beb08a3d1033132ac","user":{"login":"mitodl","id":7918516,"node_id":"MDEyOk9yZ2FuaXphdGlvbjc5MTg1MTY=","avatar_url":"https://avatars2.githubusercontent.com/u/7918516?v=4","gravatar_id":"","url":"https://api.github.com/users/mitodl","html_url":"https://github.com/mitodl","followers_url":"https://api.github.com/users/mitodl/followers","following_url":"https://api.github.com/users/mitodl/following{/other_user}","gists_url":"https://api.github.com/users/mitodl/gists{/gist_id}","starred_url":"https://api.github.com/users/mitodl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitodl/subscriptions","organizations_url":"https://api.github.com/users/mitodl/orgs","repos_url":"https://api.github.com/users/mitodl/repos","events_url":"https://api.github.com/users/mitodl/events{/privacy}","received_events_url":"https://api.github.com/users/mitodl/received_events","type":"Organization","site_admin":false},"repo":{"id":93760926,"node_id":"MDEwOlJlcG9zaXRvcnk5Mzc2MDkyNg==","name":"open-discussions","full_name":"mitodl/open-discussions","owner":{"login":"mitodl","id":7918516,"node_id":"MDEyOk9yZ2FuaXphdGlvbjc5MTg1MTY=","avatar_url":"https://avatars2.githubusercontent.com/u/7918516?v=4","gravatar_id":"","url":"https://api.github.com/users/mitodl","html_url":"https://github.com/mitodl","followers_url":"https://api.github.com/users/mitodl/followers","following_url":"https://api.github.com/users/mitodl/following{/other_user}","gists_url":"https://api.github.com/users/mitodl/gists{/gist_id}","starred_url":"https://api.github.com/users/mitodl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitodl/subscriptions","organizations_url":"https://api.github.com/users/mitodl/orgs","repos_url":"https://api.github.com/users/mitodl/repos","events_url":"https://api.github.com/users/mitodl/events{/privacy}","received_events_url":"https://api.github.com/users/mitodl/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mitodl/open-discussions","description":null,"fork":false,"url":"https://api.github.com/repos/mitodl/open-discussions","forks_url":"https://api.github.com/repos/mitodl/open-discussions/forks","keys_url":"https://api.github.com/repos/mitodl/open-discussions/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mitodl/open-discussions/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mitodl/open-discussions/teams","hooks_url":"https://api.github.com/repos/mitodl/open-discussions/hooks","issue_events_url":"https://api.github.com/repos/mitodl/open-discussions/issues/events{/number}","events_url":"https://api.github.com/repos/mitodl/open-discussions/events","assignees_url":"https://api.github.com/repos/mitodl/open-discussions/assignees{/user}","branches_url":"https://api.github.com/repos/mitodl/open-discussions/branches{/branch}","tags_url":"https://api.github.com/repos/mitodl/open-discussions/tags","blobs_url":"https://api.github.com/repos/mitodl/open-discussions/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mitodl/open-discussions/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mitodl/open-discussions/git/refs{/sha}","trees_url":"https://api.github.com/repos/mitodl/open-discussions/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mitodl/open-discussions/statuses/{sha}","languages_url":"https://api.github.com/repos/mitodl/open-discussions/languages","stargazers_url":"https://api.github.com/repos/mitodl/open-discussions/stargazers","contributors_url":"https://api.github.com/repos/mitodl/open-discussions/contributors","subscribers_url":"https://api.github.com/repos/mitodl/open-discussions/subscribers","subscription_url":"https://api.github.com/repos/mitodl/open-discussions/subscription","commits_url":"https://api.github.com/repos/mitodl/open-discussions/commits{/sha}","git_commits_url":"https://api.github.com/repos/mitodl/open-discussions/git/commits{/sha}","comments_url":"https://api.github.com/repos/mitodl/open-discussions/comments{/number}","issue_comment_url":"https://api.github.com/repos/mitodl/open-discussions/issues/comments{/number}","contents_url":"https://api.github.com/repos/mitodl/open-discussions/contents/{+path}","compare_url":"https://api.github.com/repos/mitodl/open-discussions/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mitodl/open-discussions/merges","archive_url":"https://api.github.com/repos/mitodl/open-discussions/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mitodl/open-discussions/downloads","issues_url":"https://api.github.com/repos/mitodl/open-discussions/issues{/number}","pulls_url":"https://api.github.com/repos/mitodl/open-discussions/pulls{/number}","milestones_url":"https://api.github.com/repos/mitodl/open-discussions/milestones{/number}","notifications_url":"https://api.github.com/repos/mitodl/open-discussions/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mitodl/open-discussions/labels{/name}","releases_url":"https://api.github.com/repos/mitodl/open-discussions/releases{/id}","deployments_url":"https://api.github.com/repos/mitodl/open-discussions/deployments","created_at":"2017-06-08T14:46:35Z","updated_at":"2018-07-31T20:02:25Z","pushed_at":"2018-07-31T21:28:44Z","git_url":"git://github.com/mitodl/open-discussions.git","ssh_url":"git@github.com:mitodl/open-discussions.git","clone_url":"https://github.com/mitodl/open-discussions.git","svn_url":"https://github.com/mitodl/open-discussions","homepage":null,"size":2604,"stargazers_count":3,"watchers_count":3,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":111,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":0,"open_issues":111,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mitodl/open-discussions/pulls/996"},"html":{"href":"https://github.com/mitodl/open-discussions/pull/996"},"issue":{"href":"https://api.github.com/repos/mitodl/open-discussions/issues/996"},"comments":{"href":"https://api.github.com/repos/mitodl/open-discussions/issues/996/comments"},"review_comments":{"href":"https://api.github.com/repos/mitodl/open-discussions/pulls/996/comments"},"review_comment":{"href":"https://api.github.com/repos/mitodl/open-discussions/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mitodl/open-discussions/pulls/996/commits"},"statuses":{"href":"https://api.github.com/repos/mitodl/open-discussions/statuses/e3e6f782dcae189bfd43c5b39fccf3addd2272c8"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"mbertrand"}}