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 | 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
test/functional/users_controller_test.rb