/[adm]/puppet/modules/django_application/files/django_add_permission_to_group.py
ViewVC logotype

Contents of /puppet/modules/django_application/files/django_add_permission_to_group.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1211 - (show annotations) (download) (as text)
Fri Feb 25 18:25:50 2011 UTC (13 years, 2 months ago) by misc
File MIME type: text/x-python
File size: 675 byte(s)
give a better warning when the permission is not unique
1 #!/usr/bin/python
2 import sys
3 group_name = sys.argv[1]
4 permission = sys.argv[2]
5
6 # as codename is not unique, we need to give the application name
7 app = ''
8 if len(sys.argv) > 3:
9 app = sys.argv[3]
10
11 from django.contrib.auth.models import Group, Permission
12 group = Group.objects.get(name=group_name)
13
14 permissions = Permission.objects.filter(codename=permission)
15 if app:
16 permissions = permissions.filter(content_type__app_label__exact=app)
17
18 if len(permissions) != 1:
19 print "Error, result not unique, please give the application among :"
20 print ' '.join([p.content_type.app_label for p in permissions])
21 sys.exit(1)
22
23 group.permissions.add(permissions[0])
24 group.save()

  ViewVC Help
Powered by ViewVC 1.1.30