Skip to content

Commit 3d4c899

Browse files
committed
Added submission.list_view_history(), v0.2.28, thx @josephlou5!
1 parent edcb4c6 commit 3d4c899

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

codepost/models/submissions.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88

99
# Python stdlib imports
1010
import typing as _typing
11+
try:
12+
# Python 3
13+
from urllib.parse import urljoin as _urljoin
14+
from urllib.parse import urlencode as _urlencode
15+
except ImportError: # pragma: no cover
16+
# Python 2
17+
from urlparse import urljoin as _urljoin
18+
from urllib import urlencode as _urlencode
1119

1220
# External dependencies
1321
import six as _six
@@ -58,4 +66,36 @@ class Submissions(
5866
_FIELDS_READ_ONLY = [ "dateEdited", "grade", "files", 'tests' ]
5967
_FIELDS_REQUIRED = [ "assignment", "students" ]
6068

69+
def list_view_history(self, id=None, return_all=False):
70+
"""
71+
Returns the list of view histories associated with the submission.
72+
"""
73+
_class_type = type(self)
74+
75+
id = self._get_id(id=id)
76+
77+
endpoint = "/submissions/{}/history".format(id)
78+
endpoint_params = {}
79+
80+
if len(endpoint_params) > 0:
81+
endpoint += "?{}".format(_urlencode(endpoint_params))
82+
83+
ret = self._requestor._request(
84+
endpoint=endpoint,
85+
method="GET",
86+
)
87+
if ret.status_code == 200:
88+
# Returns a list of all submission histories
89+
lst = ret.json
90+
91+
# This list tends to only contain one history (bug!)
92+
if return_all:
93+
return lst
94+
95+
if len(lst) > 0:
96+
# FIXME: sort to guarantee most recent view
97+
return lst[0]
98+
99+
return dict()
100+
61101
# =============================================================================

codepost/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Version number
2-
__version__ = "0.2.27"
2+
__version__ = "0.2.28"

0 commit comments

Comments
 (0)