Beispiel #1
0
def your_projects(request, record_owner_name):
    """
    An ajax-only request to retrieve a specified user's projects,
    assignment responses and selections
    """
    course = request.course
    in_course_or_404(record_owner_name, course)

    logged_in_user = request.user
    is_faculty = course.is_faculty(logged_in_user)
    record_owner = get_object_or_404(User, username=record_owner_name)
    viewing_own_work = record_owner == logged_in_user

    # Record Owner's Visible Work,
    # sorted by modified date & feedback (if applicable)
    projects = Project.objects.visible_by_course_and_user(request,
                                                          course,
                                                          record_owner)

    # Show unresponded assignments if viewing self & self is a student
    assignments = []
    if not is_faculty and viewing_own_work:
        assignments = Project.objects.unresponded_assignments(request,
                                                              logged_in_user)

    # Assemble the context
    user_rez = UserResource()
    course_rez = CourseSummaryResource()
    data = {
        'assignments': homepage_assignment_json(assignments, is_faculty),
        'projects': homepage_project_json(request, projects, viewing_own_work),
        'space_viewer': user_rez.render_one(request, logged_in_user),
        'space_owner': user_rez.render_one(request, record_owner),
        'editable': viewing_own_work,
        'course': course_rez.render_one(request, course),
        'compositions': len(projects) > 0 or len(assignments) > 0,
        'is_faculty': is_faculty}

    json_stream = simplejson.dumps(data, indent=2)
    return HttpResponse(json_stream, mimetype='application/json')
Beispiel #2
0
def all_projects(request):
    """
    An ajax-only request to retrieve a course's projects,
    assignment responses and selections
    """
    if not request.user.is_staff:
        in_course_or_404(request.user.username, request.course)

    course = request.course
    logged_in_user = request.user

    projects = Project.objects.visible_by_course(request, course)

    # Assemble the context
    user_rez = UserResource()
    course_rez = CourseSummaryResource()
    data = {'projects': homepage_project_json(request, projects, False),
            'space_viewer': user_rez.render_one(request, logged_in_user),
            'course': course_rez.render_one(request, course),
            'compositions': len(projects) > 0,
            'is_faculty': course.is_faculty(logged_in_user)}

    json_stream = simplejson.dumps(data, indent=2)
    return HttpResponse(json_stream, mimetype='application/json')