#NEWLINE# def Update( self , client , callback ) : #NEWLINE# #INDENT# 'Call the base class "Update" method in order to persist modified\n    columns to the db. But also ensure that this device has a unique\n    push token; two Viewfinder devices might share the same push token\n    if a phone has been given or sold to another person without\n    re-installing the OS. Also, ensure that the device is added to the\n    secondary index used for alerting (alert_user_id), for fast\n    enumeration of all devices that need to be alerted for a particular\n    user.\n    ' #NEWLINE# def _DoUpdate( ) : #NEWLINE# #INDENT# super ( Device , self ) . Update ( client , callback ) #NEWLINE# #UNINDENT# def _OnQueryByPushToken( devices ) : #NEWLINE# #INDENT# 'Disable alerts for all other devices.' #NEWLINE# with util . Barrier ( _DoUpdate ) as b : #NEWLINE# #INDENT# for device in devices : #NEWLINE# #INDENT# if ( device . device_id != self . device_id ) : #NEWLINE# #INDENT# device . push_token = None #NEWLINE# device . alert_user_id = None #NEWLINE# super ( Device , device ) . Update ( client , b . Callback ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# self . last_access = util . GetCurrentTimestamp ( ) #NEWLINE# if self . _IsModified ( 'push_token' ) : #NEWLINE# #INDENT# if ( self . push_token is None ) : #NEWLINE# #INDENT# self . alert_user_id = None #NEWLINE# _DoUpdate ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . alert_user_id = self . user_id #NEWLINE# query_expr = ( 'device.push_token={t}' , { #NEWLINE# #INDENT# 't' : self . push_token , #NEWLINE# #UNINDENT# } ) #NEWLINE# Device . IndexQuery ( callback , query_expr , None , _OnQueryByPushToken ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# _DoUpdate ( )