Projet

Général

Profil

0007-dj22-disable-subparsers-work-around-51516.patch

Benjamin Dauvergne, 01 mars 2021 15:06

Télécharger (2 ko)

Voir les différences:

Subject: [PATCH 7/9] dj22: disable subparsers work around (#51516)

 .../management/commands/rsu-duplicates.py           | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
zoo/zoo_nanterre/management/commands/rsu-duplicates.py
21 21
from decimal import Decimal
22 22
import datetime
23 23

  
24
import django
24 25
from django.core.management.base import BaseCommand, CommandParser
25 26
from django.utils.six import python_2_unicode_compatible
26 27
from django.utils.timezone import now
......
68 69
    def add_arguments(self, parser):
69 70
        cmd = self
70 71

  
71
        class SubParser(CommandParser):
72
            def __init__(self, **kwargs):
73
                super(SubParser, self).__init__(cmd, **kwargs)
72
        if django.VERSION < (2, 1):
73
            # https://stackoverflow.com/questions/36706220/is-it-possible-to-create-subparsers-in-a-django-management-command
74
            class SubParser(CommandParser):
75
                def __init__(self, **kwargs):
76
                    super(SubParser, self).__init__(cmd, **kwargs)
74 77

  
75
        subparser = parser.add_subparsers(dest='command', help='commands', parser_class=SubParser)
78
            subparser = parser.add_subparsers(dest='command', help='commands', parser_class=SubParser)
79
        else:
80
            subparser = parser.add_subparsers(title='subcommands', dest='command', required=True)
76 81
        find_parser = subparser.add_parser('find', help='find duplicates')
77 82
        find_parser.add_argument('--count', type=int, help='search last count persons created',
78 83
                                 default=None)
79
-