Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#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 loic84, 11 years ago

@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?

comment:2 by honyczek, 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 Tim Graham, 11 years ago

Resolution: needsinfo
Status: newclosed

@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 honyczek, 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 honyczek, 11 years ago

Resolution: needsinfo
Status: closednew

comment:6 by Tim Graham, 11 years ago

Is _changelist_filters being dropped from the query string?

comment:7 by honyczek, 11 years ago

No, on edit form I have URL: http://server/confiback/admin/frontend/device/89/?_changelist_filters=profile__id__exact%3D21. But after saving it returns to list with URL: http://server/confiback/admin/frontend/device/?e=1 and filter is not applied.

Last edited 11 years ago by honyczek (previous) (diff)

comment:8 by Tim Graham, 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 Aymeric Augustin, 11 years ago

Resolution: needsinfo
Status: newclosed

comment:11 by honyczek, 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 Tim Graham, 11 years ago

Ping me (timograham) in #django-dev if you like, it will be easier than communicating via this ticket.

comment:13 by Tim Graham, 11 years ago

Resolution: needsinfo
Status: closednew
Summary: preserve_filter doesn't work on production serverpreserve_filter doesn't work when running a site with a url prefix
Triage Stage: UnreviewedAccepted
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 loic84, 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 loic84, 11 years ago

Cc: loic@… added

comment:17 by honyczek, 11 years ago

Resolution: fixed
Status: newclosed

Great, it seems to be fixed. Thanks a lot.

comment:18 by loic84, 11 years ago

Resolution: fixed
Status: closednew

@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 Tim Graham <timograham@…>, 11 years ago

Resolution: fixed
Status: newclosed

In 4339e9a92d98371a50a6fe54ab7ea0c602ecee28:

Fixed #21795 -- Made add_preserved_filters account for url prefixes.

Thanks to trac username honyczek for the report. Refs #6903.

comment:20 by Tim Graham <timograham@…>, 11 years ago

In a5297c1ef4c4c010d1eb979177d4633beb5f9cad:

[1.6.x] Fixed #21795 -- Made add_preserved_filters account for url prefixes.

Thanks to trac username honyczek for the report. Refs #6903.

Backport of 4339e9a92d from master

comment:21 by Tim Graham <timograham@…>, 11 years ago

In 5268d71f18d12c362d74010210309c1cec8e8a1a:

[1.7.x] Fixed #21795 -- Made add_preserved_filters account for url prefixes.

Thanks to trac username honyczek for the report. Refs #6903.

Backport of 4339e9a92d from master

in reply to:  18 comment:22 by honyczek, 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.

comment:23 by loic84, 11 years ago

Cool, thanks @honyczek.

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