{"action":"closed","number":1038,"pull_request":{"url":"https://api.github.com/repos/flask-admin/flask-admin/pulls/1038","id":43841260,"html_url":"https://github.com/flask-admin/flask-admin/pull/1038","diff_url":"https://github.com/flask-admin/flask-admin/pull/1038.diff","patch_url":"https://github.com/flask-admin/flask-admin/pull/1038.patch","issue_url":"https://api.github.com/repos/flask-admin/flask-admin/issues/1038","number":1038,"state":"closed","locked":false,"title":"Implement CSV export for BaseModelView.","user":{"login":"tandreas","id":7153106,"avatar_url":"https://avatars.githubusercontent.com/u/7153106?v=3","gravatar_id":"","url":"https://api.github.com/users/tandreas","html_url":"https://github.com/tandreas","followers_url":"https://api.github.com/users/tandreas/followers","following_url":"https://api.github.com/users/tandreas/following{/other_user}","gists_url":"https://api.github.com/users/tandreas/gists{/gist_id}","starred_url":"https://api.github.com/users/tandreas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tandreas/subscriptions","organizations_url":"https://api.github.com/users/tandreas/orgs","repos_url":"https://api.github.com/users/tandreas/repos","events_url":"https://api.github.com/users/tandreas/events{/privacy}","received_events_url":"https://api.github.com/users/tandreas/received_events","type":"User","site_admin":false},"body":"This pull request implements a csv export in BaseModelView.\r\n\r\n* New attribute can_export enables an Export button and the /export/csv endpoint.  Default is False.\r\n\r\n* New attribute export_max_rows will truncate the CSV to a maximum number of rows.\r\n  Necessary for very large tables.  Default is None.\r\n\r\n* New attribute column_formatters_export allows custom column formatters for exports.\r\n  This was done in case the current column_formatters inject HTML or use a Jinaj2 Macro.\r\n  Defaults to column_formatters if not set.\r\n\r\n* New attribute column_type_formatters_export is by default the same as column_type_formatters\r\n  except that it removes the bool_formatter which injects HTML, called EXPORT_FORMATTERS.\r\n\r\n* get_list_value was refactored to allow different formatters and to make having a Jinja2 context optional.\r\n  A new method _get_list_value was implemented that does most of the logic.\r\n  get_list_value and the new method get_export_value call _get_list_value.\r\n\r\n* CSV export was implemented in export_csv at the endpoint /export/csv.\r\n  Uses a generator to stream the CSV as to use less memory in the case of large lists.\r\n\r\n* csv_encode was added to _compat for Python 2 and Python 3 compatibility with unicode.\r\n\r\n* In order to generate an error if a macro is used with column_formatters before streaming \r\n  occurs, a check is made to throw an error if the function name is \"inner\".\r\n  This is the name of the function flask_admin.model.template.macro returns.\r\n  I'm open to better ideas to determine if the column_formatter is a macro.\r\n\r\n* Changes to test_model.py include making it easier to add your own dict of data to a \r\n  view and use page_size with get_list.\r\n\r\n* Adds tests for CSV export.\r\n\r\nThanks to @pawl for helping!\r\n","created_at":"2015-09-01T06:25:32Z","updated_at":"2015-09-01T13:13:44Z","closed_at":"2015-09-01T13:13:44Z","merged_at":"2015-09-01T13:13:44Z","merge_commit_sha":"021f23be607b29e10d09e305caf5999754f8e1d5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/flask-admin/flask-admin/pulls/1038/commits","review_comments_url":"https://api.github.com/repos/flask-admin/flask-admin/pulls/1038/comments","review_comment_url":"https://api.github.com/repos/flask-admin/flask-admin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/flask-admin/flask-admin/issues/1038/comments","statuses_url":"https://api.github.com/repos/flask-admin/flask-admin/statuses/51113b959912b66a23f99537c666a26961f6de22","head":{"label":"tandreas:csv_export","ref":"csv_export","sha":"51113b959912b66a23f99537c666a26961f6de22","user":{"login":"tandreas","id":7153106,"avatar_url":"https://avatars.githubusercontent.com/u/7153106?v=3","gravatar_id":"","url":"https://api.github.com/users/tandreas","html_url":"https://github.com/tandreas","followers_url":"https://api.github.com/users/tandreas/followers","following_url":"https://api.github.com/users/tandreas/following{/other_user}","gists_url":"https://api.github.com/users/tandreas/gists{/gist_id}","starred_url":"https://api.github.com/users/tandreas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tandreas/subscriptions","organizations_url":"https://api.github.com/users/tandreas/orgs","repos_url":"https://api.github.com/users/tandreas/repos","events_url":"https://api.github.com/users/tandreas/events{/privacy}","received_events_url":"https://api.github.com/users/tandreas/received_events","type":"User","site_admin":false},"repo":{"id":23850692,"name":"flask-admin","full_name":"tandreas/flask-admin","owner":{"login":"tandreas","id":7153106,"avatar_url":"https://avatars.githubusercontent.com/u/7153106?v=3","gravatar_id":"","url":"https://api.github.com/users/tandreas","html_url":"https://github.com/tandreas","followers_url":"https://api.github.com/users/tandreas/followers","following_url":"https://api.github.com/users/tandreas/following{/other_user}","gists_url":"https://api.github.com/users/tandreas/gists{/gist_id}","starred_url":"https://api.github.com/users/tandreas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tandreas/subscriptions","organizations_url":"https://api.github.com/users/tandreas/orgs","repos_url":"https://api.github.com/users/tandreas/repos","events_url":"https://api.github.com/users/tandreas/events{/privacy}","received_events_url":"https://api.github.com/users/tandreas/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tandreas/flask-admin","description":"Simple and extensible administrative interface framework for Flask","fork":true,"url":"https://api.github.com/repos/tandreas/flask-admin","forks_url":"https://api.github.com/repos/tandreas/flask-admin/forks","keys_url":"https://api.github.com/repos/tandreas/flask-admin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tandreas/flask-admin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tandreas/flask-admin/teams","hooks_url":"https://api.github.com/repos/tandreas/flask-admin/hooks","issue_events_url":"https://api.github.com/repos/tandreas/flask-admin/issues/events{/number}","events_url":"https://api.github.com/repos/tandreas/flask-admin/events","assignees_url":"https://api.github.com/repos/tandreas/flask-admin/assignees{/user}","branches_url":"https://api.github.com/repos/tandreas/flask-admin/branches{/branch}","tags_url":"https://api.github.com/repos/tandreas/flask-admin/tags","blobs_url":"https://api.github.com/repos/tandreas/flask-admin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tandreas/flask-admin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tandreas/flask-admin/git/refs{/sha}","trees_url":"https://api.github.com/repos/tandreas/flask-admin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tandreas/flask-admin/statuses/{sha}","languages_url":"https://api.github.com/repos/tandreas/flask-admin/languages","stargazers_url":"https://api.github.com/repos/tandreas/flask-admin/stargazers","contributors_url":"https://api.github.com/repos/tandreas/flask-admin/contributors","subscribers_url":"https://api.github.com/repos/tandreas/flask-admin/subscribers","subscription_url":"https://api.github.com/repos/tandreas/flask-admin/subscription","commits_url":"https://api.github.com/repos/tandreas/flask-admin/commits{/sha}","git_commits_url":"https://api.github.com/repos/tandreas/flask-admin/git/commits{/sha}","comments_url":"https://api.github.com/repos/tandreas/flask-admin/comments{/number}","issue_comment_url":"https://api.github.com/repos/tandreas/flask-admin/issues/comments{/number}","contents_url":"https://api.github.com/repos/tandreas/flask-admin/contents/{+path}","compare_url":"https://api.github.com/repos/tandreas/flask-admin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tandreas/flask-admin/merges","archive_url":"https://api.github.com/repos/tandreas/flask-admin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tandreas/flask-admin/downloads","issues_url":"https://api.github.com/repos/tandreas/flask-admin/issues{/number}","pulls_url":"https://api.github.com/repos/tandreas/flask-admin/pulls{/number}","milestones_url":"https://api.github.com/repos/tandreas/flask-admin/milestones{/number}","notifications_url":"https://api.github.com/repos/tandreas/flask-admin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tandreas/flask-admin/labels{/name}","releases_url":"https://api.github.com/repos/tandreas/flask-admin/releases{/id}","created_at":"2014-09-09T21:20:23Z","updated_at":"2014-09-09T22:23:10Z","pushed_at":"2015-09-01T06:19:14Z","git_url":"git://github.com/tandreas/flask-admin.git","ssh_url":"git@github.com:tandreas/flask-admin.git","clone_url":"https://github.com/tandreas/flask-admin.git","svn_url":"https://github.com/tandreas/flask-admin","homepage":"","size":8482,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"flask-admin:master","ref":"master","sha":"9db8c9e51c43fb3b885763bdc212453248a6a854","user":{"login":"flask-admin","id":12035958,"avatar_url":"https://avatars.githubusercontent.com/u/12035958?v=3","gravatar_id":"","url":"https://api.github.com/users/flask-admin","html_url":"https://github.com/flask-admin","followers_url":"https://api.github.com/users/flask-admin/followers","following_url":"https://api.github.com/users/flask-admin/following{/other_user}","gists_url":"https://api.github.com/users/flask-admin/gists{/gist_id}","starred_url":"https://api.github.com/users/flask-admin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flask-admin/subscriptions","organizations_url":"https://api.github.com/users/flask-admin/orgs","repos_url":"https://api.github.com/users/flask-admin/repos","events_url":"https://api.github.com/users/flask-admin/events{/privacy}","received_events_url":"https://api.github.com/users/flask-admin/received_events","type":"Organization","site_admin":false},"repo":{"id":3758878,"name":"flask-admin","full_name":"flask-admin/flask-admin","owner":{"login":"flask-admin","id":12035958,"avatar_url":"https://avatars.githubusercontent.com/u/12035958?v=3","gravatar_id":"","url":"https://api.github.com/users/flask-admin","html_url":"https://github.com/flask-admin","followers_url":"https://api.github.com/users/flask-admin/followers","following_url":"https://api.github.com/users/flask-admin/following{/other_user}","gists_url":"https://api.github.com/users/flask-admin/gists{/gist_id}","starred_url":"https://api.github.com/users/flask-admin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flask-admin/subscriptions","organizations_url":"https://api.github.com/users/flask-admin/orgs","repos_url":"https://api.github.com/users/flask-admin/repos","events_url":"https://api.github.com/users/flask-admin/events{/privacy}","received_events_url":"https://api.github.com/users/flask-admin/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/flask-admin/flask-admin","description":"Simple and extensible administrative interface framework for Flask","fork":false,"url":"https://api.github.com/repos/flask-admin/flask-admin","forks_url":"https://api.github.com/repos/flask-admin/flask-admin/forks","keys_url":"https://api.github.com/repos/flask-admin/flask-admin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/flask-admin/flask-admin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/flask-admin/flask-admin/teams","hooks_url":"https://api.github.com/repos/flask-admin/flask-admin/hooks","issue_events_url":"https://api.github.com/repos/flask-admin/flask-admin/issues/events{/number}","events_url":"https://api.github.com/repos/flask-admin/flask-admin/events","assignees_url":"https://api.github.com/repos/flask-admin/flask-admin/assignees{/user}","branches_url":"https://api.github.com/repos/flask-admin/flask-admin/branches{/branch}","tags_url":"https://api.github.com/repos/flask-admin/flask-admin/tags","blobs_url":"https://api.github.com/repos/flask-admin/flask-admin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/flask-admin/flask-admin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/flask-admin/flask-admin/git/refs{/sha}","trees_url":"https://api.github.com/repos/flask-admin/flask-admin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/flask-admin/flask-admin/statuses/{sha}","languages_url":"https://api.github.com/repos/flask-admin/flask-admin/languages","stargazers_url":"https://api.github.com/repos/flask-admin/flask-admin/stargazers","contributors_url":"https://api.github.com/repos/flask-admin/flask-admin/contributors","subscribers_url":"https://api.github.com/repos/flask-admin/flask-admin/subscribers","subscription_url":"https://api.github.com/repos/flask-admin/flask-admin/subscription","commits_url":"https://api.github.com/repos/flask-admin/flask-admin/commits{/sha}","git_commits_url":"https://api.github.com/repos/flask-admin/flask-admin/git/commits{/sha}","comments_url":"https://api.github.com/repos/flask-admin/flask-admin/comments{/number}","issue_comment_url":"https://api.github.com/repos/flask-admin/flask-admin/issues/comments{/number}","contents_url":"https://api.github.com/repos/flask-admin/flask-admin/contents/{+path}","compare_url":"https://api.github.com/repos/flask-admin/flask-admin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/flask-admin/flask-admin/merges","archive_url":"https://api.github.com/repos/flask-admin/flask-admin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/flask-admin/flask-admin/downloads","issues_url":"https://api.github.com/repos/flask-admin/flask-admin/issues{/number}","pulls_url":"https://api.github.com/repos/flask-admin/flask-admin/pulls{/number}","milestones_url":"https://api.github.com/repos/flask-admin/flask-admin/milestones{/number}","notifications_url":"https://api.github.com/repos/flask-admin/flask-admin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/flask-admin/flask-admin/labels{/name}","releases_url":"https://api.github.com/repos/flask-admin/flask-admin/releases{/id}","created_at":"2012-03-18T23:21:57Z","updated_at":"2015-08-31T15:59:38Z","pushed_at":"2015-09-01T13:13:44Z","git_url":"git://github.com/flask-admin/flask-admin.git","ssh_url":"git@github.com:flask-admin/flask-admin.git","clone_url":"https://github.com/flask-admin/flask-admin.git","svn_url":"https://github.com/flask-admin/flask-admin","homepage":"","size":13561,"stargazers_count":1344,"watchers_count":1344,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":450,"mirror_url":null,"open_issues_count":115,"forks":450,"open_issues":115,"watchers":1344,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/flask-admin/flask-admin/pulls/1038"},"html":{"href":"https://github.com/flask-admin/flask-admin/pull/1038"},"issue":{"href":"https://api.github.com/repos/flask-admin/flask-admin/issues/1038"},"comments":{"href":"https://api.github.com/repos/flask-admin/flask-admin/issues/1038/comments"},"review_comments":{"href":"https://api.github.com/repos/flask-admin/flask-admin/pulls/1038/comments"},"review_comment":{"href":"https://api.github.com/repos/flask-admin/flask-admin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/flask-admin/flask-admin/pulls/1038/commits"},"statuses":{"href":"https://api.github.com/repos/flask-admin/flask-admin/statuses/51113b959912b66a23f99537c666a26961f6de22"}},"merged":true,"mergeable":null,"mergeable_state":"unknown","merged_by":{"login":"mrjoes","id":179880,"avatar_url":"https://avatars.githubusercontent.com/u/179880?v=3","gravatar_id":"","url":"https://api.github.com/users/mrjoes","html_url":"https://github.com/mrjoes","followers_url":"https://api.github.com/users/mrjoes/followers","following_url":"https://api.github.com/users/mrjoes/following{/other_user}","gists_url":"https://api.github.com/users/mrjoes/gists{/gist_id}","starred_url":"https://api.github.com/users/mrjoes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrjoes/subscriptions","organizations_url":"https://api.github.com/users/mrjoes/orgs","repos_url":"https://api.github.com/users/mrjoes/repos","events_url":"https://api.github.com/users/mrjoes/events{/privacy}","received_events_url":"https://api.github.com/users/mrjoes/received_events","type":"User","site_admin":false},"comments":4,"review_comments":0,"commits":2,"additions":333,"deletions":18,"changed_files":7}}