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

Parse Nested Objects #56

Open
liblit opened this issue Aug 25, 2017 · 2 comments
Open

Parse Nested Objects #56

liblit opened this issue Aug 25, 2017 · 2 comments

Comments

@liblit
Copy link
Contributor

liblit commented Aug 25, 2017

Original title was "Canvas.get_assignment_group should turn assignments into Assignment instances"

A call to Course.get_assignment_group can optionally include full details about the assignments in the group. That is a nice way to reduce round-trips if we already know that the details will be needed.

In version 0.6.0 of canvasapi, these assignment details are provided as a list of dict.

group = course.get_assignment_group(group.id, include='assignments')
for assignment in group.assignments:
    print(assignment)  # prints each assignment as a dict

I was expecting them to be a list of Assignment instances. Each dict seemingly has all of the details needed to build an Assignment, and I can do that conversion myself:

group = course.get_assignment_group(group.id, include='assignments')
assignments = [Assignment(group._requester, raw) for raw in group.assignments]
for assignment in assignments:
    print(assignment)  # prints each assignment as an Assignment

However, accessing group._requester directly seems like cheating. And I would have expected canvasapi to take care of such details behind the scenes. Can that be done? Can Course.get_assignment_group convert each dict into a proper Assignment for me? (Obviously it should only do so if assignment details are present; without include='assignments', no details are given, so there is nothing to convert.

@liblit
Copy link
Contributor Author

liblit commented Sep 17, 2017

Still using canvasapi 0.6.0, calling Course.get_assignment_group with discussion_topic on the include[] list returns Assignment instances have discussion_topic attributes. The values of these attributes are simple Python dict instances but should be DiscussionTopic instances. So this is essentially the same problem, but in a new context. Should I file a new issue for this new context, or do you want to bundle that in with the issue I originally reported here?

@Thetwam
Copy link
Member

Thetwam commented Sep 18, 2017

I think bundling these issues together makes sense. This is essentially the issue for turning nested objects into actual objects instead of dict. I'll edit the title to reflect this.

@Thetwam Thetwam changed the title Canvas.get_assignment_group should turn assignments into Assignment instances Parse Nested Objects Sep 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants