<s> from django . core . exceptions import ImproperlyConfigured <EOL> class SelectRelatedMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> select_related = None <EOL> def get_queryset ( self ) : <EOL> if self . select_related is None : <EOL> raise ImproperlyConfigured ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( self . __class__ . __name__ ) ) <EOL> if not isinstance ( self . select_related , ( tuple , list ) ) : <EOL> raise ImproperlyConfigured ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" . format ( self . __class__ . __name__ ) ) <EOL> queryset = super ( SelectRelatedMixin , self ) . get_queryset ( ) <EOL> if not self . select_related : <EOL> return queryset <EOL> return queryset . select_related ( * self . select_related ) <EOL> class PrefetchRelatedMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> prefetch_related = None <EOL> def get_queryset ( self ) : <EOL> if self . prefetch_related is None : <EOL> raise ImproperlyConfigured ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( self . __class__ . __name__ ) ) <EOL> if not isinstance ( self . prefetch_related , ( tuple , list ) ) : <EOL> raise ImproperlyConfigured ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" . format ( self . __class__ . __name__ ) ) <EOL> queryset = super ( PrefetchRelatedMixin , self ) . get_queryset ( ) <EOL> if not self . prefetch_related : <EOL> return queryset <EOL> return queryset . prefetch_related ( * self . prefetch_related ) <EOL> class OrderableListMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> orderable_columns = None <EOL> orderable_columns_default = None <EOL> order_by = None <EOL> ordering = None <EOL> def get_context_data ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> context = super ( OrderableListMixin , self ) . get_context_data ( ** kwargs ) <EOL> context [ "<STR_LIT>" ] = self . order_by <EOL> context [ "<STR_LIT>" ] = self . ordering <EOL> return context <EOL> def get_orderable_columns ( self ) : <EOL> if not self . orderable_columns : <EOL> raise ImproperlyConfigured ( <EOL> '<STR_LIT>' . format ( <EOL> self . __class__ . __name__ ) ) <EOL> return self . orderable_columns <EOL> def get_orderable_columns_default ( self ) : <EOL> if not self . orderable_columns_default : <EOL> raise ImproperlyConfigured ( <EOL> '<STR_LIT>' . format ( <EOL> self . __class__ . __name__ ) ) <EOL> return self . orderable_columns_default <EOL> def get_ordered_queryset ( self , queryset = None ) : <EOL> """<STR_LIT>""" <EOL> get_order_by = self . request . GET . get ( "<STR_LIT>" ) <EOL> if get_order_by in self . get_orderable_columns ( ) : <EOL> order_by = get_order_by <EOL> else : <EOL> order_by = self . get_orderable_columns_default ( ) <EOL> self . order_by = order_by <EOL> self . ordering = "<STR_LIT>" <EOL> if order_by and self . request . GET . get ( "<STR_LIT>" , "<STR_LIT>" ) == "<STR_LIT>" : <EOL> order_by = "<STR_LIT:->" + order_by <EOL> self . ordering = "<STR_LIT>" <EOL> return queryset . order_by ( order_by ) <EOL> def get_queryset ( self ) : <EOL> """<STR_LIT>""" <EOL> unordered_queryset = super ( OrderableListMixin , self ) . get_queryset ( ) <EOL> return self . get_ordered_queryset ( unordered_queryset ) </s>
