Refactor UserProfilePhotoForm to strip leading period from file extension

This commit is contained in:
Kenneth Reitz
2024-03-25 16:45:15 -04:00
parent c2f8465c09
commit ea025f812c

View File

@@ -123,8 +123,11 @@ class UserProfilePhotoForm(forms.ModelForm):
if self.cleaned_data.get("image"):
new_image = self.cleaned_data["image"]
_, file_extension = os.path.splitext(new_image.name)
new_image.name = f"{user.profile_image_filename_root}.{file_extension}"
# Strip the leading period from the file extension.
file_extension = file_extension.lstrip(".")
new_image.name = f"{user.profile_image_filename_root}.{file_extension}"
user.image = new_image
if commit: