forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request openedx#850 from MITx/feature/jarv/staff-account
Adding django-admin/rake command to set the staff bit
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
common/djangoapps/student/management/commands/set_staff.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,37 @@ | ||
from django.contrib.auth.models import User | ||
from django.core.management.base import BaseCommand, CommandError | ||
import re | ||
|
||
|
||
class Command(BaseCommand): | ||
|
||
args = '<user/email user/email ...>' | ||
help = """ | ||
This command will set isstaff to true for one or more users. | ||
Lookup by username or email address, assumes usernames | ||
do not look like email addresses. | ||
""" | ||
|
||
def handle(self, *args, **kwargs): | ||
|
||
if len(args) < 1: | ||
print Command.help | ||
return | ||
|
||
for user in args: | ||
|
||
if re.match('[^@]+@[^@]+\.[^@]+', user): | ||
try: | ||
v = User.objects.get(email=user) | ||
except: | ||
raise CommandError("User {0} does not exist".format( | ||
user)) | ||
else: | ||
try: | ||
v = User.objects.get(username=user) | ||
except: | ||
raise CommandError("User {0} does not exist".format( | ||
user)) | ||
|
||
v.is_staff = True | ||
v.save() |
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