#NEWLINE# def handle( self , * args , **options ) : #NEWLINE# #INDENT# if options [ 'devices' ] : #NEWLINE# #INDENT# devices = Device . objects . filter ( is_active = True ) #NEWLINE# self . stdout . write ( 'Devices list:\n' ) #NEWLINE# for device in devices : #NEWLINE# #INDENT# self . stdout . write ( ( '(#%s) %s\n' % ( device . id , device . name ) ) ) #NEWLINE# #UNINDENT# self . stdout . write ( '\n' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# collapse_key = devices [ 'collapse_key' ] #NEWLINE# try : #NEWLINE# #INDENT# id = args [ 0 ] #NEWLINE# message = args [ 1 ] #NEWLINE# #UNINDENT# except IndexError : #NEWLINE# #INDENT# raise CommandError ( 'Invalid params. You have to put all params: python manage.py gcm_messenger <device_id> <msg>' ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# device = Device . objects . get ( pk = int ( id ) , is_active = True ) #NEWLINE# #UNINDENT# except Device . DoesNotExist : #NEWLINE# #INDENT# raise CommandError ( ( 'Unknown device (id=%s). Check list: python manage.py gcm_messenger --devices' % id ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# result = device . send_message ( { #NEWLINE# #INDENT# 'message' : message , #NEWLINE# #UNINDENT# } , collapse_key = collapse_key ) #NEWLINE# self . stdout . write ( ( '[OK] device #%s (%s): %s\n' % ( id , device . name , result ) ) )