<s> from django . contrib import admin <EOL> from django . utils import timezone <EOL> from alert . models import Alert , AlertPreference , AdminAlert <EOL> from alert . signals import admin_alert_saved <EOL> class AlertAdmin ( admin . ModelAdmin ) : <EOL> list_display = ( '<STR_LIT:username>' , '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ) <EOL> list_filter = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> search_fields = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> actions = [ '<STR_LIT>' ] <EOL> raw_id_fields = ( "<STR_LIT:user>" , ) <EOL> def queryset ( self , request ) : <EOL> qs = super ( AlertAdmin , self ) . queryset ( request ) <EOL> if hasattr ( qs , "<STR_LIT>" ) : <EOL> qs = qs . prefetch_related ( "<STR_LIT:user>" ) <EOL> return qs <EOL> def username ( self , obj ) : <EOL> return obj . user . username <EOL> def resend ( self , request , qs ) : <EOL> for alert in qs : <EOL> alert . send ( ) <EOL> resend . short_description = "<STR_LIT>" <EOL> class AlertPrefAdmin ( admin . ModelAdmin ) : <EOL> list_display = ( "<STR_LIT:user>" , '<STR_LIT>' , "<STR_LIT>" , '<STR_LIT>' ) <EOL> list_filter = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> search_fields = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> actions = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> raw_id_fields = ( "<STR_LIT:user>" , ) <EOL> def unsubscribe ( self , request , qs ) : <EOL> qs . update ( preference = False ) <EOL> unsubscribe . short_description = '<STR_LIT>' <EOL> def subscribe ( self , request , qs ) : <EOL> qs . update ( preference = True ) <EOL> subscribe . short_description = '<STR_LIT>' <EOL> class AdminAlertAdmin ( admin . ModelAdmin ) : <EOL> list_display = ( "<STR_LIT:title>" , "<STR_LIT:status>" , "<STR_LIT>" , ) <EOL> search_fields = ( "<STR_LIT:title>" , ) <EOL> fieldsets = ( <EOL> ( None , { <EOL> '<STR_LIT>' : ( '<STR_LIT:title>' , '<STR_LIT:body>' , ) <EOL> } ) , <EOL> ( "<STR_LIT>" , { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , ) <EOL> } ) , <EOL> ( "<STR_LIT>" , { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> } ) , <EOL> ) <EOL> def get_readonly_fields ( self , request , obj = None ) : <EOL> if obj and obj . sent : <EOL> return ( "<STR_LIT:title>" , '<STR_LIT:body>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> else : <EOL> return ( ) <EOL> def save_model ( self , request , obj , form , change ) : <EOL> is_draft = obj . draft <EOL> if is_draft : <EOL> obj . draft = False <EOL> obj . sent = obj . sent or not is_draft <EOL> obj . save ( ) <EOL> recipients = obj . recipients . user_set . all ( ) <EOL> if not is_draft : <EOL> admin_alert_saved . send ( sender = AdminAlert , instance = obj , recipients = recipients ) <EOL> def status ( self , obj ) : <EOL> if obj . sent : <EOL> return "<STR_LIT>" if obj . send_at < timezone . now ( ) else "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" <EOL> def send_time ( self , obj ) : <EOL> return "<STR_LIT:->" if not obj . sent else obj . send_at <EOL> admin . site . register ( Alert , AlertAdmin ) <EOL> admin . site . register ( AlertPreference , AlertPrefAdmin ) <EOL> admin . site . register ( AdminAlert , AdminAlertAdmin ) </s>
