ucfopen / canvasapi

Python API wrapper for Instructure's Canvas LMS. Easily manage courses, users, gradebooks, and more.
https://pypi.python.org/pypi/canvasapi
MIT License
554 stars 173 forks source link

Add support for parameters to Submission.edit when using Submission.upload_file #554

Open madsobitsoe opened 2 years ago

madsobitsoe commented 2 years ago

When using canvasapi.submission.Submission.upload_file, the file is first uploaded, then attached to a comment with canvasapi.submission.Submission.edit.

Is it possible to extend upload_file such that it accepts an optional **kwargs, that can be passed to edit in case the upload succeeded?

This would allow for uploading a file setting the text_comment parameter for uploaded files, as well as setting the group_comment parameter when uploading files as comments on a submission as a grader.

bennettscience commented 1 year ago

I see the potential value, but the rest of the library only accepts **kwargs on routes that also accept arguments. The file upload flow doesn't accept any parameters, so adding that seems like it would be stepping outside the patterns used everywhere else.

When a file is uploaded successfully, it returns the attachment data that has to be posted to the submission endpoint anyways. The comment goes on the submission, not on the file.

madsobitsoe commented 1 year ago

I might be misreading/misunderstanding the code, but bear with me. In this line of Submission.upload_comment: https://github.com/ucfopen/canvasapi/blob/285982043e714a90176a580a11dc0a40b0b1e382/canvasapi/submission.py#L180 Submission.edit is called.

If I understand it correctly, this will create a new comment on the submission, with the attached file.

Can/Should I then use the returned response-object to obtain a reference to the posted submission comment, so I can edit the parameters of the comment after it has been posted? (for example for setting the [group_comment] parameter on the comment, when uploading files as feedback when grading).