Skip to content

Commit

Permalink
Quiz report should use user's preference of CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
Gao-Jun committed Jun 15, 2024
1 parent 51ab2c9 commit 45653c5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/controllers/quizzes/quiz_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def create
end

statistics.abort_csv_generation if statistics.csv_generation_failed?
statistics.generate_csv_in_background
statistics.generate_csv_in_background(@current_user)

expose statistics, backward_compatible_includes
end
Expand Down
13 changes: 7 additions & 6 deletions app/models/quizzes/quiz_statistics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def report
end

# Generates or returns the previously generated CSV version of this report.
def generate_csv
def generate_csv(user = nil)
csv_options = user ? CSVWithI18n.csv_i18n_settings(user) : {}
self.csv_attachment ||= begin
attachment = build_csv_attachment(
content_type: "text/csv",
Expand All @@ -75,15 +76,15 @@ def generate_csv
report_type: readable_type
}) + ".csv"
)
Attachments::Storage.store_for_attachment(attachment, StringIO.new(report.to_csv))
Attachments::Storage.store_for_attachment(attachment, StringIO.new(report.to_csv(csv_options)))
attachment.save!
attachment
end
end

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

build_progress
Expand All @@ -95,11 +96,11 @@ def generate_csv_in_background

progress.process_job(self, :__process_csv_job, {
strand: csv_job_strand_id
})
}, user)
end

def __process_csv_job(_progress)
generate_csv
def __process_csv_job(_progress, user = nil)
generate_csv(user)
end

# Whether the CSV attachment is currently being generated, or is about to be.
Expand Down
4 changes: 2 additions & 2 deletions app/models/quizzes/quiz_statistics/item_analysis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ def generate(_legacy = true, options = {})
end
end

def to_csv
def to_csv(csv_options = {})
@csv ||=
CSV.generate do |csv|
CSVWithI18n.generate(**csv_options) do |csv|
stats = summary_stats_for_quiz
headers = [
I18n.t("csv.question.id", "Question Id"),
Expand Down
4 changes: 2 additions & 2 deletions app/models/quizzes/quiz_statistics/student_analysis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ def attachment_csv(answer)
end
end

def to_csv
def to_csv(csv_options = {})
include_root_accounts = quiz.context.root_account.trust_exists?
CSV.generate do |csv|
CSVWithI18n.generate(**csv_options) do |csv|
context = quiz.context

# write columns to csv
Expand Down

0 comments on commit 45653c5

Please sign in to comment.