#26300: Dogfood CBV in contrib.flatpages
-------------------------------------+-------------------------------------
Reporter: knyghty | Owner: knyghty
Type: | Status: new
Cleanup/optimization |
Component: contrib.flatpages | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by knyghty):
I don't disagree that CBVs are not always better, but I think they may be
here. Personally, I think there are two things here.
Firstly, maybe you disagree, but I think that having two views and several
lines of comments to explain why there are two is kind of messy. I think
that's valuable cleanup in itself.
Secondly, yeah, it may not be much simpler than writing a custom view, but
I think it's certainly cleaner.
Quick example:
You have a contact page with some copy above it. You want to be able to
change the copy without changing the code. This is a very common scenario
I've dealt with a number of times. There are several solutions here.
1. Make your own {{{Page}}} model, and a view for it, then use
{{{DetailView}}} and {{{FormMixin}}} here. Not bad, but what if flatpages
are suitable for you otherwise, it makes more sense to leverage them
right?
2. Use a regular {{{FormView}}} and something like django-flatblocks to
put the copy in. Fine, but if you don't need flatblocks for anything else,
it's kind of annoying.
3. Use flatpages, have a separate view for the contact form, use a custom
flatpage template and put your form in the template manually. Kind of
awful in my view.
4. Use flatpages model, but make your own view for it. Okay, kinda works,
but do you really want to copy all the code from the flatblocks views for
this? Violates DRY for me.
Let me know if there's a good solution I'm missing.
Proposed solution:
Inherit {{{FlatPageDetailView}}} (or whatever) and mix in {{{FormMixin}}}.
Then just provide either a custom template with the form, or have your
default flatpage template check for a form and render it if it exists.
Seems like a nice solution in my view. It might make a good example for
the docs, too.
--
Ticket URL: <https://code.djangoproject.com/ticket/26300#comment:2>
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/065.9379abb2e3e3cff6f82e63b1621232c0%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.