Allow `color_style()` and `parse_color_setting()` to be used with custom colour palettes.
|Reported by:||mrmachine||Owned by:||nobody|
|Component:||Core (Management commands)||Version:||master|
|Severity:||Normal||Keywords:||management command customize color roles|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
I want to add new roles and change the default terminal colours that ship with Django, for use in my own project's management commands, but I want to retain the ability for these to be overridden with a DJANGO_COLORS environment variable. I also don't want to repeat myself by copying the entire color_style() and parse_color_setting() functions, which are hard coded to use django.utils.termcolor.PALETTES and which ignore any roles specified in DJANGO_COLORS which are not also present in django.utils.termcolors.PALETTES[NOCOLOR_PALETTE].
It turns out that it's fairly trivial to add a palettes argument to both functions, which will allow me to simply define my own dictionary of palettes somewhere (or import and extend the ones that ship with Django) and then call color_style(my_palettes) to get a style object with roles and default colours that are appropriate for my project, and also retain the ability for users to customise the colours for my roles with a DJANGO_COLORS environment variable.
Change History (8)
comment:1 Changed 5 years ago by mrmachine
- Component changed from Uncategorized to django-admin.py
- Keywords management command customize color roles added
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Version changed from 1.1 to SVN