Commit eed2f6dc authored by jplang's avatar jplang

Fixed that float custom fields do not use CSV decimal separator (#10364).

git-svn-id: https://svn.redmine.org/redmine/trunk@11441 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent b86f19b0
......@@ -372,7 +372,6 @@ module IssuesHelper
end
def issues_to_csv(issues, project, query, options={})
decimal_separator = l(:general_csv_decimal_separator)
encoding = l(:general_csv_encoding)
columns = (options[:columns] == 'all' ? query.available_inline_columns : query.inline_columns)
if options[:description]
......@@ -384,28 +383,9 @@ module IssuesHelper
export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
# csv header fields
csv << [ "#" ] + columns.collect {|c| Redmine::CodesetUtil.from_utf8(c.caption.to_s, encoding) }
# csv lines
issues.each do |issue|
col_values = columns.collect do |column|
s = if column.is_a?(QueryCustomFieldColumn)
cv = issue.custom_field_values.detect {|v| v.custom_field_id == column.custom_field.id}
show_value(cv)
else
value = column.value(issue)
if value.is_a?(Date)
format_date(value)
elsif value.is_a?(Time)
format_time(value)
elsif value.is_a?(Float)
("%.2f" % value).gsub('.', decimal_separator)
else
value
end
end
s.to_s
end
csv << [ issue.id.to_s ] + col_values.collect {|c| Redmine::CodesetUtil.from_utf8(c.to_s, encoding) }
csv << [ issue.id.to_s ] + columns.collect {|c| Redmine::CodesetUtil.from_utf8(csv_content(c, issue), encoding) }
end
end
export
......
......@@ -96,6 +96,31 @@ module QueriesHelper
end
end
def csv_content(column, issue)
value = column.value(issue)
if value.is_a?(Array)
value.collect {|v| csv_value(column, issue, v)}.compact.join(', ')
else
csv_value(column, issue, value)
end
end
def csv_value(column, issue, value)
case value.class.name
when 'Time'
format_time(value)
when 'Date'
format_date(value)
when 'Float'
sprintf("%.2f", value).gsub('.', l(:general_csv_decimal_separator))
when 'IssueRelation'
other = value.other_issue(issue)
l(value.label_for(issue)) + " ##{other.id}"
else
value.to_s
end
end
# Retrieve query from session or build a new query
def retrieve_query
if !params[:query_id].blank?
......
......@@ -433,6 +433,25 @@ class IssuesControllerTest < ActionController::TestCase
assert lines.detect {|line| line.include?('"MySQL, Oracle"')}
end
def test_index_csv_should_format_float_custom_fields_with_csv_decimal_separator
field = IssueCustomField.create!(:name => 'Float', :is_for_all => true, :tracker_ids => [1], :field_format => 'float')
issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {field.id => '185.6'})
with_settings :default_language => 'fr' do
get :index, :format => 'csv', :columns => 'all'
assert_response :success
issue_line = response.body.chomp.split("\n").map {|line| line.split(';')}.detect {|line| line[0]==issue.id.to_s}
assert_include '185,60', issue_line
end
with_settings :default_language => 'en' do
get :index, :format => 'csv', :columns => 'all'
assert_response :success
issue_line = response.body.chomp.split("\n").map {|line| line.split(',')}.detect {|line| line[0]==issue.id.to_s}
assert_include '185.60', issue_line
end
end
def test_index_csv_big_5
with_settings :default_language => "zh-TW" do
str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
......@@ -453,8 +472,8 @@ class IssuesControllerTest < ActionController::TestCase
if str_utf8.respond_to?(:force_encoding)
s1.force_encoding('Big5')
end
assert lines[0].include?(s1)
assert lines[1].include?(str_big5)
assert_include s1, lines[0]
assert_include str_big5, lines[1]
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment