#15668: Generic views should provide a HEAD implementation
-----------------------------------------+-----------------------
               Reporter:  j4mie          |        Owner:  nobody
                 Status:  new            |    Milestone:
              Component:  Generic views  |      Version:  1.3-rc1
             Resolution:                 |     Keywords:
           Triage Stage:  Unreviewed     |    Has patch:  1
    Needs documentation:  0              |  Needs tests:  0
Patch needs improvement:  1              |
-----------------------------------------+-----------------------
Changes (by j4mie):

 * needs_better_patch:  0 => 1
 * has_patch:  0 => 1


Comment:

 I have added an initial patch, which probably needs improvement.

 1. Is the `as_view` method the correct place to add in the `head = get`
 patch?

 2. I had to make some changes to the tests to make this work. All the
 other tests in the `ViewTest` class use a `RequestFactory`, but I had to
 use the `TestClient` to make sure the content of the response was stripped
 correctly. This begs the question: should the content removal be done in
 the `View` class itself to prevent inconsistencies? Something like this
 maybe:

 {{{#!python
 def head_if_get(self, request, *args, **kwargs):
     # This method adds support for HEAD requests. If
     # a View subclass provides a get method, this method
     # is automatically aliased to head by as_view above.
     def remove_content(response):
         response.content = ''
     response = self.get(request, *args, **kwargs)
     if hasattr(response, 'add_post_render_callback'):
         response.add_post_render_callback(remove_content)
     else:
         remove_content(response)
     return response
 }}}

 Then

 {{{#!python
 if hasattr(self, 'get') and not hasattr(self, 'head'):
     self.head = self.head_if_get
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/15668#comment:3>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to