#6083 closed (fixed)
contrib.auth still uses oldforms
Reported by: | Marc Fargas | Owned by: | Brian Rosner |
---|---|---|---|
Component: | Contrib apps | Version: | dev |
Severity: | Keywords: | auth forms newforms oldforms | |
Cc: | roppert | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
Could not find a ticket stating it so here it is.
the title says it all :)
Attachments (7)
Change History (22)
comment:1 by , 17 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 17 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 17 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
comment:4 by , 17 years ago
Has patch: | set |
---|---|
Keywords: | auth forms newforms oldforms added |
Needs documentation: | set |
Needs tests: | set |
by , 17 years ago
Attachment: | auth-uses-newforms.diff added |
---|
comment:5 by , 17 years ago
Marked #6318 as duplicate. It has a patch as well so perhaps they needed to be merged unless they really accomplished the same exact thing with little differences.
comment:6 by , 17 years ago
I encountered the following error when using Django's test framework fake web client (django.test.client.Client):
---------------------------------------------------------------------- Traceback (most recent call last): File "/home/gmaps/test/tilecache/an/portal/test_login.py", line 72, in testLoginWorks resp = self.client.post(self.loginurl, { 'username': self.u1, 'password': self.p1 }) File "/home/gmaps/django-test//lib/python2.4/site-packages/django/test/client.py", line 238, in post return self.request(**r) File "/home/gmaps/django-test//lib/python2.4/site-packages/django/core/handlers/base.py", line 82, in get_response response = callback(request, *callback_args, **callback_kwargs) File "/home/gmaps/django-test//lib/python2.4/site-packages/django/contrib/auth/views.py", line 23, in login request.session.delete_test_cookie() File "/home/gmaps/django-test//lib/python2.4/site-packages/django/contrib/sessions/backends/base.py", line 69, in delete_test_cookie del self[self.TEST_COOKIE_NAME] File "/home/gmaps/django-test//lib/python2.4/site-packages/django/contrib/sessions/backends/base.py", line 38, in __delitem__ del self._session[key] KeyError: 'testcookie' ----------------------------------------------------------------------
And this was happening because I was just POSTing to the login form with the "username" and "password" values without setting the test cookie. Then sessions.delete_test_cookie() tries to delete the cookie regardless of whether it exists or not (this seems like a bug to me...), and instead of getting an error message or anything, it just crashes. I added a one-liner fix:
--- views.py-old 2008-01-18 00:08:10.000000000 +0000 +++ views.py 2008-01-18 00:08:19.000000000 +0000 @@ -20,7 +20,8 @@ redirect_to = settings.LOGIN_REDIRECT_URL from django.contrib.auth import login login(request, form.get_user()) - request.session.delete_test_cookie() + if request.session.test_cookie_worked(): + request.session.delete_test_cookie() return HttpResponseRedirect(redirect_to) else: form = AuthenticationForm(request=request)
The updated patch I will attach contains this tweak and is against a more recent SVN rev so the patch applies cleanly.
by , 17 years ago
Attachment: | auth-uses-newforms-2.diff added |
---|
includes a one-liner update for delete_test_cookie() problem
by , 17 years ago
Attachment: | auth-uses-newforms-3.diff added |
---|
Fixed reference to comments.auth.py and added fix to admin.templates.admin.auth.user.change_password.html for new forms and slight change to the way contrib.auth.forms.AdminPasswordChangeForm cleans the form, and changed auth.views.py to use AdminPasswordChangeForm instead of the now nonexistent old form way
comment:7 by , 17 years ago
Cc: | added |
---|
by , 17 years ago
Attachment: | 03-newforms-auth.diff added |
---|
comment:8 by , 17 years ago
I tried another approach for this problem - not to remove oldforms versions, but to add newforms version only. I think it is not necessary to force everybody to port authorization code at once.
Another idea is to port "post data" logins (without redirections, with saving of post data) from oldforms-admin and newforms-admin to auth - so newforms-admin wouldn't need any authorization code. New parameter extra_context (#5298) is necessary for it - newforms-admin needs more context variables.
I am not sure that this patch works fully - I have checked only some forms. (It should be part of bigger series of tickets which is not ready.) I mean my patch mainly as a comment now. (I read about this ticket today on django-developers.)
by , 17 years ago
Attachment: | auth-uses-oldforms-3.diff added |
---|
fixes a few issues and changes the user add view into newforms
comment:9 by , 17 years ago
Patch needs improvement: | set |
---|
This new patch does not have an import of django.contrib.auth.admin in it, because while using auth multiple calls need to be made to models, auth (init), forms, etc. I never received a design decision from https://groups.google.com/group/django-developers/browse_thread/thread/ba8b115b74d6e502 . I would like to take Petr's patch to Django Devs as well, it is my opinion that as new forms merges into the trunk switches need to be made to all of admin and, in all reality, the switch of Auth would be relatively automatic.
comment:10 by , 17 years ago
Owner: | changed from | to
---|
I have added a patch against newforms-admin. I will eventually be committing the final patch there. My patch current breaks comments since it had dependancy on the oldforms AuthenticationForm. I will be looking more into whether just moving the oldforms version over will be correct way.
comment:11 by , 17 years ago
Status: | new → assigned |
---|
comment:12 by , 17 years ago
Development of this patch can be found at http://github.com/brosner/django/tree/newforms_auth
by , 17 years ago
Attachment: | 6083_newforms_auth2.diff added |
---|
more complete with tests and docs. looking for feedback.
comment:13 by , 17 years ago
Needs documentation: | unset |
---|---|
Needs tests: | unset |
I have attached a more complete version of the patch. I have moved some files in django.contrib.auth.tests to make it easier for other parts of the app.
comment:14 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
I've made the changes to contrib.auth (my first Django patch!). The oldforms are used in contrib.admin and contrib.comments, and I have patched these too. Contrib.admin now uses the newforms in authentication forms. contrib.comments subclasses the oldform AuthenticationForm, and has heavy reliance on validators so I made a copy of AuthenticationForm and put it in comments.py.
I'll update the documentation if the approach seems sound. Shall I also update the newforms branch?