Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #55 Lists in kwargs #63

Merged
merged 10 commits into from
Aug 30, 2017

Conversation

Thetwam
Copy link
Member

@Thetwam Thetwam commented Aug 29, 2017

Adds official support for lists in kwargs. Resolves #55.

Simple lists

When a parameter that contains an empty pair of square brackets ([]) needs to be passed, the arguments can be sent as a list.

For example, to get pass following parameter to the list_calendar_events method:

context_codes[]=course_123456

Just pass context_codes as a list:

context = ['course_123456']
canvas.list_calendar_events(context_codes=context)

This allows multiple values to be passed easily at once:

context = ['course_123456', 'user_123']
canvas.list_calendar_events(context_codes=context)

Which would pass this to Canvas:

context_codes[]=course_123456
context_codes[]=user_123

Nested Lists and Dicts

We have had support for nested dictionaries for a while, but that treatment now applies to lists. Lists and dicts can be mixed without any issues.

For example, to pass these arguments to the method to create a new grading standard:1

grading_scheme_entry[][name]=pass
grading_scheme_entry[][value]=50
grading_scheme_entry[][name]=fail
grading_scheme_entry[][value]=0

Just do this!

g_scheme = [
    {
        'name': 'pass',
        'value': 50
    },
    {
        'name': 'fail',
        'value': 0
    }
]
course.create_grading_scheme(title='Title', grading_scheme_entry=g_scheme)

1 Note, this method is not yet implemented but the code in this PR allows it to be created with relative ease.

…eps all the kwargs in the list of 2-tuple format. Updated requester to take in any additional kwargs and format them the same way.
…on exact positioning. In all versions of Python prior to 3.6, kwargs have no order so we can't rely on position. This is fine for the existing tests, but future tests with lists will need to check relative order.
…come in any order, but the elements of the first dict must come before any of the elements of the second dict
…s. Renamed recursive function to flatten_kwarg. Added break to files handler to slightly boost performance.
@Thetwam Thetwam added this to the CanvasAPI v0.7.0 milestone Aug 29, 2017
@Thetwam Thetwam self-assigned this Aug 29, 2017
@coveralls
Copy link

coveralls commented Aug 29, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling ffc8905 on Thetwam:issue/55-lists-in-kwargs into 097ee32 on ucfopen:develop.

@coveralls
Copy link

coveralls commented Aug 30, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling 3dfdc27 on Thetwam:issue/55-lists-in-kwargs into 5f0c579 on ucfopen:develop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants