Add command to seed forum permissions to existing users
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
"""
|
||||
This must be run only after seed_permissions_roles.py!
|
||||
|
||||
Creates default roles for all users currently in the database. Just runs through
|
||||
Enrollments.
|
||||
"""
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
from student.models import CourseEnrollment
|
||||
from django_comment_client.permissions import assign_default_role
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
args = 'course_id'
|
||||
help = 'Seed default permisssions and roles'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
if len(args) != 0:
|
||||
raise CommandError("This Command takes no arguments")
|
||||
|
||||
print "Updated roles for ",
|
||||
for i, enrollment in enumerate(CourseEnrollment.objects.all(), start=1):
|
||||
assign_default_role(None, enrollment)
|
||||
if i % 1000 == 0:
|
||||
print "{0}...".format(i),
|
||||
print
|
||||
Reference in New Issue
Block a user