Opened 8 years ago

Closed 7 years ago

#15906 closed Bug (fixed)

New head method needs documentation

Reported by: Jannis Leidel Owned by: Zbigniew Siciarz
Component: Documentation Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: yes UI/UX: no

Description (last modified by Jannis Leidel)

The head method added in r16095 & r16105 needs documentation.

Attachments (1)

patch_15906.diff (2.9 KB) - added by Zbigniew Siciarz 7 years ago.
A new section on how to use head() in a generic view.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 8 years ago by Jannis Leidel

Description: modified (diff)

comment:2 Changed 8 years ago by Jannis Leidel

Component: DocumentationGeneric views

comment:3 Changed 8 years ago by Alex Gaynor

Easy pickings: set

comment:4 Changed 7 years ago by Zbigniew Siciarz

Owner: changed from nobody to Zbigniew Siciarz
UI/UX: unset

Changed 7 years ago by Zbigniew Siciarz

Attachment: patch_15906.diff added

A new section on how to use head() in a generic view.

comment:5 Changed 7 years ago by Zbigniew Siciarz

Has patch: set

comment:6 Changed 7 years ago by Jannis Leidel

Component: Generic viewsDocumentation
Patch needs improvement: set

This looks good in principle, but I wonder if the example should use the @last_modified decorator instead:

comment:7 Changed 7 years ago by Tim Graham

@jezdez, I've spent a while looking at it, but it's unclear to me how to use the @last_modified decorator inside the class-based view. The tricky part is how to pass the "last_modified_func". I imagine it might be something like the following:

class EntryListView(ListView):
    model = Entry

    def latest_entry(self, request):
        return self.get_queryset().latest('published').published.strftime('%a, %d %b %Y %H:%M:%S GMT')

    def head(self, *args, **kwargs):
        return HttpResponse('')

Any insight?

comment:8 Changed 7 years ago by Tim Graham

Consulted with Malcolm on IRC -- didn't seem like using last_modified is viable so going to commit this as is.

malcolmt: the code in that comment looks essentially correct. Have you tried it and does it work?
malcolmt: That's what method_decorator() is for.
me: the issue with the code as I posted it is that latest_entry needs to be called with "self" (exception is: latest_entry() takes exactly 2 arguments (1 given))
malcolmt: oooh.
malcolmt: That old chestnut: functions != methods. again. :-(
malcolmt: and you need "self" in that function, so you can't make it @classmethod.
malcolmt: bummer :(
me: do you think the answer is "it's not possible" then?
malcolmt: Probably "not possible yet". It *might* be worth changing the signature on last_modified and etag to make them able to handle methods. I'm waiting for carljm to provide a consult.
malcolmt: It's almost unnecessarily fiddly sometimes in Python to make things that work with both functions and methods, it seems.
me: sounds good, thanks for the assist. I'll go ahead and commit the doc and we can revise it to use last_modified if that works out
malcolmt: I think you're using last_modified poorly in that example, since it's meant to be computed based on the request and the URL params. "self" really has no role there except as a way to avoid having to pull out the object again.
malcolmt: What's really need is a last_modified_for_methods() function that understands how to work with class methods.
malcolmt: I don't think there's an easy soln in the current setup. I also have trouble caring much about class-based views, so it's not something I'm likely to spend time on fixing. Sorry.

comment:9 Changed 7 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In [518c58296667ffc36f90b873eb97aa99fa00eb1e]:

Fixed #15906 - Documented HEAD method in CBVs; thanks zsiciarz for the patch.

Note: See TracTickets for help on using tickets.
Back to Top