#3777: Persistent change_list filtering in admin
----------------------------------------------------+-----------------------
          Reporter:  matt <matt.ba...@dotwell.org>  |         Owner:  nobody    
    
            Status:  closed                         |     Milestone:            
    
         Component:  django.contrib.admin           |       Version:  SVN       
    
        Resolution:  worksforme                     |      Keywords:  filter 
session
             Stage:  Unreviewed                     |     Has_patch:  1         
    
        Needs_docs:  1                              |   Needs_tests:  0         
    
Needs_better_patch:  0                              |  
----------------------------------------------------+-----------------------
Comment (by etiennepoul...@gmail):

 Here is how I did it (based on the previous post by tony.perkins)
 This does not require any modification to the templates, just the
 middleware
 (tested With django 1.02)


 {{{
 from django import http

 class FilterPersistMiddleware(object):

     def process_request(self, request):

         path = request.path
         if path.find('/admin/') != -1: #Dont waste time if we are not in
 admin
             query_string = request.META['QUERY_STRING']
             if not request.META.has_key('HTTP_REFERER'):
                 return None

             session = request.session
             if session.get('redirected', False):#so that we dont loop once
 redirected
                 del session['redirected']
                 return None

             referrer = request.META['HTTP_REFERER'].split('?')[0]
             referrer = referrer[referrer.find('/admin'):len(referrer)]
             key = 'key'+path.replace('/','_')

             if path == referrer: #We are in same page as before
                 if query_string == '': #Filter is empty, delete it
                     if session.get(key,False):
                         del session[key]
                     return None
                 request.session[key] = query_string
             else: #We are are coming from another page, restore filter if
 available
                 if session.get(key, False):
                     query_string=request.session.get(key)
                     redirect_to = path+'?'+query_string
                     request.session['redirected'] = True
                     return http.HttpResponseRedirect(redirect_to)
                 else:
                     return None
         else:
             return None
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/3777#comment:4>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to