Opened 15 years ago

Closed 10 years ago

#11590 closed New feature (wontfix)

REQUEST: Give LabelCommand an option for default behavior (when no labels are specified)

Reported by: maaku Owned by: nobody
Component: Core (Management commands) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The LabelCommand class is handy, but I've found circumstances where I need a default behavior when no labels are specified on the command line. For example, when specifying directories os.getcwd() provides a reasonable default and a convenient shorthand. Unless I missed something, implementing these commands required reimplementing LabelCommand.handle with the default hard coded in. Obviously violates DRY.

Suggestion:

  1. Add field "default_label" to LabelCommand with value "None"
  2. Switch (line 317-318 in django/trunk/django/core/management/base.py)
if not labels:
    raise CommandError('Enter at least one %s.' % self.label)

to

if not labels:
    if not self.default_label
        raise CommandError('Enter at least one %s.' % self.label)
    else:
        labels = [self.default_label]

or something similar.

Patch is attached.

Attachments (1)

LabelCommand_default_label.diff (692 bytes ) - added by maaku 15 years ago.
patch against SVN

Download all attachments as: .zip

Change History (9)

by maaku, 15 years ago

patch against SVN

comment:1 by Alex Gaynor, 15 years ago

Triage Stage: UnreviewedAccepted

comment:2 by maaku, 14 years ago

Checking in on the status of this patch...

The ticket was accepted 3 months ago, it has a patch, and does not need further improvement, documentation, or tests. However it is still not in SVN. Forgive my ignorance, but is there anything I need to do to move this along?

comment:3 by James Bennett, 14 years ago

milestone: 1.2

1.2 is feature-frozen, moving this feature request off the milestone.

comment:4 by Julien Phalip, 13 years ago

Severity: Normal
Type: New feature

comment:5 by Julien Phalip, 13 years ago

Needs documentation: set
Needs tests: set

comment:6 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:7 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:8 by Claude Paroz, 10 years ago

Resolution: wontfix
Status: newclosed

Considering the time this ticket is open without anyone adding tests and documentation, I'll close it as won't fix. As for me, inheriting from BaseCommand and implementing your custom code is the way to go.

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