Example #1
0
def workspace(request, wid):
    if request.method == "GET":
        ws = get_document_or_404(Workspace,id=wid)
        jsonstr = documents_to_json(ws)
        return HttpResponse(jsonstr, mimetype="application/json")
    elif request.method == "POST":
        return create_workspace(request)
Example #2
0
def fetch_one_user(request, attr, id, retformat=""):
    context = {}
    filter = { attr : id }
    user = get_document_or_404(User, **filter)
    if retformat == 'json':
        context['json'] = documents_to_json(user)
        return render(request, 'data_app/json_template', context)
    context["retformat"] = retformat
    context["attribute"] = attr
    context["id"] = id
    context["user"] = user
    return render(request, 'data_app/one_user.html', context)
Example #3
0
def fetch_workspace_users(request, wid):
    ws = get_document_or_404(Workspace, id=wid)
    rcpids = ws.owners
    users = User.objects(rcpid__in=rcpids).exclude("courses")
    jsonstr = documents_to_json(users)
    return HttpResponse(jsonstr, mimetype="application/json")
Example #4
0
def workspace_table_data(wid):
    """
        Collate and return a workspace's data as a list of rows.
        Each row starts with the person's id.
    """
    ws = get_document_or_404(Workspace, id=wid)
    students = all_workspace_students(ws)
    #gradebooks = Gradebook.objects(id__in=ws.gradebooks)
    gradebooks = Gradebook.objects(sections__in=ws.rosters)
    uploads = UserSubmittedData.objects(workspaces__contains=wid)
    courses = CourseData.objects(sections__in=ws.rosters)
    rcpids = [s.rcpid for s in students]
    
    studentdata = {}
    gradebookdata = {}
    uploaddata = {}
    coursedata = {}

    doGrades = (len(gradebooks) > 0)
    doUploads = (len(uploads) > 0)
    doCourses = (len(courses) > 0)

    userheaders = included_user_fields()
    studentdata = student_data_table(students)

    if doGrades:
        gradebookdata = merge_data_for_people(rcpids, gradebooks)
#        gradebookdata = merge_gradebooks_for_students(students, gradebooks)
    if doUploads:
        uploaddata = merge_uploads_for_students(students, uploads)
    if doCourses:
        coursedata = collect_data_for_people(rcpids, courses)

    # Combine all the data into a table format
    headers = [{"source": "User Data", "title": "rcpid"}]
    headers.extend({"source": "User Data", "title": header} for header in userheaders)
    if doGrades:
        headers.extend(gradebookdata['_headers'])
#        gradeheaders = gradebookdata.itervalues().next().keys()
#        filler = [''] * len(gradebookdata['_headers'])
#        headers.extend({"source": "Gradebook Data", "title": header} for header in gradeheaders)
    if doUploads:
        headers.extend({"source": "Uploaded Data", "title": header} for header in uploaddata['_headers'])
    if doCourses:
        headers.extend(coursedata['_headers'])


    tabledata = []
    for s in students:
        person = s.rcpid
        row = [person]
        row.extend(studentdata[person])
        if doGrades:
            if person in gradebookdata.iterkeys():
                row.extend(gradebookdata[person].values())
            else:
                row.extend(['']*len(gradebookdata['_headers']))
        if doUploads:
            if person in uploaddata.iterkeys():
                row.extend(uploaddata[person])
        if doCourses:
            if person in coursedata.iterkeys():
                row.extend(coursedata[person])
        tabledata.append(row)


    return (headers, tabledata)