Code

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#14557 closed (wontfix)

Generic View improvment

Reported by: pyrou Owned by: nobody
Component: Generic views Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Hi,

Maybe adding a __call__ method to django.views.generic.View — source:django/trunk/django/views/generic/base.py — can be useful

something like

    def __call__(self, request, *args, **kwargs):
        return self.dispatch(request, *args, **kwargs)

it will allow to use a genric View "instance" as a view... (hum.. what can be more logical?)

url(r'^permlist/$', ListView(model=Permission, template_name="default/list.html")), 

in addition to (instead of?) the current View.as_view() "factory"

url(r'^permlist/$', ListView.as_view(model=Permission, template_name="default/list.html")),

The sanity check has also to be moved to the View.__init__() method. Have a look to the attached file

Attachments (2)

base.py (6.6 KB) - added by pyrou 3 years ago.
base.py.diff (1.7 KB) - added by pyrou 3 years ago.

Download all attachments as: .zip

Change History (4)

Changed 3 years ago by pyrou

Changed 3 years ago by pyrou

comment:1 Changed 3 years ago by lrekucki

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to closed

Sorry, but I'm going to mark this as won't fix. In summary, what you propose causes assignments to self persist from one request to another(It's also not thread safe). Please see wiki page: http://code.djangoproject.com/wiki/ClassBasedViews (and the discussion threads mentioned there) if you want to know more. There is a good reason, why this way of creating views was chosen.

comment:2 Changed 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.