示例#1
0
    def create_page(self, wiki_page, **kwargs):
        """
        Create a new wiki page.

        :calls: `POST /api/v1/groups/:group_id/pages \
        <https://canvas.instructure.com/doc/api/pages.html#method.wiki_pages_api.create>`_

        :param wiki_page: Details about the page to create.
        :type wiki_page: dict
        :returns: The created page.
        :rtype: :class:`canvasapi.page.Page`
        """
        from canvasapi.course import Page

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

        response = self._requester.request(
            'POST',
            'groups/{}/pages'.format(self.id),
            _kwargs=combine_kwargs(**kwargs)
        )

        page_json = response.json()
        page_json.update({'group_id': self.id})

        return Page(self._requester, page_json)
示例#2
0
    def __update_wiki_page_body(self, wiki_page, **kwargs):
        # def create_page(self, wiki_page, **kwargs):
        """
        update a wiki page.
        :calls: `POST /api/v1/courses/:course_id/pages \
        <https://canvas.instructure.com/doc/api/pages.html#method.wiki_pages_api.update>`_
        :param wiki_page: The title for the page.
        :type wiki_page: object, not dict
        :returns: The created page.
        :rtype: :class:`canvasapi.page.Page`
        """

        print(wiki_page.title)
        # if isinstance(wiki_page, dict) and "title" in wiki_page:
        if isinstance(wiki_page, Page) and hasattr(wiki_page, 'title'):
            wiki_page_dict = vars(wiki_page)
            wiki_page_dict["body"] = "<h1>new wiki body</h1>"
            kwargs["wiki_page"] = wiki_page_dict
            print(kwargs)
        else:
            #raise RequiredFieldMissing("Dictionary with key 'title' is required.")
            raise RequiredFieldMissing(
                "Object of type Page with attribute 'title' is required.")

        response = self._requester.request("POST",
                                           "courses/{}/pages".format(
                                               self.COURSE_ID),
                                           _kwargs=combine_kwargs(**kwargs))

        page_json = response.json()
        page_json.update({"course_id": self.COURSE_ID})

        return Page(self._requester, page_json)
示例#3
0
    def show_front_page(self):
        """
        Retrieve the content of the front page.

        :calls: `GET /api/v1/groups/:group_id/front_page \
        <https://canvas.instructure.com/doc/api/pages.html#method.wiki_pages_api.show_front_page>`_

        :rtype: :class:`canvasapi.group.Group`
        """
        from canvasapi.course import Page

        response = self._requester.request(
            'GET', 'groups/{}/front_page'.format(self.id))
        page_json = response.json()
        page_json.update({'group_id': self.id})

        return Page(self._requester, page_json)
示例#4
0
    def edit_front_page(self, **kwargs):
        """
        Update the title or contents of the front page.

        :calls: `PUT /api/v1/groups/:group_id/front_page \
        <https://canvas.instructure.com/doc/api/pages.html#method.wiki_pages_api.update_front_page>`_

        :rtype: :class:`canvasapi.page.Page`
        """
        from canvasapi.course import Page

        response = self._requester.request('PUT',
                                           'groups/%s/front_page' % (self.id),
                                           _kwargs=combine_kwargs(**kwargs))
        page_json = response.json()
        page_json.update({'group_id': self.id})

        return Page(self._requester, page_json)
示例#5
0
    def get_page(self, url):
        """
        Retrieve the contents of a wiki page.

        :calls: `GET /api/v1/groups/:group_id/pages/:url \
        <https://canvas.instructure.com/doc/api/pages.html#method.wiki_pages_api.show>`_

        :param url: The url for the page.
        :type url: str
        :returns: The specified page.
        :rtype: :class:`canvasapi.groups.Group`
        """
        from canvasapi.course import Page

        response = self._requester.request(
            'GET', 'groups/{}/pages/{}'.format(self.id, url))
        page_json = response.json()
        page_json.update({'group_id': self.id})

        return Page(self._requester, page_json)