<s> from __future__ import absolute_import <EOL> from __future__ import unicode_literals <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> from django . views . generic import View <EOL> from django . views . generic . list import MultipleObjectMixin <EOL> from django . views . generic . list import MultipleObjectTemplateResponseMixin <EOL> from . filterset import filterset_factory <EOL> class FilterMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> filterset_class = None <EOL> def get_filterset_class ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . filterset_class : <EOL> return self . filterset_class <EOL> elif self . model : <EOL> return filterset_factory ( self . model ) <EOL> else : <EOL> msg = "<STR_LIT>" <EOL> raise ImproperlyConfigured ( msg % self . __class__ . __name__ ) <EOL> def get_filterset ( self , filterset_class ) : <EOL> """<STR_LIT>""" <EOL> kwargs = self . get_filterset_kwargs ( filterset_class ) <EOL> return filterset_class ( ** kwargs ) <EOL> def get_filterset_kwargs ( self , filterset_class ) : <EOL> """<STR_LIT>""" <EOL> kwargs = { '<STR_LIT:data>' : self . request . GET or None } <EOL> try : <EOL> kwargs . update ( { <EOL> '<STR_LIT>' : self . get_queryset ( ) , <EOL> } ) <EOL> except ImproperlyConfigured : <EOL> if filterset_class . _meta . model is None : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> args = ( filterset_class . __name__ , self . __class__ . __name__ ) <EOL> raise ImproperlyConfigured ( msg % args ) <EOL> return kwargs <EOL> class BaseFilterView ( FilterMixin , MultipleObjectMixin , View ) : <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> filterset_class = self . get_filterset_class ( ) <EOL> self . filterset = self . get_filterset ( filterset_class ) <EOL> self . object_list = self . filterset . qs <EOL> context = self . get_context_data ( filter = self . filterset , <EOL> object_list = self . object_list ) <EOL> return self . render_to_response ( context ) <EOL> class FilterView ( MultipleObjectTemplateResponseMixin , BaseFilterView ) : <EOL> """<STR_LIT>""" <EOL> template_name_suffix = '<STR_LIT>' <EOL> def object_filter ( request , model = None , queryset = None , template_name = None , <EOL> extra_context = None , context_processors = None , <EOL> filter_class = None ) : <EOL> class ECFilterView ( FilterView ) : <EOL> """<STR_LIT>""" <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( ECFilterView , self ) . get_context_data ( ** kwargs ) <EOL> extra_context = self . kwargs . get ( '<STR_LIT>' ) or { } <EOL> for k , v in extra_context . items ( ) : <EOL> if callable ( v ) : <EOL> v = v ( ) <EOL> context [ k ] = v <EOL> return context <EOL> kwargs = dict ( model = model , queryset = queryset , template_name = template_name , <EOL> filterset_class = filter_class ) <EOL> view = ECFilterView . as_view ( ** kwargs ) <EOL> return view ( request , extra_context = extra_context ) </s>
