How to use the canvasapi.canvas_object.CanvasObject function in canvasapi

To help you get started, we’ve selected a few canvasapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ucfopen / canvasapi / canvasapi / page_view.py View on Github external
from __future__ import absolute_import, division, print_function, unicode_literals

from six import python_2_unicode_compatible

from canvasapi.canvas_object import CanvasObject


@python_2_unicode_compatible
class PageView(CanvasObject):
    def __str__(self):
        return "{} ({})".format(self.context_type, self.id)
github ucfopen / canvasapi / canvasapi / account.py View on Github external
@python_2_unicode_compatible
class Role(CanvasObject):
    def __str__(self):  # pragma: no cover
        return "{} ({})".format(self.label, self.base_role_type)


@python_2_unicode_compatible
class SSOSettings(CanvasObject):
    def __str__(self):  # pragma: no cover
        return "{} ({})".format(self.login_handle_name, self.change_password_url)


@python_2_unicode_compatible
class Admin(CanvasObject):
    def __str__(self):  # pragma: no cover
        return "{} {} ({})".format(self.user["name"], self.user["id"], self.id)
github ucfopen / canvasapi / canvasapi / account.py View on Github external
from six import python_2_unicode_compatible, string_types

from canvasapi.canvas_object import CanvasObject
from canvasapi.exceptions import CanvasException, RequiredFieldMissing
from canvasapi.feature import Feature, FeatureFlag
from canvasapi.grading_standard import GradingStandard
from canvasapi.grading_period import GradingPeriod
from canvasapi.outcome_import import OutcomeImport
from canvasapi.paginated_list import PaginatedList
from canvasapi.rubric import Rubric
from canvasapi.sis_import import SisImport
from canvasapi.util import combine_kwargs, file_or_path, obj_or_id, obj_or_str


@python_2_unicode_compatible
class Account(CanvasObject):
    def __str__(self):
        return "{} ({})".format(self.name, self.id)

    def abort_sis_imports_pending(self, **kwargs):
        """
        Aborts all pending (created, but not processed or processing)
        SIS imports for the current account.

        :calls: `PUT /api/v1/accounts/:account_id/sis_imports/abort_all_pending \
        `_

        :returns: True if the API responds with aborted=True, False otherwise.
        :rtype: bool
        """
        response = self._requester.request(
            "PUT",
github ucfopen / canvasapi / canvasapi / account.py View on Github external
"account_notification must be a dictionary with keys "
                    "'subject', 'message', 'start_at', and 'end_at'."
                )
            )

        response = self._requester.request(
            "PUT",
            "accounts/{}/account_notifications/{}".format(self.account_id, self.id),
            _kwargs=combine_kwargs(**kwargs),
        )

        return AccountNotification(self._requester, response.json())


@python_2_unicode_compatible
class AccountReport(CanvasObject):
    def __str__(self):
        return "{} ({})".format(self.report, self.id)

    def delete_report(self, **kwargs):
        """
        Delete this report.

        :calls: `DELETE /api/v1/accounts/:account_id/reports/:report/:id \
        `_

        :rtype: :class:`canvasapi.account.AccountReport`
        """
        response = self._requester.request(
            "DELETE",
            "accounts/{}/reports/{}/{}".format(self.account_id, self.report, self.id),
            _kwargs=combine_kwargs(**kwargs),
github ucfopen / canvasapi / canvasapi / course_epub_export.py View on Github external
from __future__ import absolute_import, division, print_function, unicode_literals

from six import python_2_unicode_compatible

from canvasapi.canvas_object import CanvasObject


@python_2_unicode_compatible
class CourseEpubExport(CanvasObject):
    def __str__(self):
        return "{} course_id:({}) epub_id:({}) {} ".format(
            self.name,
            self.id,
            self.epub_export["id"],
            self.epub_export["workflow_state"],
        )
github ucfopen / canvasapi / canvasapi / planner.py View on Github external
from __future__ import absolute_import, division, print_function, unicode_literals

from six import python_2_unicode_compatible

from canvasapi.canvas_object import CanvasObject
from canvasapi.util import combine_kwargs


@python_2_unicode_compatible
class PlannerNote(CanvasObject):

    def __str__(self):
        return "{} {} ({})".format(self.title, self.todo_date, self.id)

    def update(self, **kwargs):
        """
        Update a planner note for the current user

        :calls: `PUT /api/v1/planner_notes/:id \
        `_

        :rtype: :class:`canvasapi.planner.PlannerNote`
        """

        response = self._requester.request(
            'PUT',
github ucfopen / canvasapi / canvasapi / outcome.py View on Github external
:rtype: bool
        """
        response = self._requester.request(
            'PUT',
            'outcomes/{}'.format(self.id),
            _kwargs=combine_kwargs(**kwargs)
        )

        if 'id' in response.json():
            super(Outcome, self).set_attributes(response.json())

        return 'id' in response.json()


@python_2_unicode_compatible
class OutcomeLink(CanvasObject):

    def __str__(self):
        return "Group {} with Outcome {} ({})".format(
            self.outcome_group,
            self.outcome,
            self.url
        )

    def context_ref(self):
        if self.context_type == 'Course':
            return 'courses/{}'.format(self.context_id)
        elif self.context_type == 'Account':
            return 'accounts/{}'.format(self.context_id)

    def get_outcome(self):
        """
github ucfopen / canvasapi / canvasapi / tab.py View on Github external
from __future__ import absolute_import, division, print_function, unicode_literals

from six import python_2_unicode_compatible

from canvasapi.canvas_object import CanvasObject
from canvasapi.util import combine_kwargs


@python_2_unicode_compatible
class Tab(CanvasObject):

    def __str__(self):
        return "{} ({})".format(self.label, self.id)

    def update(self, **kwargs):
        """
        Update a tab for a course.

        Note: Home and Settings tabs are not manageable, and can't be
        hidden or moved.

        :calls: `PUT /api/v1/courses/:course_id/tabs/:tab_id \
        `_

        :rtype: :class:`canvasapi.tab.Tab`
        """
github ucfopen / canvasapi / canvasapi / favorite.py View on Github external
from __future__ import absolute_import, division, print_function, unicode_literals

from six import python_2_unicode_compatible

from canvasapi.canvas_object import CanvasObject
from canvasapi.util import combine_kwargs


@python_2_unicode_compatible
class Favorite(CanvasObject):

    def __str__(self):
        return "{} ({})".format(self.context_type, self.context_id)

    def remove(self, **kwargs):
        """
        Remove a course or group from the current user's favorites.

        :calls: :Course: `DELETE /api/v1/users/self/favorites/courses/:id \
        `_
                :Group: `DELETE /api/v1/users/self/favorites/groups/:id \
        `_

        :rtype: :class:`canvasapi.favorite.Favorite`
        """
        if(self.context_type == "course"):
github ucfopen / canvasapi / canvasapi / discussion_topic.py View on Github external
from __future__ import absolute_import, division, print_function, unicode_literals

import warnings

from six import python_2_unicode_compatible

from canvasapi.canvas_object import CanvasObject
from canvasapi.paginated_list import PaginatedList
from canvasapi.util import combine_kwargs, obj_or_id


@python_2_unicode_compatible
class DiscussionTopic(CanvasObject):
    def __str__(self):
        return "{} ({})".format(self.title, self.id)

    @property
    def _parent_id(self):
        """
        Return the id of the course or group that spawned this discussion topic.

        :rtype: int
        """
        if hasattr(self, 'course_id'):
            return self.course_id
        elif hasattr(self, 'group_id'):
            return self.group_id
        else:
            raise ValueError("Discussion Topic does not have a course_id or group_id")