Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#29560 closed New feature (fixed)

Add an option to django-admin to always colorize output

Reported by: Nicolas Noé Owned by: Hasan Ramezani
Component: Core (Management commands) Version: dev
Severity: Normal Keywords:
Cc: Carlton Gibson Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

With Django management commands, it is currently possible disable colors with the --no-colors flag.

What I'd like to have is basically the other side of the coin: a --force-colors flag that instructs Django to output ANSI color sequences in cases it would disable colors by default (typically, when the output is piped to another command, as documented).

My real world use-case is the following one: I have a custom Django command to import data. I run this command myself, and I'd like to send a colored log (HTML seems perfect for this) to the data curators. I can use the https://github.com/theZiz/aha utility for this, but that doesn't work since Django disable colors when the output is piped.

Other *nix commands have a special flag for this exact use-case, for example $ ls --color=always

Change History (9)

comment:1 by Carlton Gibson, 6 years ago

Cc: Carlton Gibson added
Triage Stage: UnreviewedAccepted
Type: UncategorizedNew feature

Hi Nicolas. I'm going to Accept this: it seems reasonable.

…in cases it would disable colors by default (typically, when the output is piped to another command, as documented).

Can I ask, where is this documented? I cannot seem to find it. Thanks.

comment:2 by Nicolas Noé, 6 years ago

Thanks Carlton!

It is documented in https://docs.djangoproject.com/en/2.0/ref/django-admin/#syntax-coloring:

The django-admin / manage.py commands will use pretty color-coded output if your terminal supports ANSI-colored output. It won’t use the color codes if you’re piping the command’s output to another program.

comment:3 by Carlton Gibson, 6 years ago

Thanks Nicolas. I just found that. (I must have been blind: I even looked in that exact location... sigh :-)

comment:4 by Nicolas Noé, 6 years ago

Owner: changed from nobody to Nicolas Noé
Status: newassigned

comment:5 by Nicolas Noé, 6 years ago

Owner: Nicolas Noé removed
Status: assignednew

I unfortunately can't find time in the short term to work on the implementation...

comment:6 by Hasan Ramezani, 6 years ago

Has patch: set
Owner: set to Hasan Ramezani
Status: newassigned

comment:7 by Carlton Gibson, 6 years ago

Triage Stage: AcceptedReady for checkin

This looks good to me. (I had a couple of tiny comment which I assume will be addressed, so progressing.) Thanks Hasan.

comment:8 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In 5195b99e:

Fixed #29560 -- Added --force-color management command option.

comment:9 by Tim Graham <timograham@…>, 6 years ago

In a4d8e412:

Refs #29560 -- Fixed typo in django/core/management/base.py.

Note: See TracTickets for help on using tickets.
Back to Top