canvasapi icon indicating copy to clipboard operation
canvasapi copied to clipboard

Documentation Examples

Open Thetwam opened this issue 6 years ago • 11 comments

As a stopgap measure until we complete #9, we should provide code examples for common use cases.

Some important examples:

  • Create a new user
  • Create a new course
  • Enroll user(s) in a course
  • Create/edit an assignment
  • Get all users in a course

There's plenty of other things to add, of course. Add more as needed.

We'll also need to figure out the best way to organize all these examples. For now, a single page in the docs should suffice.

Thetwam avatar Feb 05 '18 19:02 Thetwam

@jessemcbride (and anybody else who is interested), could you take a look at my branch and see if this seems like a good pattern to continue with?

Thetwam avatar Feb 07 '18 16:02 Thetwam

@jessemcbride things to work on:

Accounts:

  • [x] Creating a new user
  • [x] List all courses

Users

  • [x] Getting a user by SIS ID
  • [x] Getting a user by their Canvas ID
  • [x] Edit a user
  • [x] Get page views

Logins

  • [x] List user logins
  • [ ] Adding a user login
  • [ ] Updating a user login

Thetwam avatar Feb 19 '18 18:02 Thetwam

Work continues on this. Will likely be an ever-evolving issue.

Thetwam avatar Mar 01 '18 15:03 Thetwam

Any examples of how to set grades for assignments? If someone can give me a hint I will make an example I see how the assignment class .set_attributes( {x.grade: X} ) works but not how to POST grades I imagine I need to post / upload the students assignment object with changed attributes

mboldin avatar Mar 20 '18 15:03 mboldin

@mboldin You should be able to grade an assignment via Submission.edit() using the submission[posted_grade] parameter as described in the Canvas docs.

Thetwam avatar Mar 22 '18 16:03 Thetwam

Thanks. The code below works. The trick is you do not use the grade parameter i.e., NOT edit(submission={'grade': new_grade}) And it is easy to iterate over student ids or use .get_submissions() to loop over submissions thanks to other Python code in CANVASAPI

## Pick course, assignment, student, and set new grade
course = canvas.get_course( -- course number --- )
a = course.get_assignment( -- assignment id --)
x = -- student ID  --
new_grade = 10

## Modify assignment grade for one student 
print (a.name, '--', a.created_at[:10], a.due_at[:10], a.updated_at)
s1 = b.get_submission(x)
print(x, s1.id, 'Current grade:', s1.grade)
s1.edit(submission={'posted_grade': new_grade})

##Check result
s2 = b.get_submission(x)
print(x, s2.id, 'Modified:', s2.grade)

mboldin avatar Mar 23 '18 13:03 mboldin

Yeah, per the Canvas Docs, submission[posted_grade] will update both the score and grade attributes.

Also, the object should update in-place, so in your example s1 should already have the modified grade. If not, let us know!

Thetwam avatar Mar 23 '18 14:03 Thetwam

I'd love to help! Is anyone tackling creating and managing assignments? I also found some issues with uploading files.

markuskreitzer avatar Jun 18 '18 23:06 markuskreitzer

Hey @elec3647!

We already have examples for creating and editing assignments. If you have suggestions to improve those examples, or have any other examples to add, please feel free to submit a pull request!

Thanks 😄

Thetwam avatar Jun 19 '18 19:06 Thetwam

Add examples in the docs for CalendarEvent.edit() (see #239).

jessemcbride avatar Jun 17 '19 17:06 jessemcbride