Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve List Filters #83

Open
WarToaster opened this issue Sep 16, 2017 · 2 comments
Open

Preserve List Filters #83

WarToaster opened this issue Sep 16, 2017 · 2 comments

Comments

@WarToaster
Copy link

Is there a way to redirect an user after he clicked on an action and preserve applied filters?

Any help would be appreciated :)

@crccheck
Copy link
Owner

I don't think that's something that can be handled with django-object-actions. You could store Admin form state in localStorage.

crccheck pushed a commit that referenced this issue Apr 12, 2018
If you want to filter change_list by some conditions,
then open each object and run some object action there,
you will be returned to change_list with the same preserved filters.

Fix #83 

* Return to preserved filters on change_list after object action

* Changes after pull request: Load add_preserved_filters from admin_urls

* Changes after pull request: Indentation presumably reverted to original style
@WarToaster
Copy link
Author

Thanks for the work on it, but it doesn't quite seem fixed. The newest Pypi release still got the old templates files, and all list filters still get dropped anyway.

Here's my current workaround:

  • add custom templates
change_form_template = "django_object_actions/change_form_filters.html"
change_list_template = "django_object_actions/change_list_filters.html"
  • add custom redirect function (mostly copied from django source contrib/admin/options.py)
def redirect_preserve_filters(self, request, obj, change_list=False):
        opts = self.model._meta
        preserved_filters = self.get_preserved_filters(request)
        if change_list:
            redir_url = reverse('admin:%s_%s_changelist' %
                                (opts.app_label, opts.model_name),
                                current_app=self.admin_site.name)
        else:
            pk_value = obj._get_pk_val()
            redir_url = reverse('admin:%s_%s_change' %
                                (opts.app_label, opts.model_name),
                                args=(pk_value,),
                                current_app=self.admin_site.name)
        preserved_filters = self.get_preserved_filters(request)
        redir_url = add_preserved_filters({'preserved_filters': preserved_filters, 'opts': opts}, redir_url)
        return HttpResponseRedirect(redir_url)
  • call that function at the end of every object action
...
obj.save()
return self.redirect_preserve_filters(request, obj)

Please tell me if I got that wrong, and thanks again!

@crccheck crccheck reopened this Apr 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants