<s> from __future__ import unicode_literals <EOL> from django . contrib import admin <EOL> from django . contrib . auth import get_user_model <EOL> from django . contrib . comments . models import Comment <EOL> from django . utils . translation import ugettext_lazy as _ , ungettext_lazy <EOL> from django . contrib . comments import get_model <EOL> from django . contrib . comments . views . moderation import perform_flag , perform_approve , perform_delete <EOL> class UsernameSearch ( object ) : <EOL> """<STR_LIT>""" <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % get_user_model ( ) . USERNAME_FIELD <EOL> class CommentsAdmin ( admin . ModelAdmin ) : <EOL> fieldsets = ( <EOL> ( None , <EOL> { '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) } <EOL> ) , <EOL> ( _ ( '<STR_LIT>' ) , <EOL> { '<STR_LIT>' : ( '<STR_LIT:user>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) } <EOL> ) , <EOL> ( _ ( '<STR_LIT>' ) , <EOL> { '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) } <EOL> ) , <EOL> ) <EOL> list_display = ( '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> list_filter = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> date_hierarchy = '<STR_LIT>' <EOL> ordering = ( '<STR_LIT>' , ) <EOL> raw_id_fields = ( '<STR_LIT:user>' , ) <EOL> search_fields = ( '<STR_LIT>' , UsernameSearch ( ) , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> actions = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> def get_actions ( self , request ) : <EOL> actions = super ( CommentsAdmin , self ) . get_actions ( request ) <EOL> if not request . user . is_superuser and '<STR_LIT>' in actions : <EOL> actions . pop ( '<STR_LIT>' ) <EOL> if not request . user . has_perm ( '<STR_LIT>' ) : <EOL> if '<STR_LIT>' in actions : <EOL> actions . pop ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in actions : <EOL> actions . pop ( '<STR_LIT>' ) <EOL> return actions <EOL> def flag_comments ( self , request , queryset ) : <EOL> self . _bulk_flag ( request , queryset , perform_flag , <EOL> ungettext_lazy ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) <EOL> flag_comments . short_description = _ ( "<STR_LIT>" ) <EOL> def approve_comments ( self , request , queryset ) : <EOL> self . _bulk_flag ( request , queryset , perform_approve , <EOL> ungettext_lazy ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) <EOL> approve_comments . short_description = _ ( "<STR_LIT>" ) <EOL> def remove_comments ( self , request , queryset ) : <EOL> self . _bulk_flag ( request , queryset , perform_delete , <EOL> ungettext_lazy ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) <EOL> remove_comments . short_description = _ ( "<STR_LIT>" ) <EOL> def _bulk_flag ( self , request , queryset , action , done_message ) : <EOL> """<STR_LIT>""" <EOL> n_comments = <NUM_LIT:0> <EOL> for comment in queryset : <EOL> action ( request , comment ) <EOL> n_comments += <NUM_LIT:1> <EOL> self . message_user ( request , done_message % n_comments ) <EOL> if get_model ( ) is Comment : <EOL> admin . site . register ( Comment , CommentsAdmin ) </s>
