{"action":"created","comment":{"url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments/64464269","id":64464269,"diff_hunk":"@@ -408,3 +330,145 @@ def extract_form_info(form, properties=None, case_ids=case_ids):\n         )\n \n     DownloadBase.set_progress(build_form_multimedia_zip, num_forms, num_forms)\n+\n+\n+def _write_attachments_to_file(fpath, use_transfer, num_forms, forms_info):\n+\n+    def filename(form_info, question_id, extension):\n+        return u\"{}-{}-{}{}\".format(\n+            unidecode(question_id),\n+            form_info['user'],\n+            form_info['id'],\n+            extension\n+        )\n+\n+    if not (os.path.isfile(fpath) and use_transfer):  # Don't rebuild the file if it is already there\n+        with open(fpath, 'wb') as zfile:\n+            with zipfile.ZipFile(zfile, 'w') as z:\n+                for form_number, form_info in enumerate(forms_info):\n+                    f = form_info['form']\n+                    for a in form_info['attachments']:\n+                        fname = filename(form_info, a['question_id'], a['extension'])\n+                        zi = zipfile.ZipInfo(fname, a['timestamp'])\n+                        z.writestr(zi, f.get_attachment(a['name']), zipfile.ZIP_STORED)\n+                    DownloadBase.set_progress(build_form_multimedia_zip, form_number + 1, num_forms)\n+\n+\n+def _get_export_properties(export_id, export_is_legacy):\n+    \"\"\"\n+    Return a list of strings corresponding to form questions that are\n+    included in the export.\n+    \"\"\"\n+    properties = set()\n+    if export_id:\n+        if export_is_legacy:\n+            schema = FormExportSchema.get(export_id)\n+            for table in schema.tables:\n+                # - in question id is replaced by . in excel exports\n+                properties |= {c.display.replace('.', '-') for c in\n+                               table.columns}\n+        else:\n+            from corehq.apps.export.models import FormExportInstance\n+            export = FormExportInstance.get(export_id)\n+            for table in export.tables:\n+                for column in table.columns:\n+                    if column.item:\n+                        path_parts = [n.name for n in column.item.path]\n+                        path_parts = path_parts[1:] if path_parts[0] == \"form\" else path_parts\n+                        properties.add(\"-\".join(path_parts))\n+    return properties\n+\n+\n+def _get_form_ids(domain, app_id, xmlns, startdate, enddate, export_is_legacy):\n+    \"\"\"\n+    Return a list of form ids.\n+    Each form has a multimedia attachment and meets the given filters.\n+    \"\"\"\n+    if not export_is_legacy:\n+        query = (FormES()\n+                 .domain(domain)\n+                 .app(app_id)\n+                 .xmlns(xmlns)\n+                 .submitted(gte=parse(startdate), lte=parse(enddate))\n+                 .remove_default_filter(\"has_user\"))\n+        form_ids = set()\n+        for form in query.scroll():\n+            try:\n+                for attachment in form['_attachments'].values():\n+                    if attachment['content_type'] != \"text/xml\":\n+                        form_ids.add(form['_id'])\n+                        continue\n+            except AttributeError:\n+                pass\n+    else:\n+        key = [domain, app_id, xmlns]\n+        form_ids = {\n+            f['id'] for f in\n+            XFormInstance.get_db().view(\n+                \"attachments/attachments\",\n+                start_key=key + [startdate],\n+                end_key=key + [enddate, {}],\n+                reduce=False\n+            )\n+            }","path":"corehq/apps/reports/tasks.py","position":233,"original_position":233,"commit_id":"269092ee059f01609fff35d5b9945564642be38b","original_commit_id":"269092ee059f01609fff35d5b9945564642be38b","user":{"login":"dimagimon","id":1179034,"avatar_url":"https://avatars.githubusercontent.com/u/1179034?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagimon","html_url":"https://github.com/dimagimon","followers_url":"https://api.github.com/users/dimagimon/followers","following_url":"https://api.github.com/users/dimagimon/following{/other_user}","gists_url":"https://api.github.com/users/dimagimon/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagimon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagimon/subscriptions","organizations_url":"https://api.github.com/users/dimagimon/orgs","repos_url":"https://api.github.com/users/dimagimon/repos","events_url":"https://api.github.com/users/dimagimon/events{/privacy}","received_events_url":"https://api.github.com/users/dimagimon/received_events","type":"User","site_admin":false},"body":"E123 closing bracket does not match indentation of opening bracket's line","created_at":"2016-05-24T20:06:06Z","updated_at":"2016-05-24T20:06:06Z","html_url":"https://github.com/dimagi/commcare-hq/pull/11737#discussion_r64464269","pull_request_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/11737","_links":{"self":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments/64464269"},"html":{"href":"https://github.com/dimagi/commcare-hq/pull/11737#discussion_r64464269"},"pull_request":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/11737"}}},"pull_request":{"url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/11737","id":71283769,"html_url":"https://github.com/dimagi/commcare-hq/pull/11737","diff_url":"https://github.com/dimagi/commcare-hq/pull/11737.diff","patch_url":"https://github.com/dimagi/commcare-hq/pull/11737.patch","issue_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/11737","number":11737,"state":"open","locked":false,"title":"Make multimedia exports compatible with \"new exports\"","user":{"login":"NoahCarnahan","id":2117127,"avatar_url":"https://avatars.githubusercontent.com/u/2117127?v=3","gravatar_id":"","url":"https://api.github.com/users/NoahCarnahan","html_url":"https://github.com/NoahCarnahan","followers_url":"https://api.github.com/users/NoahCarnahan/followers","following_url":"https://api.github.com/users/NoahCarnahan/following{/other_user}","gists_url":"https://api.github.com/users/NoahCarnahan/gists{/gist_id}","starred_url":"https://api.github.com/users/NoahCarnahan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NoahCarnahan/subscriptions","organizations_url":"https://api.github.com/users/NoahCarnahan/orgs","repos_url":"https://api.github.com/users/NoahCarnahan/repos","events_url":"https://api.github.com/users/NoahCarnahan/events{/privacy}","received_events_url":"https://api.github.com/users/NoahCarnahan/received_events","type":"User","site_admin":false},"body":"Best reviewed commit-by-commit\r\n@snopoke @benrudolph \r\n\r\n","created_at":"2016-05-24T20:05:30Z","updated_at":"2016-05-24T20:06:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c76568370aa3cd0a10f80f193637fa6cbd200d48","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/11737/commits","review_comments_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/11737/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/11737/comments","statuses_url":"https://api.github.com/repos/dimagi/commcare-hq/statuses/269092ee059f01609fff35d5b9945564642be38b","head":{"label":"dimagi:mm-exports","ref":"mm-exports","sha":"269092ee059f01609fff35d5b9945564642be38b","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}","deployments_url":"https://api.github.com/repos/dimagi/commcare-hq/deployments","created_at":"2009-07-09T17:00:07Z","updated_at":"2016-05-16T15:23:03Z","pushed_at":"2016-05-24T20:05:31Z","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":296321,"stargazers_count":72,"watchers_count":72,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":68,"mirror_url":null,"open_issues_count":49,"forks":68,"open_issues":49,"watchers":72,"default_branch":"master"}},"base":{"label":"dimagi:master","ref":"master","sha":"7f4b5442b9fc7206bbc1ed0ca609f7d41b8b7d4f","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}","deployments_url":"https://api.github.com/repos/dimagi/commcare-hq/deployments","created_at":"2009-07-09T17:00:07Z","updated_at":"2016-05-16T15:23:03Z","pushed_at":"2016-05-24T20:05:31Z","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":296321,"stargazers_count":72,"watchers_count":72,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":68,"mirror_url":null,"open_issues_count":49,"forks":68,"open_issues":49,"watchers":72,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/11737"},"html":{"href":"https://github.com/dimagi/commcare-hq/pull/11737"},"issue":{"href":"https://api.github.com/repos/dimagi/commcare-hq/issues/11737"},"comments":{"href":"https://api.github.com/repos/dimagi/commcare-hq/issues/11737/comments"},"review_comments":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/11737/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/11737/commits"},"statuses":{"href":"https://api.github.com/repos/dimagi/commcare-hq/statuses/269092ee059f01609fff35d5b9945564642be38b"}}}}
{"actor":{"display_login":"dimagimon"}}