Commit 5c6a55e0bf2f4fccacb541847719e2e01b53a2de

Authored by Rodrigo Souto
2 parents d3cc4cd5 7c6b674e

Merge commit 'refs/merge-requests/297' of git://gitorious.org/noosfero/noosfero …

…into merge-requests/297
app/controllers/admin/users_controller.rb
... ... @@ -15,8 +15,16 @@ class UsersController < AdminController
15 15 :disposition => "attachment; filename=users.xml"
16 16 end
17 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 28 end
21 29 end
22 30 end
... ...
app/views/users/_user_csv.rhtml
... ... @@ -1 +0,0 @@
1   -<%= user_csv.name %>;<%= user_csv.email %>
app/views/users/index_csv.rhtml
... ... @@ -1,2 +0,0 @@
1   -<%= _('name') %>;<%= _('email') %>
2   -<%= render :partial => 'user_csv', :collection => @users %>
test/functional/users_controller_test.rb
... ... @@ -42,6 +42,7 @@ class UsersControllerTest &lt; ActionController::TestCase
42 42  
43 43 get :index, :format => 'csv'
44 44 assert_equal 'text/csv', @response.content_type
  45 + assert_equal 'name;email', @response.body.split("\n")[0]
45 46 end
46 47  
47 48 end
... ...