Revision 5ce3ce4f snf-astakos-app/astakos/im/management/commands/group_add.py
b/snf-astakos-app/astakos/im/management/commands/group_add.py | ||
---|---|---|
37 | 37 |
|
38 | 38 |
from ._common import add_group_permission |
39 | 39 |
|
40 |
|
|
40 | 41 |
class Command(BaseCommand): |
41 | 42 |
args = "<groupname> [<permission> ...]" |
42 | 43 |
help = "Insert group" |
43 |
|
|
44 |
|
|
44 | 45 |
def handle(self, *args, **options): |
45 | 46 |
if len(args) < 1: |
46 | 47 |
raise CommandError("Invalid number of arguments") |
47 |
|
|
48 |
|
|
48 | 49 |
name = args[0].decode('utf8') |
49 |
|
|
50 |
|
|
50 | 51 |
try: |
51 | 52 |
AstakosGroup.objects.get(name=name) |
52 | 53 |
raise CommandError("A group with this name already exists") |
... | ... | |
59 | 60 |
for pname in args[1:]: |
60 | 61 |
r, created = add_group_permission(group, pname) |
61 | 62 |
if created: |
62 |
self.stdout.write('Permission: %s created successfully\n' % pname) |
|
63 |
self.stdout.write( |
|
64 |
'Permission: %s created successfully\n' % pname) |
|
63 | 65 |
if r == 0: |
64 |
self.stdout.write('Group has already permission: %s\n' % pname) |
|
66 |
self.stdout.write( |
|
67 |
'Group has already permission: %s\n' % pname) |
|
65 | 68 |
else: |
66 |
self.stdout.write('Permission: %s added successfully\n' % pname) |
|
69 |
self.stdout.write( |
|
70 |
'Permission: %s added successfully\n' % pname) |
|
67 | 71 |
except Exception, e: |
68 |
raise CommandError(e) |
|
72 |
raise CommandError(e) |
Also available in: Unified diff