from functools import wraps

def filter_powered(filterform_cls, queryset_name='object_list', pass_params=False,
        add_count=False, aggregate_args={}, values_spec=None, deferred=None):

    def decorator(view):

        @wraps(view)
        def filter_powered_view(request, *args, **kwargs):
            output = view(request, *args, **kwargs)
            # Work only with views that returns dict context
            if isinstance(output, dict):
                context = output
                queryset = output.get(queryset_name)
            elif isinstance(output, tuple):
                context = output[1]
                queryset = context.get(queryset_name)
            else:
                return output

            # XXX Maybe this should be eliminated (if there is no result,
            # do we want to have filterform in context?)
            #if not queryset:
            #    return output

            if not pass_params:
                filterform = filterform_cls(request.GET)
            else:
                filterform = filterform_cls(request.GET, view_kwargs=kwargs)

            # Perform actual filtering
            queryset = filterform.filter(queryset)

            if add_count:
                context[queryset_name + '_count'] = queryset.count()
            if aggregate_args:
                aggregated = queryset.aggregate(**aggregate_args)
                context.update(aggregated)
            if values_spec:
                queryset = queryset.values(*values_spec)
            if deferred is not None:
                queryset, context = deferred(queryset, context)

            context[queryset_name] = queryset
            context['filterform'] = filterform
            if isinstance(output, dict):
                output = context
            elif isinstance(output, tuple):
                output = (output[0], context)
            return output

        return filter_powered_view

    return decorator

@@ -360,54 +360,69 @@
   # 
-Work only with views that returns dict 
+SimpleTemplateResponse objects have context in %60
 context
+_data%60
 %0A   
@@ -433,39 +433,46 @@
      if 
-isinstance(output, dict
+hasattr(output, 'context_data'
 ):%0A     
@@ -502,61 +502,93 @@
 tput
-%0A                queryset = output.get(queryset_name)
+.context_data%0A            # Otherwise, work only with views that returns dict context
 %0A   
@@ -612,37 +612,36 @@
 nstance(output, 
-tuple
+dict
 ):%0A             
@@ -663,11 +663,8 @@
 tput
-%5B1%5D
 %0A   
@@ -676,97 +676,174 @@
     
-    queryset = context.get(queryset_name)%0A            else:%0A                return output
+elif isinstance(output, tuple):%0A                context = output%5B1%5D%0A            else:%0A                return output%0A%0A            queryset = context.get(queryset_name)
 %0A%0A  
@@ -1988,16 +1988,102 @@
 ontext)%0A
+            elif hasattr(output, 'context'):%0A                output.context = context%0A
         

Make possible to work with views that returns TemplateResponse