{"action":"created","comment":{"url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments/47325884","id":47325884,"diff_hunk":"@@ -0,0 +1,49 @@\n+from django.http import HttpResponse\n+from django.template.loader import render_to_string\n+import requests\n+from corehq import toggles\n+from corehq.apps.locations.models import SQLLocation\n+\n+\n+@toggles.ICDS_REPORTS.required_decorator()\n+def tableau(request, domain, workbook, worksheet):\n+    # TODO: In production we should limit this to only the actual workbook, but this makes iteration much easier\n+    # trusted_ticket = _get_tableau_trusted_ticket(request.)\n+    location_type_name, location_name = _get_user_permissions(request.couch_user, domain)\n+\n+    user_location_level_key = 'user_{}'.format(location_type_name)\n+\n+    context = {\n+        'report_workbook': workbook,\n+        'report_worksheet': worksheet,\n+        'user_view_by': location_type_name,\n+        user_location_level_key: location_name,\n+    }\n+\n+    response = render_to_string('tableau.html', context)\n+    return HttpResponse(response)\n+\n+\n+def _get_user_permissions(user, domain):\n+    '''\n+    Takes a couch_user and returns that users level in the heirarchy and the location name\n+    '''\n+    # TODO: This needs to handle the top level where someone can see everything\n+    try:\n+        user_location_id = user.get_domain_membership(domain).location_id\n+        loc = SQLLocation.by_location_id(user_location_id)\n+        location_type_name = loc.location_type.name\n+        location_name = loc.name\n+    except Exception as e:","path":"custom/icds/views.py","position":37,"original_position":37,"commit_id":"1e60a8fd2949fb3156be56fb9ce6aa122ddd162f","original_commit_id":"99cff405ae8b6e06bc3b3297f879ac54a27ce72d","user":{"login":"TylerSheffels","id":3419385,"avatar_url":"https://avatars.githubusercontent.com/u/3419385?v=3","gravatar_id":"","url":"https://api.github.com/users/TylerSheffels","html_url":"https://github.com/TylerSheffels","followers_url":"https://api.github.com/users/TylerSheffels/followers","following_url":"https://api.github.com/users/TylerSheffels/following{/other_user}","gists_url":"https://api.github.com/users/TylerSheffels/gists{/gist_id}","starred_url":"https://api.github.com/users/TylerSheffels/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TylerSheffels/subscriptions","organizations_url":"https://api.github.com/users/TylerSheffels/orgs","repos_url":"https://api.github.com/users/TylerSheffels/repos","events_url":"https://api.github.com/users/TylerSheffels/events{/privacy}","received_events_url":"https://api.github.com/users/TylerSheffels/received_events","type":"User","site_admin":false},"body":"Can we add a country designation in the hierarchy that we can assign superusers to?","created_at":"2015-12-11T06:38:04Z","updated_at":"2015-12-11T06:38:04Z","html_url":"https://github.com/dimagi/commcare-hq/pull/9514#discussion_r47325884","pull_request_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/9514","_links":{"self":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments/47325884"},"html":{"href":"https://github.com/dimagi/commcare-hq/pull/9514#discussion_r47325884"},"pull_request":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/9514"}}},"pull_request":{"url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/9514","id":53275045,"html_url":"https://github.com/dimagi/commcare-hq/pull/9514","diff_url":"https://github.com/dimagi/commcare-hq/pull/9514.diff","patch_url":"https://github.com/dimagi/commcare-hq/pull/9514.patch","issue_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/9514","number":9514,"state":"open","locked":false,"title":"Add ICDS tableau dashboard wrapper","user":{"login":"TylerSheffels","id":3419385,"avatar_url":"https://avatars.githubusercontent.com/u/3419385?v=3","gravatar_id":"","url":"https://api.github.com/users/TylerSheffels","html_url":"https://github.com/TylerSheffels","followers_url":"https://api.github.com/users/TylerSheffels/followers","following_url":"https://api.github.com/users/TylerSheffels/following{/other_user}","gists_url":"https://api.github.com/users/TylerSheffels/gists{/gist_id}","starred_url":"https://api.github.com/users/TylerSheffels/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TylerSheffels/subscriptions","organizations_url":"https://api.github.com/users/TylerSheffels/orgs","repos_url":"https://api.github.com/users/TylerSheffels/repos","events_url":"https://api.github.com/users/TylerSheffels/events{/privacy}","received_events_url":"https://api.github.com/users/TylerSheffels/received_events","type":"User","site_admin":false},"body":"I want to start getting review on this, because I am thinking that there will be some code revisions (my javascript might not be the cleanest). Holding off on merge until I iterate a bit more with @sheelio on the actual dashboard. I also clearly have some todo's to clean up as well.\r\n\r\n@emord @proteusvacuum @czue \r\n\r\n","created_at":"2015-12-10T15:43:24Z","updated_at":"2015-12-11T06:38:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"882f1ea44be9a4c35383d0d09a492c5fa449a445","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/9514/commits","review_comments_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/9514/comments","review_comment_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/9514/comments","statuses_url":"https://api.github.com/repos/dimagi/commcare-hq/statuses/1e60a8fd2949fb3156be56fb9ce6aa122ddd162f","head":{"label":"dimagi:add-tableau-dashboard","ref":"add-tableau-dashboard","sha":"1e60a8fd2949fb3156be56fb9ce6aa122ddd162f","user":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"repo":{"id":247278,"name":"commcare-hq","full_name":"dimagi/commcare-hq","owner":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dimagi/commcare-hq","description":"A server-side tool to help manage community health workers, written in Django","fork":false,"url":"https://api.github.com/repos/dimagi/commcare-hq","forks_url":"https://api.github.com/repos/dimagi/commcare-hq/forks","keys_url":"https://api.github.com/repos/dimagi/commcare-hq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimagi/commcare-hq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimagi/commcare-hq/teams","hooks_url":"https://api.github.com/repos/dimagi/commcare-hq/hooks","issue_events_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/events{/number}","events_url":"https://api.github.com/repos/dimagi/commcare-hq/events","assignees_url":"https://api.github.com/repos/dimagi/commcare-hq/assignees{/user}","branches_url":"https://api.github.com/repos/dimagi/commcare-hq/branches{/branch}","tags_url":"https://api.github.com/repos/dimagi/commcare-hq/tags","blobs_url":"https://api.github.com/repos/dimagi/commcare-hq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimagi/commcare-hq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimagi/commcare-hq/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimagi/commcare-hq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimagi/commcare-hq/statuses/{sha}","languages_url":"https://api.github.com/repos/dimagi/commcare-hq/languages","stargazers_url":"https://api.github.com/repos/dimagi/commcare-hq/stargazers","contributors_url":"https://api.github.com/repos/dimagi/commcare-hq/contributors","subscribers_url":"https://api.github.com/repos/dimagi/commcare-hq/subscribers","subscription_url":"https://api.github.com/repos/dimagi/commcare-hq/subscription","commits_url":"https://api.github.com/repos/dimagi/commcare-hq/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimagi/commcare-hq/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimagi/commcare-hq/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/comments{/number}","contents_url":"https://api.github.com/repos/dimagi/commcare-hq/contents/{+path}","compare_url":"https://api.github.com/repos/dimagi/commcare-hq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimagi/commcare-hq/merges","archive_url":"https://api.github.com/repos/dimagi/commcare-hq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimagi/commcare-hq/downloads","issues_url":"https://api.github.com/repos/dimagi/commcare-hq/issues{/number}","pulls_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls{/number}","milestones_url":"https://api.github.com/repos/dimagi/commcare-hq/milestones{/number}","notifications_url":"https://api.github.com/repos/dimagi/commcare-hq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimagi/commcare-hq/labels{/name}","releases_url":"https://api.github.com/repos/dimagi/commcare-hq/releases{/id}","created_at":"2009-07-09T17:00:07Z","updated_at":"2015-12-02T20:47:28Z","pushed_at":"2015-12-11T06:34:14Z","git_url":"git://github.com/dimagi/commcare-hq.git","ssh_url":"git@github.com:dimagi/commcare-hq.git","clone_url":"https://github.com/dimagi/commcare-hq.git","svn_url":"https://github.com/dimagi/commcare-hq","homepage":"http://www.commcarehq.org","size":238183,"stargazers_count":57,"watchers_count":57,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":63,"mirror_url":null,"open_issues_count":60,"forks":63,"open_issues":60,"watchers":57,"default_branch":"master"}},"base":{"label":"dimagi:master","ref":"master","sha":"01464841f387741fa8c6b6f58534087230618c90","user":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"repo":{"id":247278,"name":"commcare-hq","full_name":"dimagi/commcare-hq","owner":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dimagi/commcare-hq","description":"A server-side tool to help manage community health workers, written in Django","fork":false,"url":"https://api.github.com/repos/dimagi/commcare-hq","forks_url":"https://api.github.com/repos/dimagi/commcare-hq/forks","keys_url":"https://api.github.com/repos/dimagi/commcare-hq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimagi/commcare-hq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimagi/commcare-hq/teams","hooks_url":"https://api.github.com/repos/dimagi/commcare-hq/hooks","issue_events_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/events{/number}","events_url":"https://api.github.com/repos/dimagi/commcare-hq/events","assignees_url":"https://api.github.com/repos/dimagi/commcare-hq/assignees{/user}","branches_url":"https://api.github.com/repos/dimagi/commcare-hq/branches{/branch}","tags_url":"https://api.github.com/repos/dimagi/commcare-hq/tags","blobs_url":"https://api.github.com/repos/dimagi/commcare-hq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimagi/commcare-hq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimagi/commcare-hq/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimagi/commcare-hq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimagi/commcare-hq/statuses/{sha}","languages_url":"https://api.github.com/repos/dimagi/commcare-hq/languages","stargazers_url":"https://api.github.com/repos/dimagi/commcare-hq/stargazers","contributors_url":"https://api.github.com/repos/dimagi/commcare-hq/contributors","subscribers_url":"https://api.github.com/repos/dimagi/commcare-hq/subscribers","subscription_url":"https://api.github.com/repos/dimagi/commcare-hq/subscription","commits_url":"https://api.github.com/repos/dimagi/commcare-hq/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimagi/commcare-hq/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimagi/commcare-hq/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/comments{/number}","contents_url":"https://api.github.com/repos/dimagi/commcare-hq/contents/{+path}","compare_url":"https://api.github.com/repos/dimagi/commcare-hq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimagi/commcare-hq/merges","archive_url":"https://api.github.com/repos/dimagi/commcare-hq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimagi/commcare-hq/downloads","issues_url":"https://api.github.com/repos/dimagi/commcare-hq/issues{/number}","pulls_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls{/number}","milestones_url":"https://api.github.com/repos/dimagi/commcare-hq/milestones{/number}","notifications_url":"https://api.github.com/repos/dimagi/commcare-hq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimagi/commcare-hq/labels{/name}","releases_url":"https://api.github.com/repos/dimagi/commcare-hq/releases{/id}","created_at":"2009-07-09T17:00:07Z","updated_at":"2015-12-02T20:47:28Z","pushed_at":"2015-12-11T06:34:14Z","git_url":"git://github.com/dimagi/commcare-hq.git","ssh_url":"git@github.com:dimagi/commcare-hq.git","clone_url":"https://github.com/dimagi/commcare-hq.git","svn_url":"https://github.com/dimagi/commcare-hq","homepage":"http://www.commcarehq.org","size":238183,"stargazers_count":57,"watchers_count":57,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":63,"mirror_url":null,"open_issues_count":60,"forks":63,"open_issues":60,"watchers":57,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/9514"},"html":{"href":"https://github.com/dimagi/commcare-hq/pull/9514"},"issue":{"href":"https://api.github.com/repos/dimagi/commcare-hq/issues/9514"},"comments":{"href":"https://api.github.com/repos/dimagi/commcare-hq/issues/9514/comments"},"review_comments":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/9514/comments"},"review_comment":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/9514/commits"},"statuses":{"href":"https://api.github.com/repos/dimagi/commcare-hq/statuses/1e60a8fd2949fb3156be56fb9ce6aa122ddd162f"}}}}