forked from ucfopen/canvasapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue/525 eportfolio endpoint (ucfopen#536)
* Create new classes, add user methods Create the `EPortfolio` and `EPortfolioPage` classes to match Canvas docs. Add relevant ePortfolio methods to `User` class. * Remove ID arg from all methods The module is to work with single eportfolios already retrieved through the `Canvas` object. The IDs were redundant and were removed. * EPortfolio module tests Added fixutres for `EPortfolio` module. All tests passing. * Add `get_eportfolio` method The ePortfolio endpoint isn't linked to a specific course, so adding it to the Canvas module made sense. There is another route for users to retrieve their own ePortfolios in a `PaginatedList`. Test added and passing. * fix accidental formatting of json file * Add string method tests All tests passing. * fix flake8, isort errors * fix isort error * Docstring fixes. Add eportfolio ref * reformat eport json * Fix markdown typo Co-authored-by: Matthew Emond <[email protected]>
- Loading branch information
1 parent
6e2af8b
commit 340879f
Showing
12 changed files
with
420 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
from canvasapi.canvas_object import CanvasObject | ||
from canvasapi.paginated_list import PaginatedList | ||
from canvasapi.util import combine_kwargs | ||
|
||
|
||
class EPortfolio(CanvasObject): | ||
def __str__(self): | ||
return "{}".format(self.name) | ||
|
||
def delete(self, **kwargs): | ||
""" | ||
Delete an ePortfolio. | ||
:calls: `DELETE /api/v1/eportfolios/:id \ | ||
<https://canvas.instructure.com/doc/api/e_portfolios.html#method.eportfolios_api.delete>`_ | ||
:returns: ePortfolio with deleted date set. | ||
:rtype: :class:`canvasapi.eportfolio.EPortfolio` | ||
""" | ||
response = self._requester.request( | ||
"DELETE", "eportfolios/{}".format(self.id), _kwargs=combine_kwargs(**kwargs) | ||
) | ||
return EPortfolio(self._requester, response.json()) | ||
|
||
def get_eportfolio_pages(self, **kwargs): | ||
""" | ||
Return a list of pages for an ePortfolio. | ||
:calls: `GET /api/v1/eportfolios/:eportfolio_id/pages \ | ||
<https://canvas.instructure.com/doc/api/e_portfolios.html#method.eportfolios_api.pages>`_ | ||
:returns: List of ePortfolio pages. | ||
:rtype: :class:`canvasapi.paginated_list.PaginatedList` of | ||
:class:`canvasapi.eportfolio.EPortfolioPage` | ||
""" | ||
|
||
return PaginatedList( | ||
EPortfolioPage, | ||
self._requester, | ||
"GET", | ||
"eportfolios/{}/pages".format(self.id), | ||
_kwargs=combine_kwargs(**kwargs), | ||
) | ||
|
||
def moderate_eportfolio(self, **kwargs): | ||
""" | ||
Update the spam_status of an eportfolio. | ||
Only available to admins who can `moderate_user_content`. | ||
:calls: `PUT /api/v1/eportfolios/:eportfolio_id/moderate \ | ||
<https://canvas.instructure.com/doc/api/e_portfolios.html#method.eportfolios_api.moderate>`_ | ||
:returns: Updated ePortfolio. | ||
:rtype: :class:`canvasapi.eportfolio.EPortfolio` | ||
""" | ||
response = self._requester.request( | ||
"PUT", | ||
"eportfolios/{}/moderate".format(self.id), | ||
_kwargs=combine_kwargs(**kwargs), | ||
) | ||
|
||
return EPortfolio(self._requester, response.json()) | ||
|
||
def restore(self, **kwargs): | ||
""" | ||
Restore an ePortfolio back to active that was previously deleted. | ||
Only available to admins who can moderate_user_content. | ||
:calls: `PUT /api/v1/eportfolios/:eportfolio_id/restore \ | ||
<https://canvas.instructure.com/doc/api/e_portfolios.html#method.eportfolios_api.restore>`_ | ||
:returns: Updated ePortfolio. | ||
:rtype: :class:`canvasapi.eportfolio.EPortfolio` | ||
""" | ||
response = self._requester.request( | ||
"PUT", | ||
"eportfolios/{}/restore".format(self.id), | ||
_kwargs=combine_kwargs(**kwargs), | ||
) | ||
|
||
return EPortfolio(self._requester, response.json()) | ||
|
||
|
||
class EPortfolioPage(CanvasObject): | ||
def __str__(self): | ||
return "{}. {}".format(self.position, self.name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
========== | ||
EPortfolio | ||
========== | ||
|
||
.. autoclass:: canvasapi.eportfolio.EPortfolio | ||
:members: | ||
|
||
============== | ||
EPortfolioPage | ||
============== | ||
|
||
.. autoclass:: canvasapi.eportfolio.EPortfolioPage | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{ | ||
"delete_eportfolio": { | ||
"method": "DELETE", | ||
"endpoint": "eportfolios/1", | ||
"data": { | ||
"id": 1, | ||
"name": "ePortfolio 1", | ||
"workflow_state": "deleted", | ||
"description": "Delete this ePortfolio", | ||
"deleted_at": "2022-07-05T21:00:00Z" | ||
}, | ||
"status_code": 200 | ||
}, | ||
"get_eportfolio_by_id": { | ||
"method": "GET", | ||
"endpoint": "eportfolios/1", | ||
"data": { | ||
"id": 1, | ||
"user_id": 1, | ||
"workflow_state": "active", | ||
"name": "ePortfolio 1", | ||
"deleted_at": "null", | ||
"spam_status": "null" | ||
}, | ||
"status_code": 200 | ||
}, | ||
"get_eportfolio_pages": { | ||
"method": "GET", | ||
"endpoint": "eportfolios/1/pages", | ||
"data": [ | ||
{ | ||
"id": 1, | ||
"eportfolio_id": 1, | ||
"position": 1, | ||
"name": "ePortfolio 1", | ||
"content": "This is the page of content", | ||
"created_at": "2022-07-01T18:00:00Z", | ||
"updated_at": "2021-07-04T18:00:00Z" | ||
}, | ||
{ | ||
"id": 2, | ||
"eportfolio_id": 1, | ||
"position": 2, | ||
"name": "ePortfolio 1", | ||
"content": "This is the second page of content", | ||
"created_at": "2022-07-02T18:00:00Z", | ||
"updated_at": "2021-07-02T18:00:00Z" | ||
} | ||
], | ||
"status_code": 200 | ||
}, | ||
"moderate_eportfolio_as_spam": { | ||
"method": "PUT", | ||
"endpoint": "eportfolios/1/moderate", | ||
"data": { | ||
"id": 1, | ||
"user_id": 1, | ||
"workflow_state": "active", | ||
"name": "ePortfolio 1", | ||
"deleted_at": "null", | ||
"spam_status": "marked_as_spam" | ||
} | ||
}, | ||
"restore_deleted_eportfolio": { | ||
"method": "PUT", | ||
"endpoint": "eportfolios/1/restore", | ||
"data": { | ||
"id": 1, | ||
"user_id": 1, | ||
"workflow_state": "active", | ||
"name": "ePortfolio 1", | ||
"deleted_at": "null" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.