Files
edx-platform/lms/djangoapps/instructor_task/tasks_helper/utils.py
Kshitij Sobti 559ff54a06 Add UI to display report creation progress.
Adds an in-line status display for problem report generation progress.

Co-authored-by: Adam Kovari <adam@opencraft.com>
Co-authored-by: Eugeny Kolpakov <eugeny.kolpakov@gmail.com>
Co-authored-by: Kshitij Sobti <kshitij@sobti.in>
Co-authored-by: Braden MacDonald <braden@opencraft.com>
2020-08-12 19:05:31 +05:30

57 lines
1.7 KiB
Python

"""
Utility methods for instructor tasks
"""
from eventtracking import tracker
from lms.djangoapps.instructor_task.models import ReportStore
from util.file import course_filename_prefix_generator
REPORT_REQUESTED_EVENT_NAME = u'edx.instructor.report.requested'
# define value to use when no task_id is provided:
UNKNOWN_TASK_ID = 'unknown-task_id'
# define values for update functions to use to return status to perform_module_state_update
UPDATE_STATUS_SUCCEEDED = 'succeeded'
UPDATE_STATUS_FAILED = 'failed'
UPDATE_STATUS_SKIPPED = 'skipped'
def upload_csv_to_report_store(rows, csv_name, course_id, timestamp, config_name='GRADES_DOWNLOAD'):
"""
Upload data as a CSV using ReportStore.
Arguments:
rows: CSV data in the following format (first column may be a
header):
[
[row1_colum1, row1_colum2, ...],
...
]
csv_name: Name of the resulting CSV
course_id: ID of the course
Returns:
report_name: string - Name of the generated report
"""
report_store = ReportStore.from_config(config_name)
report_name = u"{course_prefix}_{csv_name}_{timestamp_str}.csv".format(
course_prefix=course_filename_prefix_generator(course_id),
csv_name=csv_name,
timestamp_str=timestamp.strftime("%Y-%m-%d-%H%M")
)
report_store.store_rows(course_id, report_name, rows)
report_path = report_store.storage.url(report_store.path_to(course_id, report_name))
tracker_emit(csv_name)
return report_name, report_path
def tracker_emit(report_name):
"""
Emits a 'report.requested' event for the given report.
"""
tracker.emit(REPORT_REQUESTED_EVENT_NAME, {"report_type": report_name, })