aboutsummaryrefslogtreecommitdiffstats
path: root/modules/django_application/files
diff options
context:
space:
mode:
authorMichael Scherer <misc@mageia.org>2011-02-25 18:25:50 +0000
committerMichael Scherer <misc@mageia.org>2011-02-25 18:25:50 +0000
commitb767eefb55422562ac93a80552c40ad59f21073b (patch)
treea8407ca2a324b0eda85854c9fdb1eb6d36805787 /modules/django_application/files
parent2921ceb98adb19c97a9687637adfd697965e4570 (diff)
downloadpuppet-b767eefb55422562ac93a80552c40ad59f21073b.tar
puppet-b767eefb55422562ac93a80552c40ad59f21073b.tar.gz
puppet-b767eefb55422562ac93a80552c40ad59f21073b.tar.bz2
puppet-b767eefb55422562ac93a80552c40ad59f21073b.tar.xz
puppet-b767eefb55422562ac93a80552c40ad59f21073b.zip
give a better warning when the permission is not unique
Diffstat (limited to 'modules/django_application/files')
-rw-r--r--modules/django_application/files/django_add_permission_to_group.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/modules/django_application/files/django_add_permission_to_group.py b/modules/django_application/files/django_add_permission_to_group.py
index 4e5714f3..5c3c915f 100644
--- a/modules/django_application/files/django_add_permission_to_group.py
+++ b/modules/django_application/files/django_add_permission_to_group.py
@@ -9,12 +9,16 @@ if len(sys.argv) > 3:
app = sys.argv[3]
from django.contrib.auth.models import Group, Permission
-g = Group.objects.get(name=group_name)
+group = Group.objects.get(name=group_name)
-p = Permission.objects.filter(codename=permission)
+permissions = Permission.objects.filter(codename=permission)
if app:
- p = p.filter(content_type__app_label__exact=app)
-p = p[0]
+ permissions = permissions.filter(content_type__app_label__exact=app)
-g.permissions.add(p)
-g.save()
+if len(permissions) != 1:
+ print "Error, result not unique, please give the application among :"
+ print ' '.join([p.content_type.app_label for p in permissions])
+ sys.exit(1)
+
+group.permissions.add(permissions[0])
+group.save()