Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quiz report should use user's preference of CSV #2369

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,7 @@ def report
end

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