<s> from __future__ import unicode_literals <EOL> from django . contrib import admin <EOL> from django . core . exceptions import PermissionDenied <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from . models import Hit , HitCount , BlacklistIP , BlacklistUserAgent <EOL> class HitAdmin ( admin . ModelAdmin ) : <EOL> list_display = ( '<STR_LIT>' , '<STR_LIT:user>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> search_fields = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> date_hierarchy = '<STR_LIT>' <EOL> actions = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( HitAdmin , self ) . __init__ ( * args , ** kwargs ) <EOL> self . list_display_links = None <EOL> def has_add_permission ( self , request ) : <EOL> return False <EOL> def get_actions ( self , request ) : <EOL> actions = super ( HitAdmin , self ) . get_actions ( request ) <EOL> if '<STR_LIT>' in actions : <EOL> del actions [ '<STR_LIT>' ] <EOL> return actions <EOL> def blacklist_ips ( self , request , queryset ) : <EOL> for obj in queryset : <EOL> ip , created = BlacklistIP . objects . get_or_create ( ip = obj . ip ) <EOL> if created : <EOL> ip . save ( ) <EOL> msg = _ ( "<STR_LIT>" ) % queryset . count ( ) <EOL> self . message_user ( request , msg ) <EOL> blacklist_ips . short_description = _ ( "<STR_LIT>" ) <EOL> def blacklist_user_agents ( self , request , queryset ) : <EOL> for obj in queryset : <EOL> ua , created = BlacklistUserAgent . objects . get_or_create ( <EOL> user_agent = obj . user_agent ) <EOL> if created : <EOL> ua . save ( ) <EOL> msg = _ ( "<STR_LIT>" ) % queryset . count ( ) <EOL> self . message_user ( request , msg ) <EOL> blacklist_user_agents . short_description = _ ( "<STR_LIT>" ) <EOL> def blacklist_delete_ips ( self , request , queryset ) : <EOL> self . blacklist_ips ( request , queryset ) <EOL> self . delete_queryset ( request , queryset ) <EOL> blacklist_delete_ips . short_description = _ ( <EOL> "<STR_LIT>" ) <EOL> def blacklist_delete_user_agents ( self , request , queryset ) : <EOL> self . blacklist_user_agents ( request , queryset ) <EOL> self . delete_queryset ( request , queryset ) <EOL> blacklist_delete_user_agents . short_description = _ ( <EOL> "<STR_LIT>" ) <EOL> def delete_queryset ( self , request , queryset ) : <EOL> if not self . has_delete_permission ( request ) : <EOL> raise PermissionDenied <EOL> else : <EOL> if queryset . count ( ) == <NUM_LIT:1> : <EOL> msg = "<STR_LIT>" <EOL> else : <EOL> msg = "<STR_LIT>" % queryset . count ( ) <EOL> for obj in queryset . iterator ( ) : <EOL> obj . delete ( ) <EOL> self . message_user ( request , "<STR_LIT>" % msg ) <EOL> delete_queryset . short_description = _ ( "<STR_LIT>" ) <EOL> admin . site . register ( Hit , HitAdmin ) <EOL> class HitCountAdmin ( admin . ModelAdmin ) : <EOL> list_display = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> fields = ( '<STR_LIT>' , ) <EOL> def has_add_permission ( self , request ) : <EOL> return False <EOL> admin . site . register ( HitCount , HitCountAdmin ) <EOL> class BlacklistIPAdmin ( admin . ModelAdmin ) : <EOL> pass <EOL> admin . site . register ( BlacklistIP , BlacklistIPAdmin ) <EOL> class BlacklistUserAgentAdmin ( admin . ModelAdmin ) : <EOL> pass <EOL> admin . site . register ( BlacklistUserAgent , BlacklistUserAgentAdmin ) </s>
