def forwards(self, orm): """Rename and randomize existing avatars.""" for userprofile in orm["users.UserProfile"].objects.exclude(photo=""): new_filename = _calculate_photo_filename(None, None) new_full_path = os.path.join(settings.MEDIA_ROOT, new_filename) try: shutil.move(userprofile.photo.path, new_full_path) except IOError, exp: logger.error("Error renaming avatar for user '%s': %s" % (userprofile.user.username, exp)) userprofile.photo.name = new_filename userprofile.save()
def forwards(self, orm): """Rename and randomize existing avatars.""" for userprofile in orm['users.UserProfile'].objects.exclude(photo=''): new_filename = _calculate_photo_filename(None, None) new_full_path = os.path.join(settings.MEDIA_ROOT, new_filename) try: shutil.move(userprofile.photo.path, new_full_path) except IOError, exp: logger.error("Error renaming avatar for user '%s': %s" % (userprofile.user.username, exp)) userprofile.photo.name = new_filename userprofile.save()
def test_base(self, uuid4_mock): result = _calculate_photo_filename(None, '') ok_(result.endswith('.jpg')) ok_(result.startswith(settings.USER_AVATAR_DIR)) ok_(uuid4_mock.called)