Projet

Général

Profil

0002-creating-groups-command.patch

Serghei Mihai, 17 décembre 2014 15:42

Télécharger (1,38 ko)

Voir les différences:

Subject: [PATCH 2/3] creating groups command

 authentic2/management/commands/create-group.py | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100644 authentic2/management/commands/create-group.py
authentic2/management/commands/create-group.py
1
from optparse import make_option
2
import logging
3

  
4
from django.contrib.auth.models import Group
5
from django.core.management.base import BaseCommand, CommandError
6

  
7
from django.conf import settings
8

  
9
class Command(BaseCommand):
10
    help = '''Creates a group'''
11
    option_list = BaseCommand.option_list + (
12
        make_option("--ignore-existing", action='store_true',
13
                    help='ignore existing groups',
14
                    default=False),
15
    )
16

  
17
    def handle(self, *groups, **options):
18
        for group_name in groups:
19
            if Group.objects.filter(name=group_name).exists() and not options['ignore_existing']:
20
                raise CommandError('The group %s already exists' % group_name)
21
            Group.objects.create(name=group_name)
0
-