'''
This module will retrieve info about students registered in the course

Usage:

python user_info.py

'''

from collections import defaultdict

from base_edx import EdXConnection
from generate_csv_report import CSV 

connection = EdXConnection('certificates_generatedcertificate', 'auth_userprofile')
collection = connection.get_access_to_collection()

documents = collection[].find()

result = []

for document in documents:
    user_id = document['id']
    final_grade = collection['certificates_generatedcertificate'].find_one({'id' : user_id})['grade']
    result.append([user_id, document['name'], final_grade, document['gender'], document['year_of_birth'], document['level_of_education'], document['country'], document['city']])
    




@@ -372,16 +372,34 @@
 lection%5B
+'auth_userprofile'
 %5D.find()
@@ -468,13 +468,31 @@
 nt%5B'
-id'%5D%0A
+user_id'%5D%0A    try:%0A    
     
@@ -564,16 +564,21 @@
 d_one(%7B'
+user_
 id' : us
@@ -594,16 +594,50 @@
 grade'%5D%0A
+    except:%0A        print user_id%0A
     resu
@@ -811,11 +811,196 @@
 %5D)%0A    %0A
-%0A%0A
+output = CSV(result, %5B'User ID','Username', 'Final Grade', 'Gender', 'Year of Birth', 'Level of Education', 'Country', 'City'%5D, output_file='atoc185x_user_info.csv')%0Aoutput.generate_csv()
 %0A

Update user_info.py