Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make default color for django.ImageField random #1086

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -8,6 +8,7 @@
import io
import logging
import os
import random
import warnings
from typing import Dict, TypeVar

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