Ticket #3777: admin-filters-in-session.2.diff
File admin-filters-in-session.2.diff, 8.1 KB (added by , 18 years ago) |
---|
-
django/contrib/admin/filterspecs.py
55 55 else: 56 56 self.lookup_title = f.verbose_name 57 57 self.lookup_kwarg = '%s__%s__exact' % (f.name, f.rel.to._meta.pk.name) 58 self.lookup_val = request.GET.get(self.lookup_kwarg, None)58 self.lookup_val = params.get(self.lookup_kwarg, None) 59 59 self.lookup_choices = f.rel.to._default_manager.all() 60 60 61 61 def has_output(self): … … 80 80 def __init__(self, f, request, params, model): 81 81 super(ChoicesFilterSpec, self).__init__(f, request, params, model) 82 82 self.lookup_kwarg = '%s__exact' % f.name 83 self.lookup_val = request.GET.get(self.lookup_kwarg, None)83 self.lookup_val = params.get(self.lookup_kwarg, None) 84 84 85 85 def choices(self, cl): 86 86 yield {'selected': self.lookup_val is None, … … 133 133 super(BooleanFieldFilterSpec, self).__init__(f, request, params, model) 134 134 self.lookup_kwarg = '%s__exact' % f.name 135 135 self.lookup_kwarg2 = '%s__isnull' % f.name 136 self.lookup_val = request.GET.get(self.lookup_kwarg, None)137 self.lookup_val2 = request.GET.get(self.lookup_kwarg2, None)136 self.lookup_val = params.get(self.lookup_kwarg, None) 137 self.lookup_val2 = params.get(self.lookup_kwarg2, None) 138 138 139 139 def title(self): 140 140 return self.field.verbose_name … … 157 157 class AllValuesFilterSpec(FilterSpec): 158 158 def __init__(self, f, request, params, model): 159 159 super(AllValuesFilterSpec, self).__init__(f, request, params, model) 160 self.lookup_val = request.GET.get(f.name, None)160 self.lookup_val = params.get(f.name, None) 161 161 self.lookup_choices = model._meta.admin.manager.distinct().order_by(f.name).values(f.name) 162 162 163 163 def title(self): -
django/contrib/admin/views/main.py
12 12 from django.http import Http404, HttpResponse, HttpResponseRedirect 13 13 from django.utils.html import escape 14 14 from django.utils.text import capfirst, get_text_list 15 from django.conf import settings 15 16 import operator 16 17 18 17 19 from django.contrib.admin.models import LogEntry, ADDITION, CHANGE, DELETION 18 20 if not LogEntry._meta.installed: 19 21 raise ImproperlyConfigured, "You'll need to put 'django.contrib.admin' in your INSTALLED_APPS setting before you can use the admin application." … … 33 35 SEARCH_VAR = 'q' 34 36 IS_POPUP_VAR = 'pop' 35 37 ERROR_FLAG = 'e' 38 SESSION_RESTORE_VAR = 'sr' 36 39 37 40 # Text to display within change-list table cells if the value is blank. 38 41 EMPTY_CHANGELIST_VALUE = '(None)' … … 235 238 if post_url is None: 236 239 if request.user.has_perm(app_label + '.' + opts.get_change_permission()): 237 240 # redirect to list view 238 post_url = '../ '241 post_url = '../?sr' 239 242 else: 240 243 # Object list will give 'Permission Denied', so go back to admin home 241 244 post_url = '../../../' … … 357 360 return HttpResponseRedirect("../add/") 358 361 else: 359 362 request.user.message_set.create(message=msg) 360 return HttpResponseRedirect("../ ")363 return HttpResponseRedirect("../?sr") 361 364 else: 362 365 # Populate new_data with a "flattened" version of the current data. 363 366 new_data = manipulator.flatten_data() … … 512 515 obj.delete() 513 516 LogEntry.objects.log_action(request.user.id, ContentType.objects.get_for_model(model).id, object_id, obj_display, DELETION) 514 517 request.user.message_set.create(message=_('The %(name)s "%(obj)s" was deleted successfully.') % {'name': opts.verbose_name, 'obj': obj_display}) 515 return HttpResponseRedirect("../../ ")518 return HttpResponseRedirect("../../?sr") 516 519 extra_context = { 517 520 "title": _("Are you sure?"), 518 521 "object_name": opts.verbose_name, … … 554 557 self.manager = self.opts.admin.manager 555 558 556 559 # Get search parameters from the query string. 560 self.set_params(request, model) 561 self.order_field, self.order_type = self.get_ordering() 562 self.query_set = self.get_query_set() 563 self.get_results(request) 564 self.title = (self.is_popup and _('Select %s') % self.opts.verbose_name or _('Select %s to change') % self.opts.verbose_name) 565 self.filter_specs, self.has_filters = self.get_filters(request) 566 self.pk_attname = self.lookup_opts.pk.attname 567 568 def set_params(self, request, model): 569 query = request.GET.copy() 570 restore = SESSION_RESTORE_VAR in request.GET 571 sessions = 'django.contrib.sessions' in settings.INSTALLED_APPS 572 573 # restore from session if requested 574 if sessions: 575 saved = request.session.setdefault('change_list_params', {}) \ 576 .setdefault(model._meta.app_label,{}) \ 577 .setdefault(model._meta.object_name, {}) 578 if restore: 579 for key in saved: 580 query.setdefault(key, saved[key]) 557 581 try: 558 self.page_num = int( request.GET.get(PAGE_VAR, 0))582 self.page_num = int(query.get(PAGE_VAR, 0)) 559 583 except ValueError: 560 584 self.page_num = 0 561 self.show_all = request.GET.has_key(ALL_VAR) 562 self.is_popup = request.GET.has_key(IS_POPUP_VAR) 563 self.params = dict(request.GET.items()) 585 self.show_all = query.has_key(ALL_VAR) 586 self.is_popup = query.has_key(IS_POPUP_VAR) 587 self.params = dict(query.items()) 588 564 589 if self.params.has_key(PAGE_VAR): 565 590 del self.params[PAGE_VAR] 566 591 if self.params.has_key(ERROR_FLAG): 567 592 del self.params[ERROR_FLAG] 593 if restore: 594 del self.params[SESSION_RESTORE_VAR] 595 self.query = query.get(SEARCH_VAR, '') 568 596 569 self.order_field, self.order_type = self.get_ordering()570 self.query = request.GET.get(SEARCH_VAR, '')571 self.query_set = self.get_query_set()572 self.get_results(request)573 self.title = (self.is_popup and _('Select %s') % self.opts.verbose_name or _('Select %s to change') % self.opts.verbose_name)574 self.filter_specs, self.has_filters = self.get_filters(request)575 self.pk_attname = self.lookup_opts.pk.attname597 # save session 598 if sessions: 599 # make sure session gets saved 600 request.session['change_list_params_changed'] = 1 601 saved.clear() 602 for key in self.params: 603 saved[key] = self.params[key] 576 604 577 605 def get_filters(self, request): 578 606 filter_specs = [] -
django/contrib/sessions/middleware.py
36 36 def get(self, key, default=None): 37 37 return self._session.get(key, default) 38 38 39 def setdefault(self, key, default): 40 if not key in self: 41 self[key] = default 42 return self[key] 43 39 44 def set_test_cookie(self): 40 45 self[TEST_COOKIE_NAME] = TEST_COOKIE_VALUE 41 46 -
django/contrib/admin/templates/admin/change_form.html
11 11 {% block breadcrumbs %}{% if not is_popup %} 12 12 <div class="breadcrumbs"> 13 13 <a href="../../../">{% trans "Home" %}</a> › 14 <a href="../ ">{{ opts.verbose_name_plural|capfirst|escape }}</a> ›14 <a href="../?sr">{{ opts.verbose_name_plural|capfirst|escape }}</a> › 15 15 {% if add %}{% trans "Add" %} {{ opts.verbose_name|escape }}{% else %}{{ original|truncatewords:"18"|escape }}{% endif %} 16 16 </div> 17 17 {% endif %}{% endblock %}