{"action":"created","comment":{"url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls/comments/73875073","id":73875073,"diff_hunk":"@@ -296,3 +296,32 @@ def check_supplier_role(role, supplier_id):\n         abort(400, \"'supplier_id' is required for users with 'supplier' role\")\n     elif role != 'supplier' and supplier_id:\n         abort(400, \"'supplier_id' is only valid for users with 'supplier' role, not '{}'\".format(role))\n+\n+\n+@main.route(\"/buyers/briefs\", methods=[\"GET\"])\n+def export_buyers_and_their_briefs():\n+    buyers_with_briefs = db.session.query(User, Brief).\\\n+        outerjoin(BriefUser, User.id == BriefUser.user_id).\\\n+        outerjoin(Brief, BriefUser.brief_id == Brief.id).\\\n+        filter(User.role == 'buyer').\\\n+        order_by(User.name, Brief.id).\\\n+        all()\n+\n+    buyer_rows = []\n+    last_email_address = ''\n+    for buyer, brief in buyers_with_briefs:\n+        if buyer.email_address == last_email_address:\n+            last_email_address = buyer.email_address\n+            buyer_rows[-1]['briefs'] = buyer_rows[-1]['briefs'] + ', {} - {}'.\\\n+                format(brief.data.get('title'), brief.status) if brief else None\n+            continue\n+        last_email_address = buyer.email_address\n+        buyer_rows.append({\n+            'buyer_name': buyer.name,\n+            'buyer_email': buyer.email_address,\n+            'buyer_phone': buyer.phone_number,\n+            'buyer_created': buyer.created_at,\n+            'briefs': '{} - {}'.format(brief.data.get('title'), brief.status) if brief else ''\n+        })","path":"app/main/views/users.py","position":39,"original_position":39,"commit_id":"35456aefcb8126ef6e780170a0dd87e02fd89c53","original_commit_id":"35456aefcb8126ef6e780170a0dd87e02fd89c53","user":{"login":"risicle","id":807447,"avatar_url":"https://avatars.githubusercontent.com/u/807447?v=3","gravatar_id":"","url":"https://api.github.com/users/risicle","html_url":"https://github.com/risicle","followers_url":"https://api.github.com/users/risicle/followers","following_url":"https://api.github.com/users/risicle/following{/other_user}","gists_url":"https://api.github.com/users/risicle/gists{/gist_id}","starred_url":"https://api.github.com/users/risicle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/risicle/subscriptions","organizations_url":"https://api.github.com/users/risicle/orgs","repos_url":"https://api.github.com/users/risicle/repos","events_url":"https://api.github.com/users/risicle/events{/privacy}","received_events_url":"https://api.github.com/users/risicle/received_events","type":"User","site_admin":false},"body":"Also, if you did need to do it in python, a much clearer & less error prone way do aggregations is using `itertools.groupby`\r\n\r\nhttps://docs.python.org/2/library/itertools.html#itertools.groupby\r\n\r\nAgain, see me if you want to know more...","created_at":"2016-08-08T13:32:47Z","updated_at":"2016-08-08T13:32:47Z","html_url":"https://github.com/alphagov/digitalmarketplace-api/pull/430#discussion_r73875073","pull_request_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls/430","_links":{"self":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls/comments/73875073"},"html":{"href":"https://github.com/alphagov/digitalmarketplace-api/pull/430#discussion_r73875073"},"pull_request":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls/430"}}},"pull_request":{"url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls/430","id":80255600,"html_url":"https://github.com/alphagov/digitalmarketplace-api/pull/430","diff_url":"https://github.com/alphagov/digitalmarketplace-api/pull/430.diff","patch_url":"https://github.com/alphagov/digitalmarketplace-api/pull/430.patch","issue_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/issues/430","number":430,"state":"open","locked":false,"title":"Admin can extract a list of buyers and their briefs.","user":{"login":"Wynndow","id":13836290,"avatar_url":"https://avatars.githubusercontent.com/u/13836290?v=3","gravatar_id":"","url":"https://api.github.com/users/Wynndow","html_url":"https://github.com/Wynndow","followers_url":"https://api.github.com/users/Wynndow/followers","following_url":"https://api.github.com/users/Wynndow/following{/other_user}","gists_url":"https://api.github.com/users/Wynndow/gists{/gist_id}","starred_url":"https://api.github.com/users/Wynndow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wynndow/subscriptions","organizations_url":"https://api.github.com/users/Wynndow/orgs","repos_url":"https://api.github.com/users/Wynndow/repos","events_url":"https://api.github.com/users/Wynndow/events{/privacy}","received_events_url":"https://api.github.com/users/Wynndow/received_events","type":"User","site_admin":false},"body":"For [this](https://www.pivotaltracker.com/story/show/124104161) story on Pivotal.\r\n\r\nAdmin's need to be able to extract a csv of buyers details and their briefs from the admin app. Rather than polling the api for every buyer, this sets up a new endpoint which returns them all in one hit.\r\n\r\nThe database query returns a row for every brief with buyer details duplicated, so there is also some logic to reduce the rows to one per buyer with all their briefs together.","created_at":"2016-08-05T14:49:22Z","updated_at":"2016-08-08T13:32:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1f1c063a173107ae4cafa2b40140176eb10b70c5","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls/430/commits","review_comments_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls/430/comments","review_comment_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/issues/430/comments","statuses_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/statuses/35456aefcb8126ef6e780170a0dd87e02fd89c53","head":{"label":"alphagov:admin_extract_buyer_and_briefs_list","ref":"admin_extract_buyer_and_briefs_list","sha":"35456aefcb8126ef6e780170a0dd87e02fd89c53","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":26963583,"name":"digitalmarketplace-api","full_name":"alphagov/digitalmarketplace-api","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/digitalmarketplace-api","description":"Digital Marketplace API.","fork":false,"url":"https://api.github.com/repos/alphagov/digitalmarketplace-api","forks_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/forks","keys_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/teams","hooks_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/hooks","issue_events_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/events","assignees_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/tags","blobs_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/languages","stargazers_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/stargazers","contributors_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/contributors","subscribers_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/subscribers","subscription_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/subscription","commits_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/merges","archive_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/downloads","issues_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/releases{/id}","deployments_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/deployments","created_at":"2014-11-21T14:41:36Z","updated_at":"2016-03-27T08:06:55Z","pushed_at":"2016-08-05T15:04:49Z","git_url":"git://github.com/alphagov/digitalmarketplace-api.git","ssh_url":"git@github.com:alphagov/digitalmarketplace-api.git","clone_url":"https://github.com/alphagov/digitalmarketplace-api.git","svn_url":"https://github.com/alphagov/digitalmarketplace-api","homepage":null,"size":2292,"stargazers_count":7,"watchers_count":7,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":1,"forks":7,"open_issues":1,"watchers":7,"default_branch":"master"}},"base":{"label":"alphagov:master","ref":"master","sha":"6a6d62afd4621e435cb4758960ac3eb8f1df730a","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":26963583,"name":"digitalmarketplace-api","full_name":"alphagov/digitalmarketplace-api","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/digitalmarketplace-api","description":"Digital Marketplace API.","fork":false,"url":"https://api.github.com/repos/alphagov/digitalmarketplace-api","forks_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/forks","keys_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/teams","hooks_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/hooks","issue_events_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/events","assignees_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/tags","blobs_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/languages","stargazers_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/stargazers","contributors_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/contributors","subscribers_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/subscribers","subscription_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/subscription","commits_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/merges","archive_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/downloads","issues_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/releases{/id}","deployments_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/deployments","created_at":"2014-11-21T14:41:36Z","updated_at":"2016-03-27T08:06:55Z","pushed_at":"2016-08-05T15:04:49Z","git_url":"git://github.com/alphagov/digitalmarketplace-api.git","ssh_url":"git@github.com:alphagov/digitalmarketplace-api.git","clone_url":"https://github.com/alphagov/digitalmarketplace-api.git","svn_url":"https://github.com/alphagov/digitalmarketplace-api","homepage":null,"size":2292,"stargazers_count":7,"watchers_count":7,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":1,"forks":7,"open_issues":1,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls/430"},"html":{"href":"https://github.com/alphagov/digitalmarketplace-api/pull/430"},"issue":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-api/issues/430"},"comments":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-api/issues/430/comments"},"review_comments":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls/430/comments"},"review_comment":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls/430/commits"},"statuses":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-api/statuses/35456aefcb8126ef6e780170a0dd87e02fd89c53"}}}}
{"actor":{"display_login":"risicle"}}