#21795 closed Bug (fixed)
preserve_filter doesn't work when running a site with a url prefix
Reported by: | honyczek | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 1.6 |
Severity: | Normal | Keywords: | |
Cc: | loic@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Function preserve_filter works only on development server at localhost. If you try ./manage.py runserver 192.168.1.1:8000
or if you try your project on production server (Apache HTTPD), it doesn't work. Filters in admin aren't preserved.
Related: #6903
Change History (22)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
There is one of my projects, where I enabled preserve_filters, which is available to public. http://confiback.sourceforge.net/
I'll try it at Nginx. But at Apache with mod_wsgi it doesn't work. Python 2.7.3/Django 1.6 or Python 2.7.5/Django 1.6
comment:3 by , 11 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
@honyczek, it would be really helpful if you could do some more investigation yourself and provide some more details to reproduce the problem. Just saying it "doesn't work" is not a great bug report.
comment:4 by , 11 years ago
If I enable preserve_filters parameter in my django.contrib.admin.ModelAdmin instance:
class DeviceAdmin(admin.ModelAdmin): list_display = ['name', 'ip', 'profileUrl', 'backupsUrl', 'linkUrl'] list_filter = ['profile'] inlines = [KeywordMacroInline] actions_on_bottom = True actions_on_top = False actions = ['manual_backup'] preserve_filters = True def linkUrl(self, device): if device.url: return "<a href=\"%s\" target=\"_blank\">%s</a>" % (device.url, _("Click to view device custom URL")) else: return "<a>-</a>" linkUrl.allow_tags = True linkUrl.short_description = _("Custom URL") def profileUrl(self, device): return "<a href=\"%s\">%s</a>" % (urlresolvers.reverse('admin:frontend_profile_change', args=(device.profile.id,)),device.profile.name) profileUrl.allow_tags = True profileUrl.short_description = _("Profile") def backupsUrl(self, device): return "<a href=\"%s?device__id__exact=%s\">%s: %s</a> (<a href=\"%s\">%s</a>)" % (urlresolvers.reverse('admin:frontend_backup_changelist'), device.id, _("Total"), models.Backup.objects.filter(device=device).count(), urlresolvers.reverse('frontend:download_backup_as_file', kwargs={'backup_id': models.Backup.objects.filter(device=device).latest('date').id}), _("Download the latest")) backupsUrl.allow_tags = True backupsUrl.short_description = _("Backups") def manual_backup(modeladmin, request, queryset): from django.shortcuts import redirect _ret = "{}?ids={}".format(urlresolvers.reverse('frontend:run_backup'),"_".join(str(i.id) for i in queryset)) return redirect(_ret) manual_backup.short_description = _("Make manual backup of selected devices")
then I select one of profiles on the right menu to filter list, then open one Device to edit details and then I click to Save button, so Admin returns to Device list with clean filter and displays devices from all profiles (profile filter is empty and All is selected).
What I expect:
After click to Save button, Admin returns to Device list and filter will be still enabled (previously selected profile will remain selected).
comment:5 by , 11 years ago
Resolution: | needsinfo |
---|---|
Status: | closed → new |
comment:7 by , 11 years ago
No, on edit form I have URL: http://server/confiback/admin/frontend/device/89/?_changelist_filters=e%3D1
and after saving it returns to list with URL: http://server/confiback/admin/frontend/device/?e=1
. But filter is not applied.
comment:8 by , 11 years ago
It looks like the changelist_view
function in contrib.admin.options is throwing an IncorrectLookupParameters
exception. It would be great if you could look into the reason for that. I think the fact that you say it worked on localhost not on other servers is a red herring.
comment:9 by , 11 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
comment:11 by , 11 years ago
Ok, I'd like to do it, but I haven't any knowledge how to debug this. Could you give me some recommendations what to use and where to look?
comment:12 by , 11 years ago
Ping me (timograham) in #django-dev if you like, it will be easier than communicating via this ticket.
comment:13 by , 11 years ago
Resolution: | needsinfo |
---|---|
Status: | closed → new |
Summary: | preserve_filter doesn't work on production server → preserve_filter doesn't work when running a site with a url prefix |
Triage Stage: | Unreviewed → Accepted |
UI/UX: | unset |
We discussed this on #django-dev and determined that the problem is specific to running a site with a URL prefix. In particular, add_preserved_filters
raises a Resolver404
.
loic84 is looking into it further.
comment:14 by , 11 years ago
@honyczek could you check if https://github.com/loic/django/compare/ticket21795 fixes your issue?
I have a feeling writing a test for this patch is going to be pretty painful.
comment:15 by , 11 years ago
Cc: | added |
---|
comment:17 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Great, it seems to be fixed. Thanks a lot.
follow-up: 22 comment:18 by , 11 years ago
Resolution: | fixed |
---|---|
Status: | closed → new |
@honyczek did you test the patch on the pull request? because it's not merged on master yet, hence why I'm reopening the ticket.
comment:19 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:22 by , 11 years ago
Replying to loic84:
@honyczek did you test the patch on the pull request? because it's not merged on master yet, hence why I'm reopening the ticket.
Yes, i did. Thanks.
@honyczek it works for me, both in production (uWSGI behind a Nginx reverse proxy) and with the dev server using various combinations of hosts and ports.
Would you be able to upload a minimal project that demonstrates the issue?