Skip to content

Conversation

@singingwolfboy
Copy link
Contributor

Tests are passing. @dmitchell @cahrens could you review?

cms/urls.py Outdated
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to understand why there are 3 different methods.

Why isn't the case of "new" handled by doing a PUT (or is it POST?) to textbooks_detail_handler with no ID? Isn't that the standard way of doing it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on @cahrens question

btw: I really think one of us needs to bite the bullet and remove the Backbone.HTTPemulate setting so it uses POST for create and PUT for update and then clean up our handlers to treat POST and PUT differently, but it seems like such a chore, that I've put it off just making it even more work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I developed the textbooks feature, I noticed that the list of textbooks was stored in one Mongo document, so getting/updating all textbooks at once was just as easy as getting/updating a single textbook at a time, and less error prone (because I could just overwrite the old list with the new content). As a result, I delegated data persistence to the Backbone collection, which would POST the entire collection of textbook models to the server in one HTTP request. Since this was acting on an entire collection, rather than one resource in the collection, I thought it made sense to POST to the textbooks_list_handler endpoint, and have a separate URL for creating new textbooks.

However, coming back to it now, I'm not sure that was a good idea -- it's better to be consistent. Perhaps I could make POST create a new resource, and PUT update the collection. Then I could delete the "new" handler entirely. Would that make sense?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would the relationship with textbooks_detail_handler be? Can we boil it all down to a single method?

GET with no index returns collection
GET with index returns just that textbook
POST with no index creates a textbook
PUT/POST with index updates the textbook

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's clearer to have two methods -- one that operates on collections, and one that operates on individual resources. Do you think it would be better to have one method that does both? These methods are big enough already -- I'm worried about stuffing more and more functionality into a single method.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've combined them in the past, but I don't feel that strongly about it. My main question is where does "new" belong if there are 2 methods--- with the collection method, or with the individual method? My first inclination is that it belongs with the individual method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can only belong with the individual method if the request creating the textbook already has an ID in mind for that textbook: if that's the case, then POSTing to the URL that corresponds to that ID will create the textbook if it doesn't already exist, and update it if it does. If the client doesn't have an ID in mind for the textbook yet, but wants the server to assign an ID, then it needs to use the collection method; it can't address the individual method without an ID.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backbone's model is to POST w/o an id to imply create v using an id w/ PUT to imply update.

@cahrens
Copy link

cahrens commented Nov 27, 2013

I appreciate leaving these textbook methods in course.py for the purpose of the code review (diff), However, after the review is complete, could you move them to their own view file? course.py is too big,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put new as the 2nd arg to url_reverse: self.course_locator.url_reverse('textbooks','new')

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except that we want to get rid of the need to put "new" at all and just key off the fact that there is no ID.

@cahrens
Copy link

cahrens commented Dec 5, 2013

Check out pylint warnings:

cms/djangoapps/contentstore/views/course.py 97.7%
63: C0111: (missing-docstring), get_locator_and_course: Missing docstring
318: W0612: (unused-variable), course_info_handler: Unused variable 'locator'
745: W0612: (unused-variable), textbooks_detail_handler: Unused variable 'locator'

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the same variable need to be passed with 2 different names?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it so that the template only references a textbooks variable, which I could pass in specifically. The context_course variable is used by an inherited template to render the dropdown menus -- it's not used in textbooks.html.

@cahrens
Copy link

cahrens commented Dec 5, 2013

It's hard for me to tell exactly what you changed due to the commit cleanup, but the things I looked at are good. Did not check out the branch and test again. 👍

singingwolfboy added a commit that referenced this pull request Dec 5, 2013
Refactor textbooks to use locator URLs
@singingwolfboy singingwolfboy merged commit f747c76 into master Dec 5, 2013
@singingwolfboy singingwolfboy deleted the db/locator-refactor-textbooks branch December 5, 2013 21:25
jenkins-ks pushed a commit to nttks/edx-platform that referenced this pull request Mar 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants