Skip to content

Commit 2726b03

Browse files
committed
Quiz report should use user's preference of CSV
1 parent 51ab2c9 commit 2726b03

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

app/controllers/quizzes/quiz_reports_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def create
172172
end
173173

174174
statistics.abort_csv_generation if statistics.csv_generation_failed?
175-
statistics.generate_csv_in_background
175+
statistics.generate_csv_in_background(@current_user)
176176

177177
expose statistics, backward_compatible_includes
178178
end

app/models/quizzes/quiz_statistics.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def report
6464
end
6565

6666
# Generates or returns the previously generated CSV version of this report.
67-
def generate_csv
67+
def generate_csv(user = nil)
6868
self.csv_attachment ||= begin
6969
attachment = build_csv_attachment(
7070
content_type: "text/csv",
@@ -75,15 +75,16 @@ def generate_csv
7575
report_type: readable_type
7676
}) + ".csv"
7777
)
78-
Attachments::Storage.store_for_attachment(attachment, StringIO.new(report.to_csv))
78+
csv_options = user ? CSVWithI18n.csv_i18n_settings(user) : {}
79+
Attachments::Storage.store_for_attachment(attachment, StringIO.new(report.to_csv(csv_options)))
7980
attachment.save!
8081
attachment
8182
end
8283
end
8384

8485
# Queues a job for generating the CSV version of this report unless a job has
8586
# already been queued, or the attachment had been generated previously.
86-
def generate_csv_in_background
87+
def generate_csv_in_background(user = nil)
8788
return if csv_attachment.present? || progress.present?
8889

8990
build_progress
@@ -95,11 +96,11 @@ def generate_csv_in_background
9596

9697
progress.process_job(self, :__process_csv_job, {
9798
strand: csv_job_strand_id
98-
})
99+
}, user)
99100
end
100101

101-
def __process_csv_job(_progress)
102-
generate_csv
102+
def __process_csv_job(_progress, user = nil)
103+
generate_csv(user)
103104
end
104105

105106
# Whether the CSV attachment is currently being generated, or is about to be.

app/models/quizzes/quiz_statistics/item_analysis.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ def generate(_legacy = true, options = {})
6868
end
6969
end
7070

71-
def to_csv
71+
def to_csv(csv_options = {})
7272
@csv ||=
73-
CSV.generate do |csv|
73+
CSVWithI18n.generate(**csv_options) do |csv|
7474
stats = summary_stats_for_quiz
7575
headers = [
7676
I18n.t("csv.question.id", "Question Id"),

app/models/quizzes/quiz_statistics/student_analysis.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ def attachment_csv(answer)
183183
end
184184
end
185185

186-
def to_csv
186+
def to_csv(csv_options = {})
187187
include_root_accounts = quiz.context.root_account.trust_exists?
188-
CSV.generate do |csv|
188+
CSVWithI18n.generate(**csv_options) do |csv|
189189
context = quiz.context
190190

191191
# write columns to csv

0 commit comments

Comments
 (0)