Exemple #1
0
    def assign_members(self, sync=False):
        """
        Assign unassigned members.

        :calls: `POST /api/v1/group_categories/:group_category_id/assign_unassigned_members \
        <https://canvas.instructure.com/doc/api/group_categories.html#method.group_categories.assign_unassigned_members>`_

        :rtype: :class:`canvasapi.paginated_list.PaginatedList` of :class:`canvasapi.user.User`
            or :class:`canvasapi.progress.Progress`
        """
        from canvasapi.user import User
        from canvasapi.progress import Progress
        if sync:
            return PaginatedList(
                User,
                self._requester,
                'POST',
                'group_categories/{}/assign_unassigned_members'.format(self.id)
            )
        else:
            response = self._requester.request(
                'POST',
                'group_categories/{}/assign_unassigned_members'.format(self.id)
            )
            return Progress(self._requester, response.json())
Exemple #2
0
    def conversations_batch_update(self, conversation_ids, event):
        """

        :calls: `PUT /api/v1/conversations \
        <https://canvas.instructure.com/doc/api/conversations.html#method.conversations.batch_update>`_

        :param conversation_ids: List of conversations to update. Limited to 500 conversations.
        :type conversation_ids: `list` of `str`
        :param event: The action to take on each conversation.
        :type event: `str`
        :rtype: :class:`canvasapi.progress.Progress`
        """

        from canvasapi.progress import Progress

        ALLOWED_EVENTS = [
            'mark_as_read',
            'mark_as_unread',
            'star',
            'unstar',
            'archive',
            'destroy'
        ]

        try:
            if event not in ALLOWED_EVENTS:
                raise ValueError(
                    '{} is not a valid action. Please use one of the following: {}'.format(
                        event,
                        ','.join(ALLOWED_EVENTS)
                    )
                )

            if len(conversation_ids) > 500:
                raise ValueError(
                    'You have requested {} updates, which exceeds the limit of 500'.format(
                        len(conversation_ids)
                    )
                )

            response = self.__requester.request(
                'PUT',
                'conversations',
                event=event,
                **{"conversation_ids[]": conversation_ids}
            )
            return_progress = Progress(self.__requester, response.json())
            return return_progress

        except ValueError as e:
            return e
Exemple #3
0
    def submissions_bulk_update(self, **kwargs):
        """
        Update the grading and comments on multiple student's assignment
        submissions in an asynchronous job.

        :calls: `POST /api/v1/sections/:section_id/submissions/update_grades \
        <https://canvas.instructure.com/doc/api/submissions.html#method.submissions_api.bulk_update>`_

        :rtype: :class:`canvasapi.progress.Progress`
        """
        response = self._requester.request(
            'POST',
            'sections/{}/submissions/update_grades'.format(self.id),
            _kwargs=combine_kwargs(**kwargs))
        return Progress(self._requester, response.json())
Exemple #4
0
    def restore_states(self, **kwargs):
        """
        Restore workflow_states of SIS imported items.

        :calls: `PUT /api/v1/accounts/:account_id/sis_imports/:id/restore_states \
        <https://canvas.instructure.com/doc/api/sis_imports.html#method.sis_imports_api.restore_states>`_

        :rtype: :class:`canvasapi.progress.Progress`
        """
        response = self._requester.request(
            'PUT',
            'accounts/{}/sis_imports/{}/restore_states'.format(
                self.account_id, self.id),
            _kwargs=combine_kwargs(**kwargs))
        return Progress(self._requester, response.json())
Exemple #5
0
    def conversations_batch_update(self, conversation_ids, event, **kwargs):
        """

        :calls: `PUT /api/v1/conversations \
        <https://canvas.instructure.com/doc/api/conversations.html#method.conversations.batch_update>`_

        :param conversation_ids: List of conversations to update. Limited to 500 conversations.
        :type conversation_ids: `list` of `str`
        :param event: The action to take on each conversation.
        :type event: `str`
        :rtype: :class:`canvasapi.progress.Progress`
        """

        from canvasapi.progress import Progress

        ALLOWED_EVENTS = [
            "mark_as_read",
            "mark_as_unread",
            "star",
            "unstar",
            "archive",
            "destroy",
        ]

        if event not in ALLOWED_EVENTS:
            raise ValueError(
                "{} is not a valid action. Please use one of the following: {}".format(
                    event, ",".join(ALLOWED_EVENTS)
                )
            )

        if len(conversation_ids) > 500:
            raise ValueError(
                "You have requested {} updates, which exceeds the limit of 500".format(
                    len(conversation_ids)
                )
            )

        kwargs["conversation_ids"] = conversation_ids
        kwargs["event"] = event

        response = self.__requester.request(
            "PUT",
            "conversations",
            _kwargs=combine_kwargs(**kwargs),
        )
        return_progress = Progress(self.__requester, response.json())
        return return_progress
Exemple #6
0
    def get_progress(self, **kwargs):
        """
        Get the progress of the current content migration.

        :calls: `GET /api/v1/progress/:id
            <https://canvas.instructure.com/doc/api/progress.html#method.progress.show>`_

        :rtype: :class:`canvasapi.progress.Progress`
        """

        from canvasapi.progress import Progress

        progress_id = self.progress_url.split("/")[-1]

        response = self._requester.request(
            "GET", "progress/{}".format(progress_id), _kwargs=combine_kwargs(**kwargs)
        )
        return Progress(self._requester, response.json())
Exemple #7
0
    def get_progress(self, progress, **kwargs):
        """
        Get a specific progress.

        :calls: `GET /api/v1/progress/:id
            <https://canvas.instructure.com/doc/api/progress.html#method.progress.show>`_

        :param progress: The object or ID of the progress to retrieve.
        :type progress: int, str or :class:`canvasapi.progress.Progress`

        :rtype: :class:`canvasapi.progress.Progress`
        """

        from canvasapi.progress import Progress

        progress_id = obj_or_id(progress, "progress", (Progress, ))

        response = self.__requester.request('GET',
                                            'progress/{}'.format(progress_id),
                                            _kwargs=combine_kwargs(**kwargs))
        return Progress(self.__requester, response.json())