Code

Opened 3 months ago

Closed 4 weeks ago

Last modified 3 weeks 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

Attachments (0)

Change History (22)

comment:1 Changed 3 months ago by loic84

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

@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 Changed 3 months ago by honyczek

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 Changed 3 months ago by timo

  • Resolution set to needsinfo
  • Status changed from new to 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 Changed 3 months ago by honyczek

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 Changed 3 months ago by honyczek

  • Resolution needsinfo deleted
  • Status changed from closed to new

comment:6 Changed 3 months ago by timo

Is _changelist_filters being dropped from the query string?

comment:7 Changed 3 months ago by honyczek

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 3 months ago by honyczek (previous) (diff)

comment:8 Changed 3 months ago by timo

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 Changed 3 months ago by aaugustin

  • Resolution set to needsinfo
  • Status changed from new to closed

comment:11 Changed 2 months ago by honyczek

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 Changed 2 months ago by timo

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

comment:13 Changed 4 weeks ago by timo

  • Resolution needsinfo deleted
  • Status changed from closed to new
  • Summary changed from preserve_filter doesn't work on production server to preserve_filter doesn't work when running a site with a url prefix
  • Triage Stage changed from Unreviewed to 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 Changed 4 weeks ago by loic84

@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 Changed 4 weeks ago by loic84

  • Cc loic@… added

comment:17 Changed 4 weeks ago by honyczek

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:18 follow-up: Changed 4 weeks ago by loic84

  • Resolution fixed deleted
  • Status changed from closed to 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 Changed 4 weeks ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 4339e9a92d98371a50a6fe54ab7ea0c602ecee28:

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

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

comment:20 Changed 4 weeks ago by Tim Graham <timograham@…>

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 Changed 4 weeks ago by Tim Graham <timograham@…>

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

comment:22 in reply to: ↑ 18 Changed 3 weeks ago by honyczek

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 Changed 3 weeks ago by loic84

Cool, thanks @honyczek.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.