Skip to content

Commit ca0d321

Browse files
committed
v1.3.8
1 parent 80fc9f6 commit ca0d321

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

rdgenerator/forms.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,24 @@ class GenerateForm(forms.Form):
8282
def clean_iconfile(self):
8383
print("checking icon")
8484
image = self.cleaned_data['iconfile']
85-
try:
86-
# Open the image using Pillow
87-
img = Image.open(image)
85+
if image:
86+
try:
87+
# Open the image using Pillow
88+
img = Image.open(image)
8889

89-
# Check if the image is a PNG (optional, but good practice)
90-
if img.format != 'PNG':
91-
raise forms.ValidationError("Only PNG images are allowed.")
90+
# Check if the image is a PNG (optional, but good practice)
91+
if img.format != 'PNG':
92+
raise forms.ValidationError("Only PNG images are allowed.")
9293

93-
# Get image dimensions
94-
width, height = img.size
94+
# Get image dimensions
95+
width, height = img.size
9596

96-
# Check for square dimensions
97-
if width != height:
98-
raise forms.ValidationError("Custom App Icon dimensions must be square.")
99-
100-
return image
101-
except OSError: # Handle cases where the uploaded file is not a valid image
102-
raise forms.ValidationError("Invalid icon file.")
103-
except Exception as e: # Catch any other image processing errors
104-
raise forms.ValidationError(f"Error processing icon: {e}")
97+
# Check for square dimensions
98+
if width != height:
99+
raise forms.ValidationError("Custom App Icon dimensions must be square.")
100+
101+
return image
102+
except OSError: # Handle cases where the uploaded file is not a valid image
103+
raise forms.ValidationError("Invalid icon file.")
104+
except Exception as e: # Catch any other image processing errors
105+
raise forms.ValidationError(f"Error processing icon: {e}")

0 commit comments

Comments
 (0)