def sync_users(self, users): if users: total = len(users) successful = 0 failed = 0 self.stdout.write( "Attempting to synchronize {} accounts to LDAP".format(total)) for user in users: self.stdout.write("Synchronizing '{}({})'...".format( user, user.id), ending='') update_ldap_account(user, create=True) ldap_account = get_ldap_account_safely(user) if ldap_account.synchronized: self.stdout.write(self.style.SUCCESS(' Success!')) successful = successful + 1 else: self.stdout.write(self.style.ERROR(' Error')) self.stdout.write( self.style.NOTICE(ldap_account.ldap_error_message)) failed = failed + 1 self.stdout.write( "{}/{} accounts synchronized to LDAP, {} failures".format( successful, total, failed)) else: self.stdout.write( "No accounts synchronized, to force synchronization use the 'force' argument" )
def email_address_post_delete(**kwargs): """ Delete email addresses from user's LDAP account. Because email addresses are stored in a seperate model linked to User by a ForeignKey, we need to independently listen for changes. TODO: Gets called multiple times when a user account is saved/deleted (once for each email address). """ email_address = kwargs['instance'] update_ldap_account(email_address.user)
def sync_users(self, users): if users: total = len(users) successful = 0 failed = 0 self.stdout.write("Attempting to synchronize {} accounts to LDAP".format(total)) for user in users: self.stdout.write("Synchronizing '{}({})'...".format(user, user.id), ending='') update_ldap_account(user, create=True) ldap_account = get_ldap_account_safely(user) if ldap_account.synchronized: self.stdout.write(self.style.SUCCESS(' Success!')) successful = successful + 1 else: self.stdout.write(self.style.ERROR(' Error')) self.stdout.write(self.style.NOTICE(ldap_account.ldap_error_message)) failed = failed + 1 self.stdout.write("{}/{} accounts synchronized to LDAP, {} failures".format(successful, total, failed)) else: self.stdout.write("No accounts synchronized, to force synchronization use the 'force' argument")
def user_post_save(**kwargs): """ Update user's LDAP account. """ user = kwargs['instance'] update_ldap_account(user, create=True)