Skip to content

API browser not displaying POST form #3578

Closed

Description

@nfletton

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.

Activity

  1. jpadilla commented on Nov 4, 2015

    @jpadilla
    Contributor

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

  2. avara1986 commented on Nov 4, 2015

    @avara1986

    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! 👍

  3. lovelydinosaur commented on Nov 4, 2015

    @lovelydinosaur
    Member

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

  4. avara1986 commented on Nov 4, 2015

    @avara1986

    Ok, it's solved 👍

    Thanks a lot!

  5. lovelydinosaur commented on Nov 4, 2015

    @lovelydinosaur
    Member

    Great!

  6. nfletton commented on Nov 4, 2015

    @nfletton
    ContributorAuthor

    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.

  7. added this to the 3.3.2 Release milestone on Nov 10, 2015
  8. xordoquy commented on Nov 13, 2015

    @xordoquy
    Contributor

    Closing this as #3600 was merged.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions