Files
edx-platform/common/djangoapps/student/management/commands/userinfo.py
stv 11020cf115 Fix Pylint: C0103: (invalid-name)
Command.handle: Invalid name "d" for type variable
(should match [a-z_][a-z0-9_]{2,30}$)
2014-11-24 20:48:05 -05:00

32 lines
944 B
Python

from django.core.management.base import BaseCommand
from django.contrib.auth.models import User
import json
from student.models import UserProfile
class Command(BaseCommand):
help = """Extract full user information into a JSON file.
Pass a single filename."""
def handle(self, *args, **options):
file_output = open(args[0], 'w')
users = User.objects.all()
data_list = []
for user in users:
profile = UserProfile.objects.get(user=user)
data = {
'username': user.username,
'email': user.email,
'is_active': user.is_active,
'joined': user.date_joined.isoformat(),
'name': profile.name,
'language': profile.language,
'location': profile.location,
}
data_list.append(data)
json.dump(data_list, file_output)
file_output.close()