Use FasterCSV or ruby1.9 CSV instead of ruby1.8 builtin CSV.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3007 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
4ea714fb91
commit
27e3fa2bed
|
@ -82,7 +82,7 @@ class IssuesController < ApplicationController
|
||||||
render :template => 'issues/index.rhtml', :layout => !request.xhr?
|
render :template => 'issues/index.rhtml', :layout => !request.xhr?
|
||||||
}
|
}
|
||||||
format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
|
format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
|
||||||
format.csv { send_data(issues_to_csv(@issues, @project).read, :type => 'text/csv; header=present', :filename => 'export.csv') }
|
format.csv { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') }
|
||||||
format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
|
format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
|
@ -147,7 +147,7 @@ class TimelogController < ApplicationController
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { render :layout => !request.xhr? }
|
format.html { render :layout => !request.xhr? }
|
||||||
format.csv { send_data(report_to_csv(@criterias, @periods, @hours).read, :type => 'text/csv; header=present', :filename => 'timelog.csv') }
|
format.csv { send_data(report_to_csv(@criterias, @periods, @hours), :type => 'text/csv; header=present', :filename => 'timelog.csv') }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ class TimelogController < ApplicationController
|
||||||
:include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
|
:include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
|
||||||
:conditions => cond.conditions,
|
:conditions => cond.conditions,
|
||||||
:order => sort_clause)
|
:order => sort_clause)
|
||||||
send_data(entries_to_csv(@entries).read, :type => 'text/csv; header=present', :filename => 'timelog.csv')
|
send_data(entries_to_csv(@entries), :type => 'text/csv; header=present', :filename => 'timelog.csv')
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,8 +15,6 @@
|
||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
require 'csv'
|
|
||||||
|
|
||||||
module IssuesHelper
|
module IssuesHelper
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
|
|
||||||
|
@ -146,8 +144,7 @@ module IssuesHelper
|
||||||
def issues_to_csv(issues, project = nil)
|
def issues_to_csv(issues, project = nil)
|
||||||
ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
|
ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
|
||||||
decimal_separator = l(:general_csv_decimal_separator)
|
decimal_separator = l(:general_csv_decimal_separator)
|
||||||
export = StringIO.new
|
export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
|
||||||
CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
|
|
||||||
# csv header fields
|
# csv header fields
|
||||||
headers = [ "#",
|
headers = [ "#",
|
||||||
l(:field_status),
|
l(:field_status),
|
||||||
|
@ -197,7 +194,6 @@ module IssuesHelper
|
||||||
csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
|
csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
export.rewind
|
|
||||||
export
|
export
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -81,8 +81,7 @@ module TimelogHelper
|
||||||
ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
|
ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
|
||||||
decimal_separator = l(:general_csv_decimal_separator)
|
decimal_separator = l(:general_csv_decimal_separator)
|
||||||
custom_fields = TimeEntryCustomField.find(:all)
|
custom_fields = TimeEntryCustomField.find(:all)
|
||||||
export = StringIO.new
|
export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
|
||||||
CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
|
|
||||||
# csv header fields
|
# csv header fields
|
||||||
headers = [l(:field_spent_on),
|
headers = [l(:field_spent_on),
|
||||||
l(:field_user),
|
l(:field_user),
|
||||||
|
@ -115,7 +114,6 @@ module TimelogHelper
|
||||||
csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
|
csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
export.rewind
|
|
||||||
export
|
export
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -124,8 +122,7 @@ module TimelogHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def report_to_csv(criterias, periods, hours)
|
def report_to_csv(criterias, periods, hours)
|
||||||
export = StringIO.new
|
export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
|
||||||
CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
|
|
||||||
# Column headers
|
# Column headers
|
||||||
headers = criterias.collect {|criteria| l(@available_criterias[criteria][:label]) }
|
headers = criterias.collect {|criteria| l(@available_criterias[criteria][:label]) }
|
||||||
headers += periods
|
headers += periods
|
||||||
|
@ -144,7 +141,6 @@ module TimelogHelper
|
||||||
row << "%.2f" %total
|
row << "%.2f" %total
|
||||||
csv << row
|
csv << row
|
||||||
end
|
end
|
||||||
export.rewind
|
|
||||||
export
|
export
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -14,6 +14,13 @@ rescue LoadError
|
||||||
# RMagick is not available
|
# RMagick is not available
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if RUBY_VERSION < '1.9'
|
||||||
|
require 'faster_csv'
|
||||||
|
else
|
||||||
|
require 'csv'
|
||||||
|
FCSV = CSV
|
||||||
|
end
|
||||||
|
|
||||||
REDMINE_SUPPORTED_SCM = %w( Subversion Darcs Mercurial Cvs Bazaar Git Filesystem )
|
REDMINE_SUPPORTED_SCM = %w( Subversion Darcs Mercurial Cvs Bazaar Git Filesystem )
|
||||||
|
|
||||||
# Permissions
|
# Permissions
|
||||||
|
|
|
@ -180,10 +180,13 @@ class IssuesControllerTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_index_csv_with_project
|
def test_index_csv_with_project
|
||||||
|
Setting.default_language = 'en'
|
||||||
|
|
||||||
get :index, :format => 'csv'
|
get :index, :format => 'csv'
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_not_nil assigns(:issues)
|
assert_not_nil assigns(:issues)
|
||||||
assert_equal 'text/csv', @response.content_type
|
assert_equal 'text/csv', @response.content_type
|
||||||
|
assert @response.body.starts_with?("#,")
|
||||||
|
|
||||||
get :index, :project_id => 1, :format => 'csv'
|
get :index, :project_id => 1, :format => 'csv'
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
|
Loading…
Reference in New Issue