Ticket #2382: 2382.patch

File 2382.patch, 3.5 KB (added by arnaud AT pimentech DOT net, 18 years ago)

Propagates filter values (in GET) when editing or adding an object in admin

  • contrib/admin/views/main.py

     
    269269                    (pk_value, str(new_object).replace('"', '\\"')))
    270270            elif request.POST.has_key("_addanother"):
    271271                request.user.message_set.create(message=msg + ' ' + (_("You may add another %s below.") % opts.verbose_name))
    272                 return HttpResponseRedirect(request.path)
     272                return HttpResponseRedirect(request.path + '?' + request.GET.urlencode())
    273273            else:
    274274                request.user.message_set.create(message=msg)
    275                 return HttpResponseRedirect(post_url)
     275                return HttpResponseRedirect(post_url + '?' + request.GET.urlencode())
    276276    else:
    277277        # Add default data.
    278278        new_data = manipulator.flatten_data()
     
    348348                if request.REQUEST.has_key('_popup'):
    349349                    return HttpResponseRedirect(request.path + "?_popup=1")
    350350                else:
    351                     return HttpResponseRedirect(request.path)
     351                    return HttpResponseRedirect(request.path + '?' + request.GET.urlencode())
    352352            elif request.POST.has_key("_saveasnew"):
    353353                request.user.message_set.create(message=_('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % {'name': opts.verbose_name, 'obj': new_object})
    354                 return HttpResponseRedirect("../%s/" % pk_value)
     354                return HttpResponseRedirect("../%s/" % pk_value + '?' + request.GET.urlencode())
    355355            elif request.POST.has_key("_addanother"):
    356356                request.user.message_set.create(message=msg + ' ' + (_("You may add another %s below.") % opts.verbose_name))
    357                 return HttpResponseRedirect("../add/")
     357                return HttpResponseRedirect("../add/" + '?' + request.GET.urlencode())
    358358            else:
    359359                request.user.message_set.create(message=msg)
    360                 return HttpResponseRedirect("../")
     360                return HttpResponseRedirect("../" + '?' + request.GET.urlencode())
    361361    else:
    362362        # Populate new_data with a "flattened" version of the current data.
    363363        new_data = manipulator.flatten_data()
     
    736736        return qs
    737737
    738738    def url_for_result(self, result):
    739         return "%s/" % quote(getattr(result, self.pk_attname))
     739        return "%s/" % quote(getattr(result, self.pk_attname)) + self.get_query_string()
    740740
    741741def change_list(request, app_label, model_name):
    742742    model = models.get_model(app_label, model_name)
  • contrib/admin/templates/admin/change_list.html

     
    88{% block content %}
    99<div id="content-main">
    1010{% if has_add_permission %}
    11 <ul class="object-tools"><li><a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink">{% blocktrans with cl.opts.verbose_name|escape as name %}Add {{ name }}{% endblocktrans %}</a></li></ul>
     11<ul class="object-tools"><li><a href="add/{% if is_popup %}?_popup=1{% else %}{{ cl.get_query_string }}{% endif %}" class="addlink">{% blocktrans with cl.opts.verbose_name|escape as name %}Add {{ name }}{% endblocktrans %}</a></li></ul>
    1212{% endif %}
    1313<div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist">
    1414{% block search %}{% search_form cl %}{% endblock %}
Back to Top