def get_grading_standard_for_course(self, course_id, grading_standard_id): """ Get a single grading standard in course context. https://canvas.instructure.com/doc/api/grading_standards.html#method.grading_standards_api.context_show """ url = COURSES_API.format(course_id) + "/grading_standards/{}".format( grading_standard_id) return GradingStandard(data=self._get_resource(url))
def get_users_for_course(self, course_id, params={}): """ Returns a list of users for the given course id. """ url = COURSES_API.format(course_id) + "/users" data = self._get_paged_resource(url, params=params) users = [] for datum in data: users.append(CanvasUser(data=datum)) return users
def get_grading_standards_for_course(self, course_id): """ List the grading standards available to a course https://canvas.instructure.com/doc/api/grading_standards.html#method.grading_standards_api.context_index """ url = COURSES_API.format(course_id) + "/grading_standards" standards = [] for data in self._get_paged_resource(url): standards.append(GradingStandard(data=data)) return standards
def get_external_tools_in_course(self, course_id, params={}): """ Return external tools for the passed canvas course id. https://canvas.instructure.com/doc/api/external_tools.html#method.external_tools.index """ url = COURSES_API.format(course_id) + "/external_tools" external_tools = [] for data in self._get_paged_resource(url, params=params): external_tools.append(data) return external_tools
def get_sections_in_course(self, course_id, params={}): """ Return list of sections for the passed course ID. https://canvas.instructure.com/doc/api/sections.html#method.sections.index """ url = COURSES_API.format(course_id) + "/sections" sections = [] for data in self._get_paged_resource(url, params=params): sections.append(CanvasSection(data=data)) return sections
def get_enrollments_for_course(self, course_id, params={}): """ Return a list of all enrollments for the passed course_id. https://canvas.instructure.com/doc/api/enrollments.html#method.enrollments_api.index """ url = COURSES_API.format(course_id) + "/enrollments" enrollments = [] for datum in self._get_paged_resource(url, params=params): enrollments.append(CanvasEnrollment(data=datum)) return enrollments
def get_submissions_by_course_and_assignment(self, course_id, assignment_id, params={}): """ https://canvas.instructure.com/doc/api/submissions.html#method.submissions_api.index """ url = COURSES_API.format(course_id) url += "/assignments/{}/submissions".format(assignment_id) submissions = [] for data in self._get_paged_resource(url, params=params): submissions.append(Submission(data=data)) return submissions
def create_section(self, course_id, name, sis_section_id): """ Create a canvas section in the given course id. https://canvas.instructure.com/doc/api/sections.html#method.sections.create """ url = COURSES_API.format(course_id) + "/sections" body = { "course_section": { "name": name, "sis_section_id": sis_section_id } } return CanvasSection(data=self._post_resource(url, body))
def create_grading_standard_for_course(self, course_id, name, grading_scheme, creator): """ Create a new grading standard for the passed course. https://canvas.instructure.com/doc/api/grading_standards.html#method.grading_standards_api.create """ url = COURSES_API.format(course_id) + "/grading_standards" body = { "title": name, "grading_scheme_entry": grading_scheme, "as_user_id": creator } return GradingStandard(data=self._post_resource(url, body))
def enroll_user(self, course_id, user_id, enrollment_type, params=None): """ Enroll a user into a course. https://canvas.instructure.com/doc/api/enrollments.html#method.enrollments_api.create """ url = COURSES_API.format(course_id) + "/enrollments" if not params: params = {} params["user_id"] = user_id params["type"] = enrollment_type data = self._post_resource(url, {"enrollment": params}) return CanvasEnrollment(data=data)