Django

Code

Ticket #6470 (closed: fixed)

Opened 2 years ago

Last modified 8 months ago

Admin urls should use urlpatterns

Reported by: jdetaeye Assigned to: Alex
Milestone: Component: django.contrib.admin
Version: SVN Keywords: nfa-someday
Cc: schlaber@gmail.com, jay.wineinger@gmail.com, carl@dirtcircle.com, ross@rossp.org Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

If your model has a string as key, there are some admin change pages that are not accessible.

If the primary key of your object ends in "add", "history" or "delete", you can't access the change form any more.

Culprit is the following code in admin\options.py, responsible for parsing the URL:

        if url is None:
            return self.changelist_view(request)
        elif url.endswith('add'):
            return self.add_view(request)
        elif url.endswith('history'):
            return self.history_view(request, unquote(url[:-8]))
        elif url.endswith('delete'):
            return self.delete_view(request, unquote(url[:-7]))
        else:
            return self.change_view(request, unquote(url))

A corrected version is:

        if url is None:
            return self.changelist_view(request)
        elif url == 'add':
            return self.add_view(request)
        elif url.endswith('/history'):
            return self.history_view(request, unquote(url[:-8]))
        elif url.endswith('/delete'):
            return self.delete_view(request, unquote(url[:-7]))
        else:
            return self.change_view(request, unquote(url))

This applies also to the current admin, but in the current only an object with a key equal to "add" will not be accessible (since the url processing is better).

Attachments

nfa-options.diff (0.8 kB) - added by tlpinney on 03/17/08 12:54:09.
nfa-urls.diff (16.2 kB) - added by Alex on 07/12/08 23:04:32.
Initial work on implementing them using a property, not complete(although more or less functional), tests do not all pass
admin-urlpatterns-6470.diff (19.5 kB) - added by Mnewman on 07/28/08 01:03:04.
An update to the patch to apply cleanly to r8129
admin-urlpatterns-6470.2.diff (15.5 kB) - added by Alex on 10/04/08 12:57:39.
Latest version, full tests pass, and should be backwards compatible, updated docs
admin-urlpatterns.diff (15.9 kB) - added by Alex on 01/04/09 16:09:34.
up to date version of the patch
admin-urlpatterns.2.diff (15.9 kB) - added by Alex on 01/04/09 16:14:02.
small update to always use raw strings
admin-urlpatterns.3.diff (14.8 kB) - added by Alex on 01/10/09 17:40:45.
admin-urlpatterns.4.diff (17.3 kB) - added by Alex on 01/12/09 22:41:26.
admin-urlpatterns.5.diff (17.3 kB) - added by Alex on 01/14/09 11:20:48.

Change History

03/11/08 15:08:12 changed by jacob

  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • needs_docs changed.

03/11/08 15:11:54 changed by brosner

  • keywords set to nfa-blocker.

Agreed. This should be fixed.

03/17/08 12:54:09 changed by tlpinney

  • attachment nfa-options.diff added.

03/18/08 14:55:16 changed by jkocherhans

  • summary changed from Admin URLs are not adequately examined to Admin urls should use urlpatterns.

The fix for this ticket is waiting for some changes to the way url dispatch works. There isn't currently a way for the AdminSite class to supply urlpatterns.

06/10/08 00:53:01 changed by Alex

  • keywords changed from nfa-blocker to nfa-someday.

This won't(and doesn't need to) happen pre-merge.

07/12/08 23:04:32 changed by Alex

  • attachment nfa-urls.diff added.

Initial work on implementing them using a property, not complete(although more or less functional), tests do not all pass

07/19/08 16:40:05 changed by Alex

  • version changed from newforms-admin to SVN.

07/28/08 01:03:04 changed by Mnewman

  • attachment admin-urlpatterns-6470.diff added.

An update to the patch to apply cleanly to r8129

08/10/08 04:46:04 changed by Bernd

  • cc set to schlaber@gmail.com.

08/12/08 11:25:06 changed by anonymous

  • cc changed from schlaber@gmail.com to schlaber@gmail.com, jay.wineinger@gmail.com.

09/01/08 00:33:12 changed by carljm

  • cc changed from schlaber@gmail.com, jay.wineinger@gmail.com to schlaber@gmail.com, jay.wineinger@gmail.com, carl@dirtcircle.com.

10/04/08 12:57:39 changed by Alex

  • attachment admin-urlpatterns-6470.2.diff added.

Latest version, full tests pass, and should be backwards compatible, updated docs

10/04/08 12:57:48 changed by Alex

  • owner changed from nobody to Alex.

10/04/08 18:28:31 changed by Alex

  • has_patch set to 1.

11/14/08 11:18:34 changed by Alex

Just saw malcolm's comment on the 1.1 features list(about how multiple AdminSite? instances will cause a probelm), and I'm 100% in agreement that that is an issue, however it's not an issue specific to my proposed method for handling this, you need to have a distinct name for each admin site's url, as such the admin site itself needs to have some concept of it's own name.

11/17/08 17:56:27 changed by rossp

  • cc changed from schlaber@gmail.com, jay.wineinger@gmail.com, carl@dirtcircle.com to schlaber@gmail.com, jay.wineinger@gmail.com, carl@dirtcircle.com, ross@rossp.org.

01/04/09 16:09:34 changed by Alex

  • attachment admin-urlpatterns.diff added.

up to date version of the patch

01/04/09 16:14:02 changed by Alex

  • attachment admin-urlpatterns.2.diff added.

small update to always use raw strings

01/10/09 16:54:20 changed by jacob

(In [9728]) In urlconfs, include() may now be used on an iterable of patterns instead of just a module string. Refs #6470 -- making the admin use a urlconf is much easier with this work done. Thanks, Alex Gaynor.

01/10/09 17:40:45 changed by Alex

  • attachment admin-urlpatterns.3.diff added.

01/12/09 22:41:26 changed by Alex

  • attachment admin-urlpatterns.4.diff added.

01/14/09 11:20:48 changed by Alex

  • attachment admin-urlpatterns.5.diff added.

01/14/09 14:22:26 changed by jacob

  • status changed from new to closed.
  • resolution set to fixed.

(In [9739]) Fixed #6470: made the admin use a URL resolver.

This *is* backwards compatible, but admin.site.root() has been deprecated. The new style is ('^admin/', include(admin.site.urls)); users will need to update their code to take advantage of the new customizable admin URLs.

Thanks to Alex Gaynor.

07/12/09 11:48:33 changed by anonymous

  • status changed from closed to reopened.
  • resolution deleted.

There is a typo in contrib/admin/sites.py [9739], isn't it?

@@ -199,7 +199,7 @@
                 name='%sadmin_index' % self.name),
             url(r'^logout/$',
                 wrap(self.logout),
-                name='%sadmin_logout'),
+                name='%sadmin_logout' % self.name),
             url(r'^password_change/$',
                 wrap(self.password_change),
                 name='%sadmin_password_change' % self.name),

07/12/09 12:34:02 changed by dc

  • status changed from reopened to closed.
  • resolution set to fixed.

There is a separate ticket for this error.


Add/Change #6470 (Admin urls should use urlpatterns)




Change Properties
Action