Skip to content

Commit

Permalink
Make default color for django.ImageField random
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSuperiorStanislav committed Aug 16, 2024
1 parent d6349de commit f93e7dc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.pyc
*.pyo
.idea/
.venv/

# Build-related files
docs/_build/
Expand Down
7 changes: 5 additions & 2 deletions factory/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import logging
import os
import warnings
import random
from typing import Dict, TypeVar

from django.contrib.auth.hashers import make_password
Expand Down Expand Up @@ -258,11 +259,13 @@ class ImageField(FileField):
def _make_data(self, params):
# ImageField (both django's and factory_boy's) require PIL.
# Try to import it along one of its known installation paths.
from PIL import Image
from PIL import Image, ImageColor

width = params.get('width', 100)
height = params.get('height', width)
color = params.get('color', 'blue')
color = params.get('color', random.choice( # noqa: S311
list(ImageColor.colormap.keys()),
))
image_format = params.get('format', 'JPEG')
image_palette = params.get('palette', 'RGB')

Expand Down

0 comments on commit f93e7dc

Please sign in to comment.