mirror of
https://github.com/jointakahe/takahe.git
synced 2024-11-14 03:11:46 +00:00
Fix emoji file size validation and help text and add image size validation (#410)
This commit is contained in:
parent
3679448cdf
commit
71ab6b98a6
1 changed files with 9 additions and 3 deletions
|
@ -49,13 +49,19 @@ class EmojiCreate(FormView):
|
|||
help_text="What users type to use the emoji :likethis:",
|
||||
)
|
||||
image = forms.ImageField(
|
||||
help_text="The emoji image\nShould be at least 40 x 40 pixels, and under 50kb",
|
||||
help_text=f"The emoji image\nShould be at least 40 x 40 pixels, and under {settings.SETUP.EMOJI_MAX_IMAGE_FILESIZE_KB}KB",
|
||||
)
|
||||
|
||||
def clean_image(self):
|
||||
data = self.cleaned_data["image"]
|
||||
if data.size > settings.SETUP.EMOJI_MAX_IMAGE_FILESIZE_KB:
|
||||
raise forms.ValidationError("Image filesize is too large")
|
||||
if data.size > settings.SETUP.EMOJI_MAX_IMAGE_FILESIZE_KB * 1024:
|
||||
raise forms.ValidationError(
|
||||
f"Image filesize is too large (actual: {data.size // 1024}KB)"
|
||||
)
|
||||
if data.image.width < 40 or data.image.height < 40:
|
||||
raise forms.ValidationError(
|
||||
f"Image should at least 40 x 40 pixels (actual: {data.image.width} x {data.image.height} pixels)"
|
||||
)
|
||||
return data
|
||||
|
||||
def form_valid(self, form):
|
||||
|
|
Loading…
Reference in a new issue