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

API browser not displaying POST form #3578

Closed
nfletton opened this issue Oct 31, 2015 · 7 comments
Closed

API browser not displaying POST form #3578

nfletton opened this issue Oct 31, 2015 · 7 comments

Comments

@nfletton
Copy link
Contributor

nfletton commented Oct 31, 2015

There seems to be an issue with the display of the POST form in the 3.3.0 api browser and it's related to the switch to using bootstrap tab panes in the browser base template.

In 3.2.5:
selection_059

In 3.3.0:
selection_060

Adding an 'active' class to the tab-pane containing the POST form with DevTools results in the form displaying correctly.

@jpadilla
Copy link
Member

jpadilla commented Nov 4, 2015

@nfletton it'd really help to have some steps to reproduce this.

@avara1986
Copy link

avara1986 commented Nov 4, 2015

For example, if i have this ViewSet:

class FooViewSet(viewsets.ModelViewSet):
    authentication_classes = (
        authentication.TokenAuthentication,
        authentication.SessionAuthentication,

    )
    permission_classes = (
        permissions.IsAuthenticated,
    )
    @list_route(methods=['post'], parser_classes=(MultiPartParser,))
    def foo_bar(self, request):
        ....

And send this request with Token Authorization from an external host:

POST /api/v1/foo/bar/ HTTP/1.1
Authorization: Token 628129ba5429fee459cf1e3b873a3fb8679e218b
Cache-Control: no-cache
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="msg"

test
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="attached"; filename="upload_test.txt"
Content-Type: text/plain
....

request.data return:

>> print request.data
<QueryDict: {u'msg': [u'test'], u'attached': [<InMemoryUploadedFile: upload_test.txt (text/plain)>]}>

But, if i send this request from a web form in the same host, with a started session.

POST /api/v1/foo/bar/ HTTP/1.1
X-CSRFToken:wTgUevurtyRQZW4yiiy4MyxH0UEeDdVO
Cache-Control: no-cache
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="msg"

test
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="attached"; filename="upload_test.txt"
Content-Type: text/plain

request.data return:

>> request.data
<QueryDict: {}>

But, request.POST is not empty:

>> print request.POST
<QueryDict: {u'msg': [u'test'], u'attached': [u'', u'']}>
>> print request.FILES
<MultiValueDict: {}>

If you need any further explanation, please let me know. 😃

Thanks! 👍

@tomchristie
Copy link
Member

tomchristie commented Nov 4, 2015

I'd suggest upgrading to 3.3.1 first and seeing if that resolves - if not then we'll consider looking into this further.

@avara1986
Copy link

avara1986 commented Nov 4, 2015

Ok, it's solved 👍

Thanks a lot!

@tomchristie
Copy link
Member

tomchristie commented Nov 4, 2015

Great!

@nfletton
Copy link
Contributor Author

nfletton commented Nov 4, 2015

Can we leave this one open? For me, 3.3.1 does not solve the original problem I reported.

I think the problem is that the POST form renders inside Bootstrap style tabs. In my scenario there's only one tab rendered by the template (tab-pane with id = post-generic-content-form) and as a consequence of the conditional code in base.html no Bootstrap tab markup is generated (i.e. the Nav tabs markup http://getbootstrap.com/javascript/#markup). Without the tab markup the code in default.js to activate a tab, has no effect. That JS code is:

} else {
    // If no tab selected, display rightmost tab.
    $('.form-switcher a:first').tab('show');
}

I'll take a further look but I have not seen what historical change is causing this for me.

@xordoquy
Copy link
Collaborator

xordoquy commented Nov 13, 2015

Closing this as #3600 was merged.

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

5 participants