forked from kobotoolbox/kpi
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add management command
- Loading branch information
Showing
3 changed files
with
29 additions
and
3 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
kpi/management/commands/grant_default_permissions_per_user.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import sys | ||
from optparse import make_option | ||
from django.core.management.base import BaseCommand | ||
from django.contrib.auth.models import User | ||
from kpi.utils.permissions import grant_default_model_level_perms | ||
|
||
|
||
class Command(BaseCommand): | ||
def add_arguments(self, parser): | ||
parser.add_argument('--username', | ||
action='store', | ||
dest='username', | ||
default=False, | ||
help="Add username i.e --username <username>") | ||
|
||
def handle(self, *args, **options): | ||
username = options.get('username') | ||
if username: | ||
users = User.objects.filter(username=username) | ||
if users: | ||
grant_default_model_level_perms(users[0]) | ||
sys.stdout.write("done") | ||
else: | ||
sys.stdout.write("user does not exist") | ||
else: | ||
sys.stdout.write("please provide a username") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters