Skip to content

Commit

Permalink
Merge pull request #6342 from smithellis/2021-500-error-group-avatar
Browse files Browse the repository at this point in the history
2021 - 500 Error after submission with no file
  • Loading branch information
akatsoulas authored Nov 13, 2024
2 parents 137dbd8 + 69ad9af commit befa48d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions kitsune/groups/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,24 @@ def __init__(self, *args, **kwargs):
size=settings.AVATAR_SIZE
)

class Meta(object):
class Meta:
model = GroupProfile
fields = ["avatar"]

def clean_avatar(self):
if not ("avatar" in self.cleaned_data and self.cleaned_data["avatar"]):
return self.cleaned_data["avatar"]
avatar = self.cleaned_data.get("avatar")

# Ensure an avatar file is attached
if not avatar:
raise forms.ValidationError(_("An avatar image is required."))

# Validate file size
try:
check_file_size(self.cleaned_data["avatar"], settings.MAX_AVATAR_FILE_SIZE)
check_file_size(avatar, settings.MAX_AVATAR_FILE_SIZE)
except FileTooLargeError as e:
raise forms.ValidationError(e.args[0])
return self.cleaned_data["avatar"]

return avatar


USERS_PLACEHOLDER = _lazy("username")
Expand Down

0 comments on commit befa48d

Please sign in to comment.