def run(): profiles = Profile.objects.all() users = User.objects.all() for profile in profiles: try: profile.user except User.DoesNotExist: print( Colorizer.Red('User doesnt exist for profile with ID : ' + str(profile.id))) profile.delete() print(Colorizer.Cyan('Removing profile')) for user in users: try: user.profile except Profile.DoesNotExist: print( Colorizer.Red('Profile doesnt exist for user ID: ' + str(user.id) + ', EMAIL: ' + user.email)) user.delete() print(Colorizer.Cyan('Removing user with EMAIL: ' + user.email))
def user_sync_template(callback=lambda x: x, args=[]): errored = [] profiles = Profile.objects.filter(user__email=args[0]) \ if len(args) > 0 \ else Profile.objects.all() print(' ') print(Colorizer.Yellow('############ START UPDATING ###########')) print(' ') for k, profile in enumerate(profiles): counter = '(' + str(k) + ' of ' + str(len(profiles)) + ')' results = callback(profile) if results is not True: print( Colorizer.Red(counter + 'UPDATE ERROR : ' + profile.user.email)) [print(' ' + line) for line in str(results['error']).split('\n')] errored.append(results) else: print( Colorizer.Cyan(counter) + '' + Colorizer.Green('User updated: ') + profile.user.email) print(Colorizer.Yellow(' ')) print(Colorizer.Yellow('############### RESULTS ###############')) print('') print( Colorizer.Green( str(len(profiles) - len(errored)) + ' USERS WAS SUCCESFULLY UPDATED')) print(' ') print(Colorizer.Red(str(len(errored)) + ' USERS WITH ERRORS')) for error in errored: print(' ') print(' ' + Colorizer.Red(error['user'].email + ' - UUID: ' + str(error['user'].id))) print(' | EXCEPTION: ') [print(' | ' + line) for line in str(error['error']).split('\n')] print(Colorizer.Yellow(' ')) print(Colorizer.Yellow('#######################################'))