Opened 5 years ago

Closed 5 years ago

#25385 closed Cleanup/optimization (fixed)

Allow importing django.views.generic.View from django.views.View

Reported by: jambonrose Owned by: Asif Saifuddin Auvi
Component: Generic views Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Whenever I talk about class-based views and how their concept is separate from generic views (typically in a class setting), the question I am asked is invariably: if they are different, why do we import View from django.views.generic?

To help developers better avoid confusion and better separate the concepts, I would like to change the import of the View class. Ideally:

from django.views import View

I would furthermore like to move View from the generic directory into it's own module.

Change History (21)

comment:1 Changed 5 years ago by Tim Graham

Have you discussed the idea with anyone? If not, could you please raise it on the DevelopersMailingList to see if there are any objections?

comment:2 Changed 5 years ago by Tim Graham

Component: Core (URLs)Generic views
Summary: Import of ViewsAllow importing django.views.generic.View from django.views.View

comment:4 Changed 5 years ago by Tim Graham

Triage Stage: UnreviewedAccepted

comment:5 Changed 5 years ago by Tim Graham

Easy pickings: set

comment:6 Changed 5 years ago by Asif Saifuddin Auvi

anyone working on this? or volunteer needed? I'm interested to work on it :D

comment:7 Changed 5 years ago by Tim Graham

If there's no activity on a ticket in weeks, it's probably fine to reassign it.

comment:8 Changed 5 years ago by Asif Saifuddin Auvi

Owner: changed from jambonrose to Asif Saifuddin Auvi
Status: newassigned

comment:9 Changed 5 years ago by Asif Saifuddin Auvi

Hi tim,

View class need to be moved from generic module to views module, what whould be the module name? base.py? or view.py?

after moving specific classes it will be needed to fix the import in existing all modules/files too. does the contextmixin need to be moved along with VIEW class?

comment:10 Changed 5 years ago by Asif Saifuddin Auvi

+ deprecation warnings needed too for moved classes?

comment:11 Changed 5 years ago by Tim Graham

I think it's enough to add an import for from django.views.generic.base import View in django/views/__init__.py. I don't see much gain in moving the code.

comment:12 in reply to:  11 Changed 5 years ago by Asif Saifuddin Auvi

Replying to timgraham:

I think it's enough to add an import for from django.views.generic.base import View in django/views/__init__.py. I don't see much gain in moving the code.

that seems much simpler then!!!

comment:13 Changed 5 years ago by Asif Saifuddin Auvi

PR created

https://github.com/django/django/pull/5742

Docs + Release notes needed.

should It be back ported to 1.8 and 1.9?

comment:14 Changed 5 years ago by Asif Saifuddin Auvi

./django/views/init__.py:1:1: F401 'View' imported but unused
Build step 'Execute shell' marked build as failure
Setting status of 3b403668b22bea5315bc1c6fbb8237527d43ebb4 to FAILURE with url http://djangoci.com/job/flake8/6233/ and message: 'Build finished. No test results found.'
Using context: flake8
Finished: FAILURE

Then test should be added too to make the build pass?

comment:15 Changed 5 years ago by Tim Graham

You can fix the flake8 failure by adding __all__ = ['View'] in that file.

It's a new feature, so it's not a candidate for backport. See our supported versions policy.

comment:16 Changed 5 years ago by Asif Saifuddin Auvi

ok thanks will update accordingly

comment:17 Changed 5 years ago by Asif Saifuddin Auvi

I guess only release notes and some docs update and squash commit required

comment:18 Changed 5 years ago by Varun Sharma

Has patch: set

comment:19 in reply to:  18 ; Changed 5 years ago by Asif Saifuddin Auvi

Replying to varun:

PR: https://github.com/django/django/pull/5951

Hi Varun, I've already send a PR and the PR is still open. besides I haven't deassigned the issue yet :) so to avoid duplicate works better to ask the assigned guy first.

comment:20 in reply to:  19 Changed 5 years ago by Varun Sharma

Replying to auvipy:
Hi !!
I saw your PR and there wasn't any activity or follow up in that from last 18 days. I guess that's a reasonable period to reassign the ticket. There wasn't much of work in this anyway :)

comment:21 Changed 5 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 3d6474e1:

Fixed #25385 -- Allowed importing views.generic.View from views.View.

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