<s> from __future__ import division , absolute_import , unicode_literals <EOL> from django . contrib import messages <EOL> from django . views . generic import TemplateView <EOL> from django . utils . encoding import force_text <EOL> from django . utils . text import capfirst <EOL> from django . utils . translation import ugettext_lazy , ungettext , pgettext_lazy <EOL> from django . utils . translation import ugettext as _ <EOL> from . import permissions , utils <EOL> from . viewmixins import AdminModel2Mixin <EOL> def get_description ( action ) : <EOL> if hasattr ( action , '<STR_LIT:description>' ) : <EOL> return action . description <EOL> else : <EOL> return capfirst ( action . __name__ . replace ( '<STR_LIT:_>' , '<STR_LIT:U+0020>' ) ) <EOL> class BaseListAction ( AdminModel2Mixin , TemplateView ) : <EOL> permission_classes = ( permissions . IsStaffPermission , ) <EOL> empty_message = ugettext_lazy ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> only_selected = True <EOL> queryset = None <EOL> def __init__ ( self , queryset , * args , ** kwargs ) : <EOL> self . queryset = queryset <EOL> self . model = queryset . model <EOL> options = utils . model_options ( self . model ) <EOL> self . app_label = options . app_label <EOL> self . model_name = options . model_name <EOL> self . item_count = len ( queryset ) <EOL> if self . item_count <= <NUM_LIT:1> : <EOL> objects_name = options . verbose_name <EOL> else : <EOL> objects_name = options . verbose_name_plural <EOL> self . objects_name = force_text ( objects_name ) <EOL> super ( BaseListAction , self ) . __init__ ( * args , ** kwargs ) <EOL> def get_queryset ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . queryset <EOL> def description ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> @ property <EOL> def success_message ( self ) : <EOL> raise NotImplementedError ( <EOL> "<STR_LIT>" <EOL> ) <EOL> @ property <EOL> def success_message_plural ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . success_message <EOL> @ property <EOL> def default_template_name ( self ) : <EOL> raise NotImplementedError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def get_context_data ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> context = super ( BaseListAction , self ) . get_context_data ( ) <EOL> def _format_callback ( obj ) : <EOL> opts = utils . model_options ( obj ) <EOL> return '<STR_LIT>' % ( force_text ( capfirst ( opts . verbose_name ) ) , <EOL> force_text ( obj ) ) <EOL> collector = utils . NestedObjects ( using = None ) <EOL> collector . collect ( self . queryset ) <EOL> context . update ( { <EOL> '<STR_LIT>' : self , <EOL> '<STR_LIT>' : self . objects_name , <EOL> '<STR_LIT>' : self . queryset , <EOL> '<STR_LIT>' : collector . nested ( _format_callback ) , <EOL> } ) <EOL> return context <EOL> def get ( self , request ) : <EOL> if self . item_count > <NUM_LIT:0> : <EOL> return super ( BaseListAction , self ) . get ( request ) <EOL> message = _ ( self . empty_message ) <EOL> messages . add_message ( request , messages . INFO , message ) <EOL> return None <EOL> def post ( self , request ) : <EOL> if self . process_queryset ( ) is None : <EOL> message = ungettext ( <EOL> self . success_message , <EOL> self . success_message_plural , <EOL> self . item_count <EOL> ) % { <EOL> '<STR_LIT:count>' : self . item_count , '<STR_LIT>' : self . objects_name <EOL> } <EOL> messages . add_message ( request , messages . INFO , message ) <EOL> return None <EOL> def process_queryset ( self ) : <EOL> msg = '<STR_LIT>' <EOL> raise NotImplementedError ( msg ) <EOL> class DeleteSelectedAction ( BaseListAction ) : <EOL> default_template_name = "<STR_LIT>" <EOL> description = ugettext_lazy ( "<STR_LIT>" ) <EOL> success_message = pgettext_lazy ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> success_message_plural = pgettext_lazy ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> permission_classes = BaseListAction . permission_classes + ( <EOL> permissions . ModelDeletePermission , <EOL> ) <EOL> def post ( self , request ) : <EOL> if request . POST . get ( '<STR_LIT>' ) : <EOL> super ( DeleteSelectedAction , self ) . post ( request ) <EOL> else : <EOL> return self . get ( request ) <EOL> def process_queryset ( self ) : <EOL> self . get_queryset ( ) . delete ( ) </s>
