Patch #5957 » users_export2.patch
| app/helpers/users_helper.rb (working copy) | ||
|---|---|---|
|
end
|
||
|
tabs
|
||
|
end
|
||
|
def users_to_csv(users)
|
||
|
ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
|
||
|
decimal_separator = l(:general_csv_decimal_separator)
|
||
|
export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
|
||
|
# csv header fields
|
||
|
headers = [ l(:field_login),
|
||
|
l(:field_firstname),
|
||
|
l(:field_lastname),
|
||
|
l(:field_mail),
|
||
|
l(:field_admin),
|
||
|
l(:field_created_on),
|
||
|
l(:field_last_login_on)
|
||
|
]
|
||
|
# Export user custom fields
|
||
|
custom_fields = UserCustomField.all
|
||
|
custom_fields.each {|f| headers << f.name}
|
||
|
# Description in the last column
|
||
|
csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
|
||
|
# csv lines
|
||
|
users.each do |user|
|
||
|
fields = [user.login,
|
||
|
user.firstname,
|
||
|
user.lastname,
|
||
|
user.mail,
|
||
|
user.admin,
|
||
|
user.created_on,
|
||
|
user.last_login_on
|
||
|
]
|
||
|
custom_fields.each {|f| fields << show_value(user.custom_value_for(f)) }
|
||
|
csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
|
||
|
end
|
||
|
end
|
||
|
export
|
||
|
end
|
||
|
end
|
||
| app/controllers/users_controller.rb (working copy) | ||
|---|---|---|
|
include SortHelper
|
||
|
helper :custom_fields
|
||
|
include CustomFieldsHelper
|
||
|
include UsersHelper
|
||
|
def index
|
||
|
sort_init 'login', 'asc'
|
||
| ... | ... | |
|
@user_pages = Paginator.new self, @user_count,
|
||
|
per_page_option,
|
||
|
params['page']
|
||
|
limit = (params[:format] == 'csv') ? nil : @user_pages.items_per_page
|
||
|
@users = User.find :all,:order => sort_clause,
|
||
|
:conditions => c.conditions,
|
||
|
:limit => @user_pages.items_per_page,
|
||
|
:limit => limit,
|
||
|
:offset => @user_pages.current.offset
|
||
|
render :layout => !request.xhr?
|
||
|
respond_to do |format|
|
||
|
format.html { render :layout => !request.xhr? }
|
||
|
format.csv { send_data(users_to_csv(@users), :type => 'text/csv; header=present', :filename => 'export.csv') }
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def show
|
||
| app/views/users/index.rhtml (working copy) | ||
|---|---|---|
|
</div>
|
||
|
<p class="pagination"><%= pagination_links_full @user_pages, @user_count %></p>
|
||
|
<% other_formats_links do |f| %>
|
||
|
<%= f.link_to 'CSV', :url => { :project_id => @project } %>
|
||
|
<% end %>
|
||
|
<% html_title(l(:label_user_plural)) -%>
|
||