Materials API
parent
0e3dcda1ff
commit
05192aa32c
|
@ -241,3 +241,31 @@ class CakeCMS:
|
|||
if value is True: value = 1
|
||||
if value is False: value = 0
|
||||
return self.post('notes_entries/change', {'NotesEntry': {'student_id': student_id, 'note_id': note_id, 'value': value}}, course=course)
|
||||
|
||||
def materials_index(self, course=None):
|
||||
"""
|
||||
Get a list of all accessible material categories and files.
|
||||
Files can be either stored files (to be retrieved with material_download) or links to other sites.
|
||||
:param course:
|
||||
:return:
|
||||
"""
|
||||
return self.get('material_categories/index', course=course).json()
|
||||
|
||||
def material_download(self, id, filename=None, course=None):
|
||||
"""
|
||||
Download a material file. If filename is given, the result is a pair (filename, file-content).
|
||||
If filename is given, the download is written to this file (and the suggested name is returned).
|
||||
:param id:
|
||||
:param filename:
|
||||
:param course:
|
||||
:return:
|
||||
"""
|
||||
if not filename:
|
||||
response = self.get('material_files/download/' + str(id), course=course)
|
||||
return response.headers['Content-Disposition'].split('filename="')[1][:-1], response.content
|
||||
else:
|
||||
response = self.get('material_files/download/' + str(id), course=course, stream=True)
|
||||
with open(filename, 'wb') as fd:
|
||||
for chunk in response.iter_content(chunk_size=4096):
|
||||
fd.write(chunk)
|
||||
return response.headers['Content-Disposition'].split('filename="')[1][:-1]
|
||||
|
|
Loading…
Reference in New Issue