{"action":"created","comment":{"url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments/30388469","id":30388469,"diff_hunk":"@@ -0,0 +1,165 @@\n+from django.utils.translation import ugettext_noop\n+from casexml.apps.case.models import CommCareCase\n+from corehq.apps.hqwebapp.doc_info import get_doc_info\n+from corehq.apps.locations.models import SQLLocation\n+from corehq.apps.reports.datatables import DataTablesHeader, DataTablesColumn\n+from corehq.apps.reports.filters.dates import DatespanFilter\n+from corehq.apps.reports.filters.fixtures import AsyncLocationFilter\n+from corehq.apps.reports.generic import GenericTabularReport\n+from corehq.apps.reports.standard import CustomProjectReport, ProjectReportParametersMixin, DatespanMixin\n+from corehq.apps.reports.util import format_datatables_data\n+from corehq.apps.sms.models import WORKFLOW_DEFAULT, SMSLog, INCOMING, OUTGOING\n+from corehq.apps.users.models import CouchUser\n+from corehq.const import SERVER_DATETIME_FORMAT\n+from corehq.util.timezones.conversions import ServerTime\n+from dimagi.utils.parsing import json_format_datetime\n+from django.utils.translation import ugettext as _\n+import settings\n+\n+\n+# copy paste from: https://github.com/dimagi/commcare-hq/blob/master/corehq/apps/reports/standard/sms.py\n+# we can't extend report by MessageLogReport.\n+def _fmt(val):\n+    if val is None:\n+        return format_datatables_data(\"-\", \"-\")\n+    else:\n+        return format_datatables_data(val, val)\n+\n+\n+class UnrecognizedSMSReport(CustomProjectReport, ProjectReportParametersMixin,\n+                            GenericTabularReport, DatespanMixin):\n+    name = ugettext_noop('Unrecognized SMS')\n+    slug = 'unrecognized_sms'\n+    fields = [AsyncLocationFilter, DatespanFilter]\n+    exportable = True\n+\n+    def _fmt_timestamp(self, timestamp):\n+        return self.table_cell(\n+            timestamp,\n+            timestamp.strftime(SERVER_DATETIME_FORMAT),\n+        )\n+\n+    def _fmt_contact_link(self, msg, doc_info):\n+        if doc_info:\n+            username, contact_type, url = (doc_info.display,\n+                doc_info.type_display, doc_info.link)\n+        else:\n+            username, contact_type, url = (None, None, None)\n+        username = username or \"-\"\n+        contact_type = contact_type or _(\"Unknown\")\n+        if url:\n+            ret = self.table_cell(username, '<a href=\"%s\">%s</a>' % (url, username))\n+        else:\n+            ret = self.table_cell(username, username)\n+        ret['raw'] = \"|||\".join([username, contact_type,\n+            msg.couch_recipient or \"\"])\n+        return ret\n+\n+    def get_recipient_info(self, message, contact_cache):\n+        recipient_id = message.couch_recipient\n+\n+        if recipient_id in contact_cache:\n+            return contact_cache[recipient_id]\n+\n+        doc = None\n+        if recipient_id not in [None, \"\"]:\n+            try:\n+                if message.couch_recipient_doc_type == \"CommCareCase\":\n+                    doc = CommCareCase.get(recipient_id)\n+                else:\n+                    doc = CouchUser.get_by_user_id(recipient_id)","path":"custom/ilsgateway/tanzania/reports/unrecognized_sms.py","position":70,"original_position":70,"commit_id":"dc4b61b56ef4799e8ca9b26f881ece5ae145e228","original_commit_id":"dc4b61b56ef4799e8ca9b26f881ece5ae145e228","user":{"login":"czue","id":66555,"avatar_url":"https://avatars.githubusercontent.com/u/66555?v=3","gravatar_id":"","url":"https://api.github.com/users/czue","html_url":"https://github.com/czue","followers_url":"https://api.github.com/users/czue/followers","following_url":"https://api.github.com/users/czue/following{/other_user}","gists_url":"https://api.github.com/users/czue/gists{/gist_id}","starred_url":"https://api.github.com/users/czue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/czue/subscriptions","organizations_url":"https://api.github.com/users/czue/orgs","repos_url":"https://api.github.com/users/czue/repos","events_url":"https://api.github.com/users/czue/events{/privacy}","received_events_url":"https://api.github.com/users/czue/received_events","type":"User","site_admin":false},"body":"if we end up showing a lot of data on this report we should probably cache these lookups.","created_at":"2015-05-15T06:50:00Z","updated_at":"2015-05-15T06:50:00Z","html_url":"https://github.com/dimagi/commcare-hq/pull/6672#discussion_r30388469","pull_request_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/6672","_links":{"self":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments/30388469"},"html":{"href":"https://github.com/dimagi/commcare-hq/pull/6672#discussion_r30388469"},"pull_request":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/6672"}}},"pull_request":{"url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/6672","id":35305365,"html_url":"https://github.com/dimagi/commcare-hq/pull/6672","diff_url":"https://github.com/dimagi/commcare-hq/pull/6672.diff","patch_url":"https://github.com/dimagi/commcare-hq/pull/6672.patch","issue_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/6672","number":6672,"state":"open","locked":false,"title":"Changes in ILS reports","user":{"login":"lwyszomi","id":429541,"avatar_url":"https://avatars.githubusercontent.com/u/429541?v=3","gravatar_id":"","url":"https://api.github.com/users/lwyszomi","html_url":"https://github.com/lwyszomi","followers_url":"https://api.github.com/users/lwyszomi/followers","following_url":"https://api.github.com/users/lwyszomi/following{/other_user}","gists_url":"https://api.github.com/users/lwyszomi/gists{/gist_id}","starred_url":"https://api.github.com/users/lwyszomi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lwyszomi/subscriptions","organizations_url":"https://api.github.com/users/lwyszomi/orgs","repos_url":"https://api.github.com/users/lwyszomi/repos","events_url":"https://api.github.com/users/lwyszomi/events{/privacy}","received_events_url":"https://api.github.com/users/lwyszomi/received_events","type":"User","site_admin":false},"body":"@czue ","created_at":"2015-05-13T08:46:26Z","updated_at":"2015-05-15T06:50:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f2261e8a2b2433e3ee06c3351252d390e3f8e66c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/6672/commits","review_comments_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/6672/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/6672/comments","statuses_url":"https://api.github.com/repos/dimagi/commcare-hq/statuses/dc4b61b56ef4799e8ca9b26f881ece5ae145e228","head":{"label":"lwyszomi:ils_reports_fix","ref":"ils_reports_fix","sha":"dc4b61b56ef4799e8ca9b26f881ece5ae145e228","user":{"login":"lwyszomi","id":429541,"avatar_url":"https://avatars.githubusercontent.com/u/429541?v=3","gravatar_id":"","url":"https://api.github.com/users/lwyszomi","html_url":"https://github.com/lwyszomi","followers_url":"https://api.github.com/users/lwyszomi/followers","following_url":"https://api.github.com/users/lwyszomi/following{/other_user}","gists_url":"https://api.github.com/users/lwyszomi/gists{/gist_id}","starred_url":"https://api.github.com/users/lwyszomi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lwyszomi/subscriptions","organizations_url":"https://api.github.com/users/lwyszomi/orgs","repos_url":"https://api.github.com/users/lwyszomi/repos","events_url":"https://api.github.com/users/lwyszomi/events{/privacy}","received_events_url":"https://api.github.com/users/lwyszomi/received_events","type":"User","site_admin":false},"repo":{"id":12557346,"name":"commcare-hq","full_name":"lwyszomi/commcare-hq","owner":{"login":"lwyszomi","id":429541,"avatar_url":"https://avatars.githubusercontent.com/u/429541?v=3","gravatar_id":"","url":"https://api.github.com/users/lwyszomi","html_url":"https://github.com/lwyszomi","followers_url":"https://api.github.com/users/lwyszomi/followers","following_url":"https://api.github.com/users/lwyszomi/following{/other_user}","gists_url":"https://api.github.com/users/lwyszomi/gists{/gist_id}","starred_url":"https://api.github.com/users/lwyszomi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lwyszomi/subscriptions","organizations_url":"https://api.github.com/users/lwyszomi/orgs","repos_url":"https://api.github.com/users/lwyszomi/repos","events_url":"https://api.github.com/users/lwyszomi/events{/privacy}","received_events_url":"https://api.github.com/users/lwyszomi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lwyszomi/commcare-hq","description":"A server-side tool to help manage community health workers, written in Django","fork":true,"url":"https://api.github.com/repos/lwyszomi/commcare-hq","forks_url":"https://api.github.com/repos/lwyszomi/commcare-hq/forks","keys_url":"https://api.github.com/repos/lwyszomi/commcare-hq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lwyszomi/commcare-hq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lwyszomi/commcare-hq/teams","hooks_url":"https://api.github.com/repos/lwyszomi/commcare-hq/hooks","issue_events_url":"https://api.github.com/repos/lwyszomi/commcare-hq/issues/events{/number}","events_url":"https://api.github.com/repos/lwyszomi/commcare-hq/events","assignees_url":"https://api.github.com/repos/lwyszomi/commcare-hq/assignees{/user}","branches_url":"https://api.github.com/repos/lwyszomi/commcare-hq/branches{/branch}","tags_url":"https://api.github.com/repos/lwyszomi/commcare-hq/tags","blobs_url":"https://api.github.com/repos/lwyszomi/commcare-hq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lwyszomi/commcare-hq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lwyszomi/commcare-hq/git/refs{/sha}","trees_url":"https://api.github.com/repos/lwyszomi/commcare-hq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lwyszomi/commcare-hq/statuses/{sha}","languages_url":"https://api.github.com/repos/lwyszomi/commcare-hq/languages","stargazers_url":"https://api.github.com/repos/lwyszomi/commcare-hq/stargazers","contributors_url":"https://api.github.com/repos/lwyszomi/commcare-hq/contributors","subscribers_url":"https://api.github.com/repos/lwyszomi/commcare-hq/subscribers","subscription_url":"https://api.github.com/repos/lwyszomi/commcare-hq/subscription","commits_url":"https://api.github.com/repos/lwyszomi/commcare-hq/commits{/sha}","git_commits_url":"https://api.github.com/repos/lwyszomi/commcare-hq/git/commits{/sha}","comments_url":"https://api.github.com/repos/lwyszomi/commcare-hq/comments{/number}","issue_comment_url":"https://api.github.com/repos/lwyszomi/commcare-hq/issues/comments{/number}","contents_url":"https://api.github.com/repos/lwyszomi/commcare-hq/contents/{+path}","compare_url":"https://api.github.com/repos/lwyszomi/commcare-hq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lwyszomi/commcare-hq/merges","archive_url":"https://api.github.com/repos/lwyszomi/commcare-hq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lwyszomi/commcare-hq/downloads","issues_url":"https://api.github.com/repos/lwyszomi/commcare-hq/issues{/number}","pulls_url":"https://api.github.com/repos/lwyszomi/commcare-hq/pulls{/number}","milestones_url":"https://api.github.com/repos/lwyszomi/commcare-hq/milestones{/number}","notifications_url":"https://api.github.com/repos/lwyszomi/commcare-hq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lwyszomi/commcare-hq/labels{/name}","releases_url":"https://api.github.com/repos/lwyszomi/commcare-hq/releases{/id}","created_at":"2013-09-03T07:05:35Z","updated_at":"2015-03-13T12:55:20Z","pushed_at":"2015-05-14T09:16:59Z","git_url":"git://github.com/lwyszomi/commcare-hq.git","ssh_url":"git@github.com:lwyszomi/commcare-hq.git","clone_url":"https://github.com/lwyszomi/commcare-hq.git","svn_url":"https://github.com/lwyszomi/commcare-hq","homepage":"http://www.commcarehq.org","size":170217,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"dimagi:master","ref":"master","sha":"eb31042e21002ffacce726ba25b9645b4207ef9f","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-05-08T20:08:47Z","pushed_at":"2015-05-15T06:46:55Z","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":389709,"stargazers_count":44,"watchers_count":44,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":57,"mirror_url":null,"open_issues_count":37,"forks":57,"open_issues":37,"watchers":44,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/6672"},"html":{"href":"https://github.com/dimagi/commcare-hq/pull/6672"},"issue":{"href":"https://api.github.com/repos/dimagi/commcare-hq/issues/6672"},"comments":{"href":"https://api.github.com/repos/dimagi/commcare-hq/issues/6672/comments"},"review_comments":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/6672/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/6672/commits"},"statuses":{"href":"https://api.github.com/repos/dimagi/commcare-hq/statuses/dc4b61b56ef4799e8ca9b26f881ece5ae145e228"}}}}