|
| 1 | +# Copyright 2024 UW-IT, University of Washington |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | + |
| 5 | +from django.core.management.base import BaseCommand |
| 6 | +from django.conf import settings |
| 7 | +from sis_provisioner.dao.canvas import ( |
| 8 | + get_course_report_data, DataFailureException) |
| 9 | +from uw_canvas.collaborations import Collaborations |
| 10 | +from logging import getLogger |
| 11 | +import csv |
| 12 | + |
| 13 | +logger = getLogger(__name__) |
| 14 | + |
| 15 | + |
| 16 | +class Command(BaseCommand): |
| 17 | + help = ('Create a report of all course collaborations') |
| 18 | + |
| 19 | + def handle(self, *args, **options): |
| 20 | + client = Collaborations() |
| 21 | + |
| 22 | + outpath = 'course-collaborations.csv' |
| 23 | + outfile = open(outpath, 'w') |
| 24 | + csv.register_dialect('unix_newline', lineterminator='\n') |
| 25 | + writer = csv.writer(outfile, dialect='unix_newline') |
| 26 | + writer.writerow([ |
| 27 | + 'course_id', 'course_sis_id', 'collaboration_id', |
| 28 | + 'collaboration_type', 'document_id', 'url', 'title']) |
| 29 | + |
| 30 | + report_data = get_course_report_data() |
| 31 | + header = report_data.pop(0) |
| 32 | + for row in csv.reader(report_data): |
| 33 | + if not len(row): |
| 34 | + continue |
| 35 | + |
| 36 | + canvas_id = row[0] |
| 37 | + course_sis_id = row[1] |
| 38 | + try: |
| 39 | + for col in client.get_collaborations_for_course(canvas_id): |
| 40 | + writer.writerow([ |
| 41 | + canvas_id, course_sis_id, col.collaboration_id, |
| 42 | + col.collaboration_type, col.document_id, col.url, |
| 43 | + col.title]) |
| 44 | + except DataFailureException as ex: |
| 45 | + logger.info(f'ERROR fetching collaborations, {ex}') |
| 46 | + continue |
| 47 | + |
| 48 | + outfile.close() |
0 commit comments