Ticket #4413: remember_change_list_params.diff

File remember_change_list_params.diff, 2.2 KB (added by jim-django@…, 17 years ago)

patch to contrib/admin/views/main.py to return users to the last viewed change list after saving.

  • main.py

     
    105105                break
    106106    return js
    107107
     108def list_params_recall_key(model):
     109    return "%s.%s.last_params"  % (model._meta.app_label, model.__class__.__name__)
     110
    108111class AdminBoundField(object):
    109112    def __init__(self, field, field_mapping, original):
    110113        self.field = field
     
    357360                return HttpResponseRedirect("../add/")
    358361            else:
    359362                request.user.message_set.create(message=msg)
    360                 return HttpResponseRedirect("../")
     363                last_params_key = list_params_recall_key(model)
     364                print "last_params_key is %s" % repr(last_params_key)
     365                if last_params_key in request.session:
     366                    print "got last_params, it was %s" % repr(request.session[last_params_key])
     367                    last_params = request.session[last_params_key].items()
     368                    page = "?%s" % "&".join(["%s=%s" % kv for kv in last_params])
     369                    print "page is %s" % repr(page)
     370                else:
     371                    print "no last_page_key."
     372                    page = ""
     373                return HttpResponseRedirect("../%s" % page)
    361374    else:
    362375        # Populate new_data with a "flattened" version of the current data.
    363376        new_data = manipulator.flatten_data()
     
    558571            self.page_num = int(request.GET.get(PAGE_VAR, 0))
    559572        except ValueError:
    560573            self.page_num = 0
     574
     575
     576
    561577        self.show_all = ALL_VAR in request.GET
    562578        self.is_popup = IS_POPUP_VAR in request.GET
    563579        self.params = dict(request.GET.items())
    564         if PAGE_VAR in self.params:
    565             del self.params[PAGE_VAR]
     580
    566581        if ERROR_FLAG in self.params:
    567582            del self.params[ERROR_FLAG]
    568583
     584        # Remember which page the user was on (hackish)
     585        request.session[list_params_recall_key(model)] = self.params.copy()
     586
     587        if PAGE_VAR in self.params:
     588            del self.params[PAGE_VAR]
     589
     590
     591
    569592        self.order_field, self.order_type = self.get_ordering()
    570593        self.query = request.GET.get(SEARCH_VAR, '')
    571594        self.query_set = self.get_query_set()
Back to Top