зеркало из https://github.com/mozilla/kitsune.git
Merge pull request #6342 from smithellis/2021-500-error-group-avatar
2021 - 500 Error after submission with no file
This commit is contained in:
Коммит
befa48d3e6
|
@ -29,18 +29,24 @@ class GroupAvatarForm(forms.ModelForm):
|
|||
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")
|
||||
|
|
Загрузка…
Ссылка в новой задаче