1 from django.core.management.base import BaseCommand, AppCommand
2 from optparse import make_option
3 from django.contrib.auth.models import Group
4 from madrona.common.utils import enable_sharing
5
7 help = "Configures the permissions to allow sharing between groups"
8 args = '[Group names to grant sharing permissions to ...]'
9
10 option_list = BaseCommand.option_list + (
11 make_option('-a', '--all', action='store_true', dest='all',
12 help="Enable sharing for ALL current groups"),
13 )
14
15 - def handle(self, *groupnames, **options):
16 self.all = options.get('all', False)
17
18 if self.all:
19 print "Enabling sharing for all groups..."
20 enable_sharing()
21 gs = Group.objects.all()
22 for g in gs:
23 enable_sharing(g)
24 print " [DONE]", g.name
25 return
26
27 if len(groupnames) > 0:
28 print "Enabling sharing for %s groups.." % len(groupnames)
29 enable_sharing()
30 for gname in groupnames:
31 try:
32 g = Group.objects.get(name=gname)
33 enable_sharing(g)
34 print " [DONE]", gname
35 except Exception as e:
36 print " [FAILED]", gname
37 print " ",e
38 return
39
40 enable_sharing()
41 print """
42 The site is now configured to allow sharing.
43 For a group to share features, you must grant this permission explictly to group:
44
45 $ python manage.py enable_sharing GroupName "Group Name with Spaces"
46
47 OR to grant sharing permissions to all groups:
48
49 $ python manage.py enable_sharing --all
50 """
51