From 3cdd2353d6bc9150477f4b09bf251d89c2dbdbaf Mon Sep 17 00:00:00 2001 From: Serghei MIHAI Date: Fri, 12 Dec 2014 15:19:29 +0100 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 diff --git a/authentic2/management/commands/create-group.py b/authentic2/management/commands/create-group.py new file mode 100644 index 0000000..04e9a35 --- /dev/null +++ b/authentic2/management/commands/create-group.py @@ -0,0 +1,21 @@ +from optparse import make_option +import logging + +from django.contrib.auth.models import Group +from django.core.management.base import BaseCommand, CommandError + +from django.conf import settings + +class Command(BaseCommand): + help = '''Creates a group''' + option_list = BaseCommand.option_list + ( + make_option("--ignore-existing", action='store_true', + help='ignore existing groups', + default=False), + ) + + def handle(self, *groups, **options): + for group_name in groups: + if Group.objects.filter(name=group_name).exists() and not options['ignore_existing']: + raise CommandError('The group %s already exists' % group_name) + Group.objects.create(name=group_name) -- 2.1.3