import script: Delete medium sized avatars if it exists.

Deletion of medium sized image is done if it exists before calling the
function 'ensure_medium_avatar_image', to avoid potentially confusing
problems with left-over medium-size avatar images from a previous run
being used when repeatedly importing the same realm in a development
environment..

Fixes #8949.
This commit is contained in:
Rhea Parekh 2018-04-07 19:46:51 +05:30 committed by Tim Abbott
parent c63d1c9205
commit ed7127c8b4
1 changed files with 9 additions and 1 deletions

View File

@ -1461,7 +1461,15 @@ def import_uploads_local(import_dir: Path, processing_avatars: bool=False,
for record in records:
if record['s3_path'].endswith('.original'):
user_profile = get_user_profile_by_id(record['user_profile_id'])
# If medium sized avatar does not exist, this creates it using the original image
avatar_path = user_avatar_path_from_ids(user_profile.id, record['realm_id'])
medium_file_path = os.path.join(settings.LOCAL_UPLOADS_DIR, "avatars",
avatar_path) + '-medium.png'
if os.path.exists(medium_file_path):
# We remove the image here primarily to deal with
# issues when running the import script multiple
# times in development (where one might reuse the
# same realm ID from a previous iteration).
os.remove(medium_file_path)
upload_backend.ensure_medium_avatar_image(user_profile=user_profile)
def import_uploads_s3(bucket_name: str, import_dir: Path, processing_avatars: bool=False,