#29750: Add a pre-dispatch() hook for class-based views
----------------------------------+--------------------------------------
Reporter: François Freitag | Owner: nobody
Type: New feature | Status: closed
Component: Generic views | Version: 2.1
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Carlton Gibson):
* status: new => closed
* resolution: => wontfix
Comment:
Hi François.
Hmmm. I'm sceptical about this to begin. For me, there's two things going
on here: the framework specific job of handling the request, for which the
logic belongs in `dispatch()`, and the application specific job of
whatever-it-is-your-app-does, for which the logic belongs in the method
handlers. I look at the examples here and think that you're mixing the
two, just making the code harder to follow, and so creating an unnecessary
maintenance burden, all for the sake a single line of duplication.
The specific `get_object()` call in `BaseUpdateView` is a key part of the
view logic. That it's repeated is absolutely fine (for me): it keeps the
view logic entirely on the surface, and clear as day. If that logic moves
to `dispatch()`, the question is ''What's this doing here?'', or more
likely, I never look at it at all, because that's just not where it's
meant to be, especially if spread across a number of mixins, as in your
example. (If such repetition did become overwhelming, if can be factored
to a helper that is a single line to call, that remains part of the view
logic.)
> ... is often implemented by overriding the dispatch() method.
Really? (For these kinds of reasons) I just wouldn't do that. 🙂
However, as ever, there's more than one way to go about things... can I
ask you to post this to django-developers to see if people are keen?
I'm always open to persuasion but my comments here would be an initial -1.
(One thought: if you want this, can you not create a base view/mixin that
adds the `pre_dispatch()` hook, then override that as needed, thus leaving
Django out of it?)
For now, I'm going to close this here as `wontfix`. If the discussion on
django-developers is positive, I'm really happy to see if re-opened then.
(Bottom-line is it's a design decision that's better off settled there
than here. Hopefully that makes sense.)
--
Ticket URL: <https://code.djangoproject.com/ticket/29750#comment:1>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/073.d0817ec389658c221c0582a062269a99%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.