Opened 15 years ago
Closed 11 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:
- Add field "default_label" to LabelCommand with value "None"
- 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)
Change History (9)
by , 15 years ago
Attachment: | LabelCommand_default_label.diff added |
---|
comment:1 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 15 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 , 15 years ago
milestone: | 1.2 |
---|
1.2 is feature-frozen, moving this feature request off the milestone.
comment:4 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → New feature |
comment:5 by , 14 years ago
Needs documentation: | set |
---|---|
Needs tests: | set |
comment:8 by , 11 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
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.
patch against SVN