コード例 #1
0
ファイル: course.py プロジェクト: allygator/canvasapi
    def update_submission(self, assignment_id, user_id, **kwargs):
        """
        Comment on and/or update the grading for a student's assignment submission.

        :calls: `PUT /api/v1/courses/:course_id/assignments/:assignment_id/submissions/:user_id \
        <https://canvas.instructure.com/doc/api/submissions.html#method.submissions_api.update>`_

        :param assignment_id: The ID of the assignment.
        :type assignment_id: int
        :param user_id: The ID of the user.
        :type user_id: str
        :rtype: :class:`canvasapi.submission.Submission`
        """
        response = self._requester.request(
            'PUT',
            'courses/%s/assignments/%s/submissions/%s' % (self.id, assignment_id, user_id),
            **combine_kwargs(**kwargs)
        )

        submission = self.get_submission(assignment_id, user_id)

        if 'submission_type' in response.json():
            super(Submission, submission).set_attributes(response.json())

        return Submission(self._requester, response.json())
コード例 #2
0
ファイル: course.py プロジェクト: allygator/canvasapi
    def submit_assignment(self, assignment_id, submission, **kwargs):
        """
        Makes a submission for an assignment.

        :calls: `POST /api/v1/courses/:course_id/assignments/:assignment_id/submissions \
        <https://canvas.instructure.com/doc/api/submissions.html#method.submissions.create>`_

        :param submission: The attributes of the submission.
        :type submission: `dict`
        :rtype: :class:`canvasapi.submission.Submission`
        """
        if isinstance(submission, dict) and 'submission_type' in submission:
            kwargs['submision'] = submission
        else:
            raise RequiredFieldMissing(
                "Dictionary with key 'submission_type' is required."
            )

        response = self._requester.request(
            'POST',
            'courses/%s/assignments/%s/submissions' % (self.id, assignment_id),
            **combine_kwargs(**kwargs)
        )

        return Submission(self._requester, response.json())
コード例 #3
0
    def get_submission(self, user, **kwargs):
        """
        Get a single submission, based on user id.

        :calls: `GET /api/v1/courses/:course_id/assignments/:assignment_id/submissions/:user_id \
        <https://canvas.instructure.com/doc/api/submissions.html#method.submissions_api.show>`_

        :param user: The object or ID of the related user
        :type user: :class:`canvasapi.user.User` or int

        :rtype: :class:`canvasapi.submission.Submission`
        """
        user_id = obj_or_id(user, "user", (User,))

        response = self._requester.request(
            "GET",
            "courses/{}/assignments/{}/submissions/{}".format(
                self.course_id, self.id, user_id
            ),
            _kwargs=combine_kwargs(**kwargs),
        )
        response_json = response.json()
        response_json.update(course_id=self.course_id)

        return Submission(self._requester, response_json)
コード例 #4
0
ファイル: section.py プロジェクト: tuanvpham/canvasapi
    def submit_assignment(self, assignment, submission, **kwargs):
        """
        Makes a submission for an assignment.

        :calls: `POST /api/v1/sections/:section_id/assignments/:assignment_id/submissions \
        <https://canvas.instructure.com/doc/api/submissions.html#method.submissions.create>`_

        :param assignment: The object or ID of the assignment.
        :type assignment: :class:`canvasapi.assignment.Assignment` or int
        :param submission: The attributes of the submission.
        :type submission: dict

        :rtype: :class:`canvasapi.submission.Submission`
        """
        from canvasapi.assignment import Assignment

        assignment_id = obj_or_id(assignment, "assignment", (Assignment, ))

        if isinstance(submission, dict) and 'submission_type' in submission:
            kwargs['submision'] = submission
        else:
            raise RequiredFieldMissing(
                "Dictionary with key 'submission_type' is required.")

        response = self._requester.request(
            'POST',
            'sections/{}/assignments/{}/submissions'.format(
                self.id, assignment_id),
            _kwargs=combine_kwargs(**kwargs))
        response_json = response.json()
        response_json.update(section_id=self.id)

        return Submission(self._requester, response_json)
コード例 #5
0
ファイル: section.py プロジェクト: tuanvpham/canvasapi
    def update_submission(self, assignment, user, **kwargs):
        """
        Comment on and/or update the grading for a student's assignment submission.

        :calls: `PUT /api/v1/sections/:section_id/assignments/:assignment_id/submissions/:user_id \
        <https://canvas.instructure.com/doc/api/submissions.html#method.submissions_api.update>`_

        :param assignment: The object or ID of the assignment.
        :type assignment: :class:`canvasapi.assignment.Assignment` or int
        :param user: The object or ID of the user.
        :type user: :class:`canvasapi.user.User` or int or str

        :rtype: :class:`canvasapi.submission.Submission`
        """
        from canvasapi.assignment import Assignment
        from canvasapi.user import User

        assignment_id = obj_or_id(assignment, "assignment", (Assignment, ))
        user_id = obj_or_id(user, "user", (User, ))

        response = self._requester.request(
            'PUT',
            'sections/{}/assignments/{}/submissions/{}'.format(
                self.id, assignment_id, user_id),
            _kwargs=combine_kwargs(**kwargs))

        submission = self.get_submission(assignment_id, user_id)

        response_json = response.json()
        response_json.update(section_id=self.id)

        if 'submission_type' in response_json:
            super(Submission, submission).set_attributes(response_json)

        return Submission(self._requester, response_json)
コード例 #6
0
ファイル: section.py プロジェクト: tuanvpham/canvasapi
    def get_submission(self, assignment, user, **kwargs):
        """
        Get a single submission, based on user id.

        :calls: `GET /api/v1/sections/:section_id/assignments/:assignment_id/submissions/:user_id \
        <https://canvas.instructure.com/doc/api/submissions.html#method.submissions_api.show>`_

        :param assignment: The object or ID of the assignment.
        :type assignment: :class:`canvasapi.assignment.Assignment` or int
        :param user: The object or ID of the user.
        :type user: :class:`canvasapi.user.User` or int or str

        :rtype: :class:`canvasapi.submission.Submission`
        """
        from canvasapi.assignment import Assignment
        from canvasapi.user import User

        assignment_id = obj_or_id(assignment, "assignment", (Assignment, ))
        user_id = obj_or_id(user, "user", (User, ))

        response = self._requester.request(
            'GET',
            'sections/{}/assignments/{}/submissions/{}'.format(
                self.id, assignment_id, user_id),
            _kwargs=combine_kwargs(**kwargs))
        response_json = response.json()
        response_json.update(section_id=self.id)

        return Submission(self._requester, response_json)
コード例 #7
0
    def update_submission(self, assignment, user, **kwargs):
        """
        Comment on and/or update the grading for a student's assignment submission.

        .. warning::
            .. deprecated:: 0.9.0
                Use :func:`canvasapi.submission.Submission.edit` instead.

        :calls: `PUT /api/v1/sections/:section_id/assignments/:assignment_id/submissions/:user_id \
        <https://canvas.instructure.com/doc/api/submissions.html#method.submissions_api.update>`_

        :param assignment: The object or ID of the assignment.
        :type assignment: :class:`canvasapi.assignment.Assignment` or int
        :param user: The object or ID of the user.
        :type user: :class:`canvasapi.user.User` or int or str

        :rtype: :class:`canvasapi.submission.Submission`
        """
        from canvasapi.assignment import Assignment
        from canvasapi.user import User

        warnings.warn(
            "Section.update_submission() is deprecated and will be removed "
            "in the future. Use Submission.edit() instead.",
            DeprecationWarning,
        )

        assignment_id = obj_or_id(assignment, "assignment", (Assignment,))
        user_id = obj_or_id(user, "user", (User,))

        submission = Submission(
            self._requester,
            {
                "course_id": self.course_id,
                "assignment_id": assignment_id,
                "user_id": user_id,
            },
        )

        return submission.edit(**kwargs)
コード例 #8
0
    def mark_submission_as_unread(self, assignment, user, **kwargs):
        """
        Mark submission as unread. No request fields are necessary.

        .. warning::
            .. deprecated:: 0.9.0
                Use :func:`canvasapi.submission.Submission.mark_unread` instead.

        :calls: `DELETE
            /api/v1/sections/:section_id/assignments/:assignment_id/submissions/:user_id/read \
            <https://canvas.instructure.com/doc/api/submissions.html#method.submissions_api.mark_submission_unread>`_

        :param assignment: The object or ID of the assignment.
        :type assignment: :class:`canvasapi.assignment.Assignment` or int
        :param user: The object or ID of the user.
        :type user: :class:`canvasapi.user.User` or int or str

        :rtype: `bool`
        """
        from canvasapi.assignment import Assignment
        from canvasapi.user import User

        warnings.warn(
            "Section.mark_submission_as_unread() is deprecated and will be "
            "removed in the future. Use Submission.mark_unread() instead.",
            DeprecationWarning,
        )

        assignment_id = obj_or_id(assignment, "assignment", (Assignment,))
        user_id = obj_or_id(user, "user", (User,))

        submission = Submission(
            self._requester,
            {
                "course_id": self.course_id,
                "assignment_id": assignment_id,
                "user_id": user_id,
            },
        )
        return submission.mark_unread(**kwargs)
コード例 #9
0
    def get_submission(self, assignment_id, user_id, **kwargs):
        """
        Get a single submission, based on user id.

        :calls: `GET /api/v1/sections/:section_id/assignments/:assignment_id/submissions/:user_id \
        <https://canvas.instructure.com/doc/api/submissions.html#method.submissions_api.show>`_

        :param assignment_id: The ID of the assignment.
        :type assignment_id: int
        :param user_id: The ID of the user.
        :type user_id: str
        :rtype: :class:`canvasapi.submission.Submission`
        """
        response = self._requester.request(
            'GET', 'sections/%s/assignments/%s/submissions/%s' %
            (self.id, assignment_id, user_id), **combine_kwargs(**kwargs))
        return Submission(self._requester, response.json())
コード例 #10
0
ファイル: assignment.py プロジェクト: varlokkur/canvasapi
    def submit(self, submission, file=None, **kwargs):
        """
        Makes a submission for an assignment.

        :calls: `POST /api/v1/courses/:course_id/assignments/:assignment_id/submissions \
        <https://canvas.instructure.com/doc/api/submissions.html#method.submissions.create>`_

        :param submission: The attributes of the submission.
        :type submission: dict
        :param file: A file to upload with the submission. (Optional,
            defaults to `None`. Submission type must be `online_upload`)
        :type file: file or str

        :rtype: :class:`canvasapi.submission.Submission`
        """
        if isinstance(submission, dict) and "submission_type" in submission:
            kwargs["submission"] = submission
        else:
            raise RequiredFieldMissing(
                "Dictionary with key 'submission_type' is required.")

        if file:
            if submission.get("submission_type") != "online_upload":
                raise ValueError(
                    "To upload a file, `submission['submission_type']` must be `online_upload`."
                )

            upload_response = self.upload_to_submission(file, **kwargs)
            if upload_response[0]:
                kwargs["submission"]["file_ids"] = [upload_response[1]["id"]]
            else:
                raise CanvasException("File upload failed. Not submitting.")

        response = self._requester.request(
            "POST",
            "courses/{}/assignments/{}/submissions".format(
                self.course_id, self.id),
            _kwargs=combine_kwargs(**kwargs),
        )
        response_json = response.json()
        response_json.update(course_id=self.course_id)

        return Submission(self._requester, response_json)
コード例 #11
0
    def get_quiz_submission(self, quiz_submission, **kwargs):
        """
        Get a single quiz submission.

        :calls: `GET /api/v1/courses/:course_id/quizzes/:quiz_id/submissions/:id \
        <https://canvas.instructure.com/doc/api/quiz_submissions.html#method.quizzes/quiz_submissions_api.show>`_

        :param quiz_submission: The object or ID of the quiz submission to retrieve.
        :type quiz_submission: int, string, :class:`canvasapi.quiz.QuizSubmission`

        :rtype: :class:`canvasapi.quiz.QuizSubmission`
        """
        quiz_submission_id = obj_or_id(quiz_submission, "quiz_submission",
                                       (QuizSubmission, ))

        response = self._requester.request(
            "GET",
            "courses/{}/quizzes/{}/submissions/{}".format(
                self.course_id, self.id, quiz_submission_id),
            _kwargs=combine_kwargs(**kwargs),
        )

        response_json = response.json()["quiz_submissions"][0]
        response_json.update({"course_id": self.course_id})
        if len(response.json().get("quizzes", [])) > 0:
            response_json.update(
                {"quiz": Quiz(self._requester,
                              response.json()["quizzes"][0])})
        if len(response.json().get("submissions", [])) > 0:
            response_json.update({
                "submission":
                Submission(self._requester,
                           response.json()["submissions"][0])
            })
        if len(response.json().get("users", [])) > 0:
            response_json.update(
                {"user": User(self._requester,
                              response.json()["users"][0])})

        return QuizSubmission(self._requester, response_json)