Commit 5c6a55e0bf2f4fccacb541847719e2e01b53a2de
Exists in
master
and in
29 other branches
Merge commit 'refs/merge-requests/297' of git://gitorious.org/noosfero/noosfero …
…into merge-requests/297
Showing
4 changed files
with
11 additions
and
5 deletions
Show diff stats
app/controllers/admin/users_controller.rb
@@ -15,8 +15,16 @@ class UsersController < AdminController | @@ -15,8 +15,16 @@ class UsersController < AdminController | ||
15 | :disposition => "attachment; filename=users.xml" | 15 | :disposition => "attachment; filename=users.xml" |
16 | end | 16 | end |
17 | format.csv do | 17 | format.csv do |
18 | - @users = User.find(:all, :conditions => {:environment_id => environment.id}, :include => [:person]) | ||
19 | - render :template => "users/index_csv.rhtml", :content_type => 'text/csv', :layout => false | 18 | + # using a direct connection with the dbms to optimize |
19 | + command = User.send(:sanitize_sql, ["SELECT profiles.name, users.email FROM profiles | ||
20 | + INNER JOIN users ON profiles.user_id=users.id | ||
21 | + WHERE profiles.environment_id = ?", environment.id]) | ||
22 | + users = User.connection.execute(command) | ||
23 | + csv_content = "name;email\n" | ||
24 | + users.each { |u| | ||
25 | + CSV.generate_row([u['name'], u['email']], 2, csv_content, fs=';') | ||
26 | + } | ||
27 | + render :text => csv_content, :content_type => 'text/csv', :layout => false | ||
20 | end | 28 | end |
21 | end | 29 | end |
22 | end | 30 | end |
app/views/users/_user_csv.rhtml
@@ -1 +0,0 @@ | @@ -1 +0,0 @@ | ||
1 | -<%= user_csv.name %>;<%= user_csv.email %> |
app/views/users/index_csv.rhtml
test/functional/users_controller_test.rb
@@ -42,6 +42,7 @@ class UsersControllerTest < ActionController::TestCase | @@ -42,6 +42,7 @@ class UsersControllerTest < ActionController::TestCase | ||
42 | 42 | ||
43 | get :index, :format => 'csv' | 43 | get :index, :format => 'csv' |
44 | assert_equal 'text/csv', @response.content_type | 44 | assert_equal 'text/csv', @response.content_type |
45 | + assert_equal 'name;email', @response.body.split("\n")[0] | ||
45 | end | 46 | end |
46 | 47 | ||
47 | end | 48 | end |