Generic view classes should inherit from TemplateView etc
See original GitHub issueI’m talking about the classes located in wagtailadmin.views.generic
.
They all are inheriting from View
. They would be easier to use if inheriting from TemplateView (e.g. adding extra context data with get_context_data
).
The Create/Edit/Delete views could also benefit from inheriting at least from FormMixin
. Even better if they would inherit from BaseCreateView
and so on.
So, any reason why this was not done? I’m willing to do the PR if needed.
Thanks.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Introduction to class-based views - Django documentation
Class-based views provide an alternative way to implement views as Python ... Object oriented techniques such as mixins (multiple inheritance) can be used ......
Read more >Class based views - Advanced Django Training
The class-based views in Django all extend from the parent class View . This class can be found in django.views.generic.base (code here). The...
Read more >Django Class-Based Generic Views: tips for beginners (or ...
If you inherit from two classes that both define a foo() method, your new class will use the one from the parent class...
Read more >How to implement a Django class-based view that is both ...
You're overcomplicating this. FormView - like almost all generic views - already inherits from TemplateView (or rather, from ContextMixin, ...
Read more >Django Tutorial Part 6: Generic list and detail views
We will be inheriting from an existing generic view function that already ... For Django class-based views we access an appropriate view ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the response. Here’s what I think about it:
That’s where I disagree. They separate every logical needs so you only have to override what’s necessary. Right now, in the
IndexView
, I need to override and copy/paste (because what I need to change is located in the middle of the method) the entireget
method, which include getting the data, setting the context and the rendering. All that only to add a single variable to the context. Personally, that is what I call counter-productive.Most of what we need would already be handled by the CBV provided by Django. And some of those needs are already (not completely) re-implemented by some classes (https://github.com/wagtail/wagtail/blob/master/wagtail/wagtailadmin/views/generic.py#L170-L183, https://github.com/wagtail/wagtail/blob/master/wagtail/wagtailadmin/views/generic.py#L204-L212).
Generic CBV should be easy to use and with low maintenance for almost every use-case. Right now I need to check at every new Wagtail release that the logic inside these views didn’t changed, otherwise I have to change my own view as well to reflect those changes.
Resolved in #3625