Commit 666828f7 by John Jarvis

Command for certificate whitelist

parent 7e033d02
from django.core.management.base import BaseCommand, CommandError
import os
from optparse import make_option
from student.models import UserProfile
from certificates.models import CertificateWhitelist
from django.contrib.auth.models import User
class Command(BaseCommand):
help = """
......@@ -16,12 +15,12 @@ class Command(BaseCommand):
$ ... cert_whitelist --add joe -c "MITx/6.002x/2012_Fall"
Remove a user from the whitelist for a course
$ ... cert_whitelist --del joe -c "MITx/6.002x/2012_Fall"
Print out who is whitelisted for a course
$ ... cert_whitelist -c "MITx/6.002x/2012_Fall"
$ ... cert_whitelist -c "MITx/6.002x/2012_Fall"
"""
......@@ -37,7 +36,7 @@ class Command(BaseCommand):
dest='del',
default=False,
help='user to remove from the certificate whitelist'),
make_option('-c', '--course-id',
metavar='COURSE_ID',
dest='course_id',
......@@ -50,7 +49,7 @@ class Command(BaseCommand):
if not course_id:
raise CommandError("You must specify a course-id")
if options['add'] and options['del']:
raise CommandError("Either remove or add a user, not both")
raise CommandError("Either remove or add a user, not both")
if options['add'] or options['del']:
user_str = options['add'] or options['del']
......@@ -59,8 +58,9 @@ class Command(BaseCommand):
else:
user = User.objects.get(username=user_str)
cert_whitelist, created = CertificateWhitelist.objects.get_or_create(
user=user, course_id=course_id)
cert_whitelist, created = \
CertificateWhitelist.objects.get_or_create(
user=user, course_id=course_id)
if options['add']:
cert_whitelist.whitelist = True
elif options['del']:
......@@ -68,6 +68,7 @@ class Command(BaseCommand):
cert_whitelist.save()
whitelist = CertificateWhitelist.objects.all()
print "User whitelist for course {0}:\n{1}".format(course_id,
'\n'.join([ "{0} {1} {2}".format(u.user.username, u.user.email, u.whitelist) for u in whitelist]))
print "User whitelist for course {0}:\n{1}".format(course_id,
'\n'.join(["{0} {1} {2}".format(
u.user.username, u.user.email, u.whitelist)
for u in whitelist]))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment