From 12c3c4cc2d7fa346c2cd8ea2c9f7d3f740d7a60f Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Sun, 11 Mar 2012 20:26:57 -0400 Subject: [PATCH] Extract complete user info into a json file --- student/management/commands/userinfo.py | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 student/management/commands/userinfo.py diff --git a/student/management/commands/userinfo.py b/student/management/commands/userinfo.py new file mode 100644 index 0000000000..72b4d2ebd6 --- /dev/null +++ b/student/management/commands/userinfo.py @@ -0,0 +1,38 @@ +import os.path + +from lxml import etree + +from django.core.management.base import BaseCommand +from django.conf import settings +from django.contrib.auth.models import User + +import mitxmako.middleware as middleware +import json + +from student.models import UserProfile + +middleware.MakoMiddleware() + +class Command(BaseCommand): + help = \ +''' Extract full user information into a JSON file. +Pass a single filename.''' + def handle(self, *args, **options): + f = open(args[0],'w') + #text = open(args[0]).read() + #subject = open(args[1]).read() + users = User.objects.all() + + l = [] + for user in users: + up = UserProfile.objects.get(user = user) + d = { 'username':user.username, + 'email':user.email, + 'is_active':user.is_active, + 'joined':user.date_joined.isoformat(), + 'name':up.name, + 'language':up.language, + 'location':up.location} + l.append(d) + json.dump(l,f) + f.close()