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

Fix create in newer Tastypie and jQuery (kipped retro-compatibility) #35

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

gartz
Copy link

@gartz gartz commented Jul 31, 2013

Fixes the CREATE method when django-tastypie response only using the page status without a body content;
Make it compatible with old backbone version (0.9.x or older)
Add package.json to be able to use npm install for this package

@PaulUithol
Copy link
Owner

What does this fix, exactly? Can you show that, possibly though a test case?

@gartz
Copy link
Author

gartz commented Oct 26, 2013

The old backbone doesn't have the ajax property, that bind's JQuery or other lib ajax method, so it need to check if Backbone.ajax is present, if isn't it need to try other required lib ajax, like JQuery.

The other change is about xhr response, when you are creating something, tastypie only returns an empty file with the status code, so the resp is empty, but the action has been succeed, creating the item. So when it test and get no response, it thinks it fail, but the request status is success, then we have problems with creating itens, they where created, but in the clientside it still thinking it wasn't created and keep using CREATE instead UPDATE. This fix make only depends from STATUS code and get the right URI to ensure client model represents the created on the server-side.

After this changes it worked on our Django with Tastypie.

I can't create the test case right now, but if you want to test, the first case you simply remove the "ajax" property from Backbone and run the code (backbone 9.x and before doesn't have that property) and for the second, just send a response with only status and none json, resp will become undefined or empty and the !resp will make it believes that isn't been created even when it has been created.

@helber
Copy link

helber commented Oct 30, 2013

I think this is useful to me.

@gartz
Copy link
Author

gartz commented Nov 4, 2013

I have added the package.json to we can use npm install in this package.

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.

3 participants